Sign in to follow this  
celios

glTexImage2D not showing texture correctly

Recommended Posts

Hi. Newbie question. Please help. I want to display a 1280 x 1024 (well actually size may vary) texture. Since this is just in testing phase, I created my own RGBA texture just by filling color values to array of char. The order of the color is red, green, blue, alpha. Somehow the texture does not show right. If the value of all alpha is 255, the texture is pitch black, while it actually shoud not. If the value of alpha is less than 255, it shows something, but still not right. It does not seem like red / blue order error. Wish I could attach some screenshots. This is the function body of my render function : glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_TEXTURE_RECTANGLE_ARB); if(first) { glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData); first = false; } else { glTexSubImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, imageData); } glBegin (GL_QUADS); glTexCoord2f (0.0, 0.0); glVertex2d (0, 0); glTexCoord2f (1.0, 0.0); glVertex2d (Width, 0); glTexCoord2f (1.0, 1.0); glVertex2d (Width, Height); glTexCoord2f (0.0, 1.0); glVertex2d (0, Height); glEnd (); glFlush(); glDisable(GL_TEXTURE_RECTANGLE_ARB); Please tell me if there is anything wrong with the code. Thanks, Celios [Edited by - celios on July 10, 2007 7:00:19 PM]

Share this post


Link to post
Share on other sites
What's the definition of imageData? Also, the title mentions glTexSubImage2D, so does that mean that setting the texture up once (without subsequently resetting it) does work?

Share this post


Link to post
Share on other sites
Quote:
Original post by Todo
What's the definition of imageData? Also, the title mentions glTexSubImage2D, so does that mean that setting the texture up once (without subsequently resetting it) does work?


imageData is a pointer to structures.
The structure is :
struct RGBPixel {
uint8 red, green, blue, alpha;
};

Sorry for the title error.
I believe it is glTexImage2D problem and not glTexSubImage2D problem.
It was rather late last night, so please excuse me.
I have made correction to the topic title.

If I use GL_TEXTURE_2D and use glBuild2DMipmap in place of glTexImage2D,
the texture would show correctly.
Also after the first render, for the next render calls, glTexSubImage2D
shows correct texture color.

If I use glTexImage2D with GL_TEXTURE_2D ( and texture size, window size, and quad size changed to 1024 x 1024 ) or GL_TEXTURE_RECTANGLE_ARB,
the texture would not show correct colors.
Also after the first render, for the next render calls, glTexSubImage2D
somehow follows the texture color of the first render with glTexImage2D.

While I believe that glBuild2DMipmap is slower than glTexImage2D,
I need to use textures that does not have power of 2 dimensions so
I cannot use GL_TEXTURE_2D.
The OpenGL version of the video card is 1.5.7.
When using GL_TEXTURE_RECTANGLE_ARB, I cannot use glBuild2DMipmap.
Then again, even when I modified the texture size, window size, and quad size into 1024 x 1024,
glTexImage2D also did not show it correctly.

Please help.

Thanks,
Celios

Share this post


Link to post
Share on other sites
After several days of confusion finally got it to work.

To other people who also got into this problem,
please visit this thread :
http://www.gamedev.net/community/forums/topic.asp?topic_id=422015

Also there was something about mipmapping.
GL_TEXTURE_RECTANGLE_ARB does not support mipmapping, so some filters (which by default enables mipmaping ) need to be set to correct value, otherwise the texture will be incomplete & disabled, or so I heard.

This setting works for me :
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);

Regards,
Celios

Share this post


Link to post
Share on other sites
I suggest that you use GL_CLAMP_TO_EDGE instead to avoid that border color blend "thing".
www.opengl.org/registry has info all on these extensions in case you are up to it.
ARB_texture_rectangle is in the list.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this