Original Post
🔒 Locked
texturing gahhhh
Advertisement
You have to call glTexCoord before each glVertex.
See NeHe Tutorial 6.
(Where do you call glGenTextures?)
(And what is s_tex and why is it equal to 1?)
See NeHe Tutorial 6.
(Where do you call glGenTextures?)
(And what is s_tex and why is it equal to 1?)
...you´re forgetting the glTexCoord{if}()...
Quote:
Original post by F-Kop
Why must all online tutorials suck?
Because they encourage mindless copying over actual understanding. I don't know if that's the specific problem here, but it's why they suck.
Thanks, that was pretty stupid of me to forget glTexCoord. I had it working for a while, but I think I broke it again. I debugged every aspect of the program I can think of, and I found nothing wrong. But when I run the program, it shows a dark blue square where my sprite should be. Here is my draw code:
s_tex[m_spr] in this case is the first texture I loaded. The texture is a strip of 8 sprites, each 16x16 pixels. m_sub is the index of the sprite that should be displayed. Everything looks fine to me, but again, I'm new to OpenGL. Any help is appreciated.
void CLink :: OnDraw( ){ glTranslatef( m_x, m_y, 0.0f ); glBindTexture( GL_TEXTURE_2D, s_tex[m_spr] ); glBegin( GL_QUADS ); glTexCoord2i( m_sub * 16, 0 ); glVertex3f( 0.0f, 0.0f, 0.0f ); glTexCoord2i( m_sub * 16 + 15, 0 ); glVertex3f( 15.0f, 0.0f, 0.0f ); glTexCoord2i( m_sub * 16 + 15, 15 ); glVertex3f( 15.0f, 15.0f, 0.0f ); glTexCoord2i( m_sub * 16, 15 ); glVertex3f( 0.0f, 15.0f, 0.0f ); glEnd( );}s_tex[m_spr] in this case is the first texture I loaded. The texture is a strip of 8 sprites, each 16x16 pixels. m_sub is the index of the sprite that should be displayed. Everything looks fine to me, but again, I'm new to OpenGL. Any help is appreciated.
I see a glTranslate, but no glLoadIdentity. Are you remembering to reset the transformation before you mess with it each frame?
There's a glLoadIdentity before the call to the OnDraw function.
Huh. Everything else looks pretty good. Put GL error checks after each GL function.
I noticed something kinda funny. It seems like each of the textures I loaded are a different solid color. I put some error checks everywhere, but it didn't find anything. Time for some more debugging.
Quote:
Original post by F-Kop
I noticed something kinda funny. It seems like each of the textures I loaded are a different solid color.
My guess: Your texture coords are borked, and you're seeing the pixel color in one of the corners of your texture. You know that textures index from 0 to 1, right?
I believe that you use a value from 0.0f to 1.0f for OpenGL Texture calls. So, 1.0 would be the farthest point to the left/bottom. Its not in pixels, like you're doing it. So in this case, you'd be tiling the texture at least 15 times, possibly creating a solid color if the resolution isn't so great.
Hope that helps.
Oh, and buy Begining OpenGL Game Programming. It's an *excellent* book, far superior to even NeHe tutorials. It goes it to far more explanation than web tutorials do. To summurize it: its not just a bunch of example code with tons of comments.
Edit: beaten to it by Sneftel, sorta. But on second look, I notice that you're using glTexCoord2i not, glTexCoord2f. This might, therefore, be in pixels, since it wouldn't work realy well if it was a range of 0 to 1, only integers. :)
Hope that helps.
Oh, and buy Begining OpenGL Game Programming. It's an *excellent* book, far superior to even NeHe tutorials. It goes it to far more explanation than web tutorials do. To summurize it: its not just a bunch of example code with tons of comments.
Edit: beaten to it by Sneftel, sorta. But on second look, I notice that you're using glTexCoord2i not, glTexCoord2f. This might, therefore, be in pixels, since it wouldn't work realy well if it was a range of 0 to 1, only integers. :)

Yay! Link can walk! But why does he look so distorted? Like those red pixels on the sides of his hat.
EDIT: This is what it should look like:
Is there a way to make the texture appear exactly the same is the bitmap, down to the last pixel?
Quote:
Original post by F-Kop
Is there a way to make the texture appear exactly the same is the bitmap, down to the last pixel?
Use nearest filtering and add (0.5f/TextureWidth,0.5f/TextureHeight) to all texture coordinates.
Quote:
Original post by vNistelrooy Quote:
Original post by F-Kop
Is there a way to make the texture appear exactly the same is the bitmap, down to the last pixel?
Use nearest filtering and add (0.5f/TextureWidth,0.5f/TextureHeight) to all texture coordinates.
Do not add 0.5f to the texture coordinates, that is a Direct3D thing.
I don't know much (anything) about OpenGL, but it looks to me like you're loading a 32-bit image into a 16-bit texture, or rendering onto a 16-bit back buffer. I'd check just to make sure.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement