Textures will not draw

Started by
9 comments, last by Kurt Blanken 12 years, 9 months ago
SOLVED
I've been following several tutorials on OpenGL and I cannot for the life of me get the texture to show up. can someone let me know what I'm doing wrong?

Edit for more clarity: I get a white box. So I can see the quad, but not the texture that should be on top of it. I am using Visual Studio 2010 for compilation and freeGLUT for handling the windowing API.

Edit: glGetError returns 1282 from the start of main until the first call in the resize function.

My load texture function:
char* fileName = "..\\Assets\\ARG.bmp";

GLubyte *TextureImage[1];
memset(TextureImage,0,sizeof(void *)*1);
TextureImage[0] = LoadDIBitmap(fileName, &BitmapInfo);

glEnable( GL_TEXTURE_2D );
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

glGenTextures(1, &textures[0]);
glBindTexture(GL_TEXTURE_2D, textures[0]);

glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

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_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, BitmapInfo->bmiHeader.biWidth,
BitmapInfo->bmiHeader.biHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
TextureImage[0]);



My display function:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-5.0f);

glEnable (GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textures[0]);

glBegin (GL_QUADS);
glTexCoord2d(0.0,0.0); glVertex2d(-1.0,-1.0);
glTexCoord2d(1.0,0.0); glVertex2d(+1.0,-1.0);
glTexCoord2d(1.0,1.0); glVertex2d(+1.0,+1.0);
glTexCoord2d(0.0,1.0); glVertex2d(-1.0,+1.0);
glEnd();

//glDisable (GL_TEXTURE_2D);
glutSwapBuffers();
Advertisement
remove the glDisable and it should work

remove the glDisable and it should work


That did not fix it.
I'm uncertain of the paramters for LoadDIBitmap(), but I presume that BitmapInfo contains all the pertinent information regarding texture width and height, and it returns a pointer to memory allocated and has the texture information in it.

Have you used your debugger to check the contains in the memory location returned and check it actually contains the bitmap data you're expecting?

Also Bitmaps don't have an alpha channel, so the format you should be passing to glTexImage2D() should be either GL_RGB or GL_BGR_Ext (I believe BMP's store the channels in reverse order so BGR not RGB)

Also, does textures[0] contain a non-zero value?

Try adding in some glGetError() after each call to see exactly what line it's failing on.

I'm uncertain of the paramters for LoadDIBitmap(), but I presume that BitmapInfo contains all the pertinent information regarding texture width and height, and it returns a pointer to memory allocated and has the texture information in it.

Have you used your debugger to check the contains in the memory location returned and check it actually contains the bitmap data you're expecting?

Also Bitmaps don't have an alpha channel, so the format you should be passing to glTexImage2D() should be either GL_RGB or GL_BGR_Ext (I believe BMP's store the channels in reverse order so BGR not RGB)

Also, does textures[0] contain a non-zero value?

Try adding in some glGetError() after each call to see exactly what line it's failing on.



I think loading the texture is not the problem. I have changed it back to GL_RGB.

I am getting error number 1282 after the call to glEnd()

I think loading the texture is not the problem.


You think, or you know?

[quote name='Kurt Blanken' timestamp='1309391143' post='4829307']
I think loading the texture is not the problem.


You think, or you know?
[/quote]

After some debugging I am back to "no clue." glGetError returns 1282 all over the place.

After some debugging I am back to "no clue." glGetError returns 1282 all over the place.


Which line is the very first time it reports an error?

[quote name='Kurt Blanken' timestamp='1309392972' post='4829328']
After some debugging I am back to "no clue." glGetError returns 1282 all over the place.


Which line is the very first time it reports an error?
[/quote]

As far as I can tell it has that value when it enters main, and stays that way until it calls resize for the first time.

If it is possible that something wrong somewhere else (glut calls, linking, etc) could cause textures to not work but still be able to draw polygons, I can show the rest of the code as well.
Post the rest of the code. I have a strong feeling that you're doing all the initialization before you have a rendering context to operate on if you're getting that error all over the place.

This topic is closed to new replies.

Advertisement