Jump to content
  • Advertisement
Sign in to follow this  
BahDragon

OpenGL Need Help figuring out a texture issue

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

Ive been programming a 2D tile platformer in OpenGL and the tiles are 64 by 64. Everything is fine until i resize the screen. When i resize the screen i try to make everything resize as well by keeping the variables in glOrtho constant. However it distorts the textures a bit and I can see small lines seperating some of the tiled textures where there weren't any before. Is there any way to fix this issue? Inside the reshape function I have this

void reshape(int width, int height)
{
if( fullScreen )
{
fullScreenWindowWidth = width;
fullScreenWindowHeight = height;
width = height * 4 / 3;
fullScreenGameWidth = width;
fullScreenRightShift = ( fullScreenWindowWidth - fullScreenGameWidth ) >> 1;
}
else
{
width = height * 4 / 3;
glutReshapeWindow( width, height );
}


glViewport(0, 0, width, height);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D( 0, 1280, 0, 960 );
glMatrixMode(GL_MODELVIEW);

//calculate time since last frame
frameTime = glutGet( GLUT_ELAPSED_TIME ) - elapsedTime;
elapsedTime = glutGet( GLUT_ELAPSED_TIME );

}

Share this post


Link to post
Share on other sites
Advertisement
using nested for loops. Here it is

for( loop1 = 0; loop1 < windowWidth + pixelsRightofTile; loop1 += GAME_TILE_SIZE )
{
for( loop2 = 0; loop2 < windowHeight + pixelsAboveTile; loop2 += GAME_TILE_SIZE )
{
tileLeftX = int(loop1 + mapX) / GAME_TILE_SIZE, tileBottomY = int(loop2 + mapY) / GAME_TILE_SIZE;

glBindTexture( GL_TEXTURE_2D,
tile[ GameMap[ currentMap ][ tileLeftX ][ tileBottomY ].tileNumber ].texID );
glBegin(GL_QUADS);
glTexCoord2i( 0, 0 ); glVertex2f( loop1, loop2 );
glTexCoord2i( 1, 0 ); glVertex2f( GAME_TILE_SIZE + loop1, loop2 );
glTexCoord2i( 1, 1 ); glVertex2f( GAME_TILE_SIZE + loop1, GAME_TILE_SIZE + loop2 );
glTexCoord2i( 0, 1 ); glVertex2f( loop1, GAME_TILE_SIZE + loop2 );
glEnd();
}
}

GAME_TILE_SIZE is a constant equal to 64.

Share this post


Link to post
Share on other sites
I got it working.. apparently adding these lines

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );

fixed the issue. I found the same issue in this topic over here.
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=259097

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!