Jump to content
  • Advertisement
Sign in to follow this  
rakoon2

glTexCoord2f calls wrong? ( horizontally mirrored )

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

Hello guys! I am using one big texture that contains all my tiles. If I draw a single tile, the texture is not right!( vertical mirrored,.. or so ) The TexCoords seem to be wrong. Please help me! :) Here is the code:
GLfloat SrcX = ( tile_num % tiles_in_one_row ) * tile_size;
GLfloat SrcY = ( tile_num / tiles_in_one_row) * tile_size;

texture->activate();
glEnable(GL_TEXTURE_2D);
		
  glBegin( GL_QUADS );
    glTexCoord2f( (SrcX+16.0f)/texture_wh, (SrcY+16.0f)/texture_wh );
    glVertex2f( x, y + 16.0f); 
		    
    glTexCoord2f( SrcX/texture_wh, (SrcY+16.0f)/texture_wh );
    glVertex2f( x + 16.0f, y + 16.0f );  
			
    glTexCoord2f( SrcX/texture_wh, SrcY/texture_wh );
    glVertex2f( x + 16.0f, y );
			
    glTexCoord2f( (SrcX+16.0f)/texture_wh, SrcY/texture_wh ); 
    glVertex2f( x , y );  
  glEnd();
  glDisable(GL_TEXTURE_2D);


And one more question: Why should I enable GL "functions" only when I need them(and disable later on)? e.: glEnable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D) Thank you for your help! [Edited by - rakoon2 on October 14, 2004 6:21:34 AM]

Share this post


Link to post
Share on other sites
Advertisement
I don't see anything wrong with this code. If your tiles are coming out vertically mirrored, exchange

(SrcY+16.0f)/texture_wh

and

SrcY/texture_wh

Share this post


Link to post
Share on other sites
Quote:
Original post by rakoon2
Just checked it. The tile is horizontally mirrored. Sorry.

Thank you! :)

Ofcourse they are coming out horizontally mirrored, you're making them do it. =)

Look, for your left most vertex (plain x), you're using SrcX+16.0f as texture coordinate. For your rightmost vertex (x+16.0f) you are using plain SrcX as texture coordinate.

Make sure plain x vertices have plain SrcX texCoords and the +16 variants are coupled together and you'll be fine. =)



[Edited by - DEVLiN on October 14, 2004 8:45:00 AM]

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!