Jump to content
  • Advertisement
Sign in to follow this  
_DivideByZero_

Texture Coordinates -- Grey Square

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

For my project I am trying to draw an image onto the screen from a sheet of multiple images. I am trying to draw the first 16x16 tile of a 256x256 bitmap, but whenever I set the texture coordinates to anything but the ones necessary to draw the whole image*, it draws a grey square instead.

This is my code:


glBindTexture( GL_TEXTURE_2D, texid[sprite]);
glBegin( GL_QUADS );
glTexCoord2i(0.0,0.9375);
glVertex3f( 0, 0, 0 );
glTexCoord2i(0.0625,0.9375);
glVertex3f( 16, 0, 0 );
glTexCoord2i(0.0625,1.0);
glVertex3f( 16, 16, 0 );
glTexCoord2i(0.0,1.0);
glVertex3f( 0, 16, 0 );
glEnd();
SDL_GL_SwapBuffers();

Wheras:

glBindTexture( GL_TEXTURE_2D, texid[sprite]);
glBegin( GL_QUADS );
glTexCoord2i(0.0,0.0);
glVertex3f( 0, 0, 0 );
glTexCoord2i(1.0,0.0);
glVertex3f( 256, 0, 0 );
glTexCoord2i(1.0,1.0);
glVertex3f( 256, 256, 0 );
glTexCoord2i(0.0,1.0);
glVertex3f( 0, 256, 0 );
glEnd();
SDL_GL_SwapBuffers();

Works flawlessly.

*The exception is when I set the coordinates to something like:

glTexCoord2i(0.0,0.5);
glVertex3f( 0, 0, 0 );
glTexCoord2i(1.0,0.5);
glVertex3f( 256, 0, 0 );
glTexCoord2i(1.0,0.5);
glVertex3f( 256, 256, 0 );
glTexCoord2i(0.0,1.0); /***When I set this one to .5 it draws the first row of pixels stretched down across the whole image.
When I set it to 5 though, the image gets repeated 5 times vertically within the 256 pixels. If I set it lower than one it simple doesn't work.***/
glVertex3f( 0, 256, 0 );

Then nothing happens. I don't understand what's going on.


EDIT: After further experimentation, only the last coordinate and the 1st one, 2nd line actually do anything. If they are changed, the pixels from the top and left side are repeated across the entire image, respectively.

Here's a screenshot of what happens when the both are less than 1.0.
http://i383.photobucket.com/albums/oo277/meep112233/Screenshot-UntitledWindow.png

[Edited by - _DivideByZero_ on December 24, 2010 7:32:54 PM]

Share this post


Link to post
Share on other sites
Advertisement
Well that's rather stupid of it.

Anyway you're passing floats to glTexCoord2i, which truncates it to ints. Use glTexCoord2f instead.

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!