-1

openGL を使用してテクスチャをレンダリングする作業を行っています。私は途中で立ち往生しています。

私の目標は、この写真を取得することです: http://i.imgur.com/d3kZTsn.png

これが私がいる場所です:http://i.imgur.com/uAV8q0W.png

誰もこの問題を見たことがありますか?

if (tObject == 0)         // We don't yet have an OpenGL texture target
{
    // This code counts the number of images and if there are none simply 
    // returns without doing anything
    int nImages = 0;
    while (tName[nImages][0] != '\0' && nImages < MAX_IMAGES)
        nImages++;

    if (nImages < 1)
        return;

    // To Do
    //
    // Generate a texture object and place the object's value in the "tObject"
    // member, then bind the object to the 2D texture target

    glGenTextures(nImages, &tObject);
    glBindTexture(GL_TEXTURE_2D, tObject);

    for (int nImage = 0; nImage < nImages; nImage++)
    {
        // This code loads the texture using the windows library's "BitmapFile" object
        BitmapFile texture;
        if (!texture.Read(tName[nImage]))
            complain("Couldn't read texture %s", tName);

        GLuint srcFormat, targFormat;
        // To Do
        // 
        // First decide which format the texture is.  If the texture has 4 bytes
        // per pixel then it should be an RGBA texture, if it is 3 bytes per pixel
        // then it is an RGB image.  Notice though that the byte order for the BitmatFile
        // object is reversed, so you need to take that into account in the "source" format

        if( texture.BytesPerPixel() == 3 )
        {
            srcFormat = GL_BGR;
            targFormat = GL_RGB;
        }
        else
        {
            srcFormat = GL_BGRA;
            targFormat = GL_RGBA;
        }

        // Then you need to set the unpack alignment to tell OpenGL about the structure 
        // of the data in the image and send the data to OpenGL.  If there are multiple files
        // then we are manually creating a mipmap here and you will use the "level" parameter
        // of glTexImage2D to tell OpenGL which mipmap level is being set.  The levels are 
        // set in the same order as they are stored in the image list.

        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

        if( nImages > 1 )
        {
            glGenerateMipmap(GL_TEXTURE_2D);
        }

        glTexImage2D(GL_TEXTURE_2D, nImage, targFormat, texture.Width(), texture.Height(), 0, srcFormat, GL_UNSIGNED_BYTE, texture.ImageData());
    }
    // Finally, if there is only one image, you need to tell OpenGL to generate a mipmap

    if( nImages == 1)
    {
        glGenerateMipmap(GL_TEXTURE_2D);
    }
}   

// Here you need to bind the texture to the 2D texture target and set the texture parameters
// You need to set the wrap mode, the minification and magnification filters.

glBindTexture(GL_TEXTURE_2D, tObject);

glTexParameteri(tObject, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(tObject, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(tObject, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(tObject, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

// To Do 
//
// For advanced antialiasing set the number of anisotropic samples
GLERR;
4

1 に答える 1

1

を呼び出すために使用しているロジックがわかりませんglGenerateMipmap (...)。の 2 番目のパラメータglTexImage2D (...)はテクスチャ LODで、LOD 0 から始まるミップ ピラミッド全体glGenerateMipmapを生成します。基本的に、これを行うことで、そのループの最初と最後の反復を除いて、すべての呼び出しを無効にします。配列テクスチャが必要なように見えますが、これらの画像のそれぞれが個別のテクスチャである必要があります。glTexImage2D (...)

実際にglGenTextures (...)は、あなたが思うようには機能しません。nImagesis > 1の場合、配列を渡すことになっています。その配列は、nImages多くのテクスチャ オブジェクト名を保持します。それぞれをバインドし、画像データを個別に LOD 0 にアップロードすると、ミップマップを生成できます。

以下は、私が今言及したすべてに対応しています。

GLuint* tObjects = NULL;

if (tObjects == NULL)      // We don't yet have any OpenGL textures
{
    // This code counts the number of images and if there are none simply 
    // returns without doing anything
    int nImages = 0;
    while (tName[nImages][0] != '\0' && nImages < MAX_IMAGES)
        nImages++;

    if (nImages < 1)
        return;

    tObjects = new GLuint [nImages];

    // To Do
    //
    // Generate multiple texture objects and place the object's values in the "tObjects"
    // member, then bind the object to the 2D texture target

    glGenTextures (nImages, tObjects);

    for (int nImage = 0; nImage < nImages; nImage++)
    {
        glBindTexture(GL_TEXTURE_2D, tObjects [nImage]);

        // This code loads the texture using the windows library's "BitmapFile" object
        BitmapFile texture;
        if (!texture.Read(tName[nImage]))
            complain("Couldn't read texture %s", tName);

        GLuint srcFormat, targFormat;
        // To Do
        // 
        // First decide which format the texture is.  If the texture has 4 bytes
        // per pixel then it should be an RGBA texture, if it is 3 bytes per pixel
        // then it is an RGB image.  Notice though that the byte order for the BitmatFile
        // object is reversed, so you need to take that into account in the "source" format

        if( texture.BytesPerPixel() == 3 )
        {
            srcFormat = GL_BGR;
            targFormat = GL_RGB;
        }
        else
        {
            srcFormat = GL_BGRA;
            targFormat = GL_RGBA;
        }

        // Then you need to set the unpack alignment to tell OpenGL about the structure 
        // of the data in the image and send the data to OpenGL.  If there are multiple files
        // then we are manually creating a mipmap here and you will use the "level" parameter
        // of glTexImage2D to tell OpenGL which mipmap level is being set.  The levels are 
        // set in the same order as they are stored in the image list.

        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

        glTexImage2D(GL_TEXTURE_2D, 0, targFormat, texture.Width(), texture.Height(), 0, srcFormat, GL_UNSIGNED_BYTE, texture.ImageData());

        glGenerateMipmap (GL_TEXTURE_2D);

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    }
}
于 2015-03-13T02:32:47.273 に答える