开发者

OpenGl Textures

im trying to apply 2 textures to my level the code compiles but the levels come out completly white,

struct Image 
{
    unsigned long size_x;
    unsigned long size_y;
    char *data;
}

typedef struct Image Image;

const int textureCount = 2;

Image myTextureData[textureCount];
GLuint theTexture[textureCount];

char* textureFilenames0[textureCount] = {"road.bmp"};
char* textureFilenames1[textureCount] = {"building.bmp"};

texture loader class

void textureLoader() 
{

    /*glPixelStorei(GL_UNPACK_ALIGNMENT, 1);*/

    glGenTextures(2, theTexture);


    glBindTexture(GL_TEXTURE_2D, theTexture[0]);
    for(int k=0; k < textureCount; k++) 
    {
        if(!imageLoader(textureFilenames0[k], &myTextureData[k])) 
            exit(1);

        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);

        gluBuild2DMipmaps(GL_TEXTURE_2D, 3, myTextureData[k].size_x, myTextureData[k].size_y, GL_RGB, GL_UNSIGNED_BYTE, myTextureData[k].data);

    glBindTex开发者_StackOverflowture(GL_TEXTURE_2D, theTexture[1]);
    for(int k=0; k < textureCount; k++) 
    {
        if(!imageLoader(textureFilenames1[k], &myTextureData[k])) 
            exit(1);

        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);

        gluBuild2DMipmaps(GL_TEXTURE_2D, 3, myTextureData[k].size_x, myTextureData[k].size_y, GL_RGB, GL_UNSIGNED_BYTE, myTextureData[k].data);
    }
}


Have you called

glEnable(GL_TEXTURE_2D);

and glTexCoord2 or glTexCoordPointer?

Also, try setting the texture parameters before uploading the data.

Finally, when using loops, you need all the filenames in one array, like

char* textureFilenames[textureCount] = {"road.bmp", "building.bmp"};

Or you can get rid of the loop and write

char* textureFilenames0 = "road.bmp";
char* textureFilenames1 = "building.bmp";

But there are not textureCount files with the road bitmap inside.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜