(solved)[OpenGL] lame problem

Started by
14 comments, last by Daggerbot 15 years, 10 months ago
I use this code to load a texture:

glGenTextures( 1, (GLuint*) &m_handle );
glBindTexture( GL_TEXTURE_2D, (GLuint) m_handle );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmap->GetPixelBuffer() );



And I use this code to render a texture:

glBindTexture( GL_TEXTURE_2D, (GLuint) tex.GetHandle() );
glBegin( GL_QUADS );
	glTexCoord2i( 0, 0 );
	glVertex3i( x, y, depth );
	glTexCoord2i( 1, 0 );
	glVertex3i( x + width, y, depth );
	glTexCoord2i( 1, 1 );
	glVertex3i( x + width, y + height, depth );
	glTexCoord2i( 0, 1 );
	glVertex3i( x, y + height, depth );
glEnd();



But I get that horrible white rectangle where the texture should be on the screen. I've done some debugging, and the "handle" is 1, like it should be. Does it appear that the error is in the code above? Thanks for your time. [Edited by - Daggerbot on June 17, 2008 1:24:14 AM]
Advertisement
glEnable(GL_TEXTURE_2D);

?
Make sure you configure the filtering levels (MIN and MAG) as it seems that the default uses something else which won't allow basic textures as you've shown work.
If you still have the white texture problem, try making sure your texture size is a power (e.g. 128x128). Some (older) graphics cards don't support textures of an arbitrary size.
www.ice-d.com
Quote:glEnable(GL_TEXTURE_2D);

Already added.

Quote:Make sure you configure the filtering levels (MIN and MAG) as it seems that the default uses something else which won't allow basic textures as you've shown work.


Added this:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);


Still shows a white rectangle.

Quote:If you still have the white texture problem, try making sure your texture size is a power (e.g. 128x128). Some (older) graphics cards don't support textures of an arbitrary size.


The image was an irregular size, but I changed it to 256x256, but still no success.



Here's some initialization code:

glEnable( GL_TEXTURE_2D );glEnable( GL_DEPTH_TEST );glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );glClearDepth( 1.0 );glDepthFunc( GL_LEQUAL );


Is there a problem here?
Have you checked that bitmap->GetPixelBuffer() isn't just returning white pixels?
Quote:Original post by Hodgman
Have you checked that bitmap->GetPixelBuffer() isn't just returning white pixels?


And if it is functioning correctly, does it truly return what GL would treat as RGBA?
GetPixelBuffer() returns an array of these:
union TPixel{	Tdword dw;	struct { Tbyte r, g, b, a; };	struct { Tbyte ra, rb, rg, rr; };};

I've tried passing the actual loaded image and a hard-coded solid red image, and both show the white rectangle.

By the way, rate++ to everyone who has replied.
seems odd, few things to check:

- if you're in a multithreaded env, make sure the context is made current to the thread before creating and using

- glGetError() is your friend, write macro to let you wrap calls e.g. SAFE_GL( glTexImage2D( ... ) ), I personally use a simple method which makes a nice error message, if you're feeling lazy use gluGetErrorString, but I wouldnt recommend it as a permanent solution

- double check that TPixel union, don't quote me on this, but I have a nagging feeling anonymous structs within unions are technically not standard...
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
This is a long reach, but what OS are you running? I recently had problems with OpenGL on linux. All my textures were white - I never resolved the issue and came to the conclusion it was a driver problem. I could not get drivers working correctly to confirm this though.
www.ice-d.com

This topic is closed to new replies.

Advertisement