Jump to content
  • Advertisement
Sign in to follow this  
Daggerbot

(solved)[OpenGL] lame problem

This topic is 3659 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!