Need Help figuring out a texture issue

Started by
2 comments, last by BahDragon 12 years, 2 months ago
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 );

}
Advertisement
How do you draw your tiles / calculate their coordinates?
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.
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

This topic is closed to new replies.

Advertisement