Jump to content
  • Advertisement
Sign in to follow this  
spek

OpenGL glTexImage2D fails somehow

This topic is 3753 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

Hi, Pretty basic question, although I really don't know what's causing problems. I'm using glTexImage2D to load pixel data to a new texture. This works for cubeMaps, 3D textures, but not for simple 2D textures.
// Delphi Code
pixelData = array of array[0..3] of glFloat;
...
glEnable( GL_TEXTURE_2D );
glGenTextures( 1, @texHandle ); // @ == & in C
glBindTexture( GL_TEXTURE_2D, texHandle );

glTexImage2D( GL_TEXTURE_2D, 0,
              GL_RGBA16F_ARB,
              512, 512, // width, height
              0,
              GL_RGBA,
              GL_FLOAT,
              pixelData );
This results in a pure black texture. First I thought my pixelData array was just wrong. So I tried creating a 3D texture (with 1 slice) with the same pixelData. But that just works fine, and the creation code of the 3D texture is almost the same, except that I use glTexImage3D instead of glTexImage2D, and set GL_TEXTURE_3D as a target. At the point where I try to create this texture, I also create other cubemaps and 3D textures. So maybe OpenGL is in the wrong state when I try to create my texture? What could go wrong? Greetings, Rick

Share this post


Link to post
Share on other sites
Advertisement
http://www.opengl.org/wiki/index.php/Texture_Mapping

Quote:
Some people make the mistake of not calling glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, MinFilter); and they get the default state GL_LINEAR_MIPMAP_NEAREST and they don't define the mipmaps, so the texture is considered incomplete and you just get a white textur

Share this post


Link to post
Share on other sites
I forgot to mention, right after the code I posted above, the parameters are set. I always use simple linear filtering, sometimes "nearest":

// Delphi Code
pixelData = array of array[0..3] of glFloat;
...
glEnable( GL_TEXTURE_2D );
glGenTextures( 1, @texHandle ); // @ == & in C
glBindTexture( GL_TEXTURE_2D, texHandle );

glTexImage2D( GL_TEXTURE_2D, 0,
GL_RGBA16F_ARB,
512, 512, // width, height
0,
GL_RGBA,
GL_FLOAT,
pixelData );

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);


I checked my other code, and saw that the 4 "parameter lines" are placed before the glTexImage... line, instead of after. Maybe that could be a problem, in case OpenGL is expecting mipmaps in the first case like you said... I can't try changing the order right now, have to wait till tonight :)

Greetings,
Rick

Share this post


Link to post
Share on other sites
I always put the glTexParameter*() calls before I call glTexImage*(), but I don't think that makes a difference...

Are you using GL_RGBA16F_ARB on the cubemaps and 3D textures? What hardware are you on?

Share this post


Link to post
Share on other sites
Problem is fixed. As ussual, when I read my code again right before posting, I saw the target in the glTexParameteri lines was not GL_TEXTURE_2D, but GL_TEXTURE_3D (copy & paste & forget from other code). So, I think the cause was what V-Man told about.

Thanks for helping guys!
Rick

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!