Jump to content
  • Advertisement
Sign in to follow this  
sakky

OpenGL small problem with gl texture coordinates

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

I’m creating a sprite interface for OpenGL like I did for Direct3D. The interface uses with, height and stride to compute a source rectangle on an image; then renders it. I’m getting incorrect texture coordinates from OpenGL. I know the formula works, but I’m unsure how the texture coordinates are being interpreted when using glTexCoord(*). I’ve tried using a scaling matrix, no results. Next, I’ve tried scaling the coordinates my self, still-no results. code:
glMatrixMode( GL_TEXTURE ) ;
glPushMatrix( ) ;

glLoadIdentity( ) ;
glScalef( ( 1.0F / 512 ),
			( 1.0F / 512 ),
			1.0F ) ;

glMatrixMode( GL_MODELVIEW ) ;
glLoadIdentity( ) ;

rcSource.left					 = ( nFrame % pSprite->nWidth  ) * pSprite->nWidth  ;
rcSource.top					 = ( nFrame / pSprite->nHeight ) * pSprite->nHeight ;
rcSource.right					 = ( rcSource.left  + pSprite->nWidth  ) ;
rcSource.bottom					 = ( rcSource.right + pSprite->nHeight ) ;

glBindTexture( GL_TEXTURE_2D, pSprite->nRes ) ;

glBegin( GL_TRIANGLE_STRIP ) ;
	glTexCoord2s( rcSource.left, rcSource.top ) ;
	glVertex2i( nX, nY ) ;

	glTexCoord2s( rcSource.left, rcSource.bottom ) ;
	glVertex2i( nX, nY + pSprite->nHeight ) ;

	glTexCoord2s( rcSource.right, rcSource.top ) ;
	glVertex2i( nX + pSprite->nWidth, nY ) ;

	glTexCoord2s( rcSource.right, rcSource.bottom ) ;
	glVertex2i( nX + pSprite->nWidth, nY + pSprite->nHeight ) ;
glEnd( ) ;

glMatrixMode( GL_TEXTURE ) ;
glPopMatrix( ) ;

glMatrixMode( GL_MODELVIEW ) ;

Please help!

Share this post


Link to post
Share on other sites
Advertisement
Woops! I figured it out. It was a combination of my formula and the TGA was right-side-up. Not a biggie with the TGA, but as one can probably depict from my above source that I would run into all kinds of problems like this.

Argh! I need to pay more attension to things. Uh... thanks anyways I guess.

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!