Texturing problem

Started by
13 comments, last by Enigma 18 years ago
Assuming you're using Win32 to create your OpenGL window you should make sure that your calls to wglCreateContext and wglMakeCurrent occur before your call to Text::LoadTextImg. You could try checking this by adding an assert(wglGetCurrentContext()); at the start of Text::LoadTextImg.

Σnigma
Advertisement
Hi tjrr3d,

I copied the code you posted into a sample app I had and I couldn't see the texture either, but I also couldn't see the white box til I changed a few things.

first off, the code wouldn't compile with the following line from your Render function.
glTranslated(x,y);

this function takes 3 doubles so I assume you fixed this and it didn't make it into the post. I changed that line to.
glTranslated(0.0, 0.0, -1.0);

But I still couldn't see anything until I changed you last parameter to glOrtho to 2. My width and height are 640x480
glOrtho(0, SCREENWIDTH, 0, SCREENHEIGHT, -1, 2);

I also didn't see you make a glViewport call, but maybe you make it somewhere else and I'm not sure if there is a default condition for it in opengl.

I did get it too work ok with the above fixes, but the way I load bitmaps requires me to use GL_BGR_EXT in my glTexImage2D call like this.
glTexImage2D(GL_TEXTURE_2D, 0, 3, Width, Height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, TextureImage[0]);
but if I do it your way I can still see a texture it just has red and blue reversed.

I hope this helps and I can further explain anything I did if you need me to.

Diruntled Gamer:
Youre right I originally had glTranslated(x, y, 0). I tried you fixes, but still see only white. Actually I can view quads without the changing the glOrtho to 2 and the glTranslated to -1; But I changed it to your way and still nothing.
When you tested it, was it with Qt, or a windows app?

Enigma:
I put the assert in and my program crashed. This is what it said:

Debug Error!

Program: blah, blah\debug\GfxGui.exe

This application has requested the Runtime to terminate in an unusual way. Please contatct the applications support team for more information.

I think Qt already created the context. I mean there are not handles to device contexts and stuff like a windows app. So I think that may be why the fuction crashed the program
I am using win32, and the function I use to load the texture from file is called LoadDIBitmap. The only way I can reproduce your problem is to disable GL_TEXTURE_2D, and then draw the quad I get a white box. I'm guessing I'd also get a white box if my LoadDIBitmap didn't work. You do make a lot of glEnable and glDisable calls with depth testing and texturing and for what you are trying to do you really only need to enable them once and leave them on. Your initializeGL function would be a good place for that.

Are you sure your auxDIBImageLoad works properly can you display bitmaps other ways with it like SetDIBitsToDevice or glDrawPixels? Check that and make sure your not disabling texturing somewhere by not disabling it at all.

DG
Are you sure that wasn't the assert firing? I'm not sure what it would look like for you since it depends on your compiler and probably whether you're running through a debugger or not. An alternative test would be to try something like if (!wglGetCurrentContext()){MessageBox(0, "no opengl context", "Assert Failed", MB_OK);}. I'm not familiar with Qt, but it appears you could also try if (!QGLContext::currentContext()){MessageBox(0, "no opengl context", "Assert Failed", MB_OK);}. If either of those display the message box then Qt is not creating your opengl context until after you try to create your texture and you must move the call to create your texture to a point in your program after the context has been created.

Σnigma

This topic is closed to new replies.

Advertisement