Tilemap problem

Started by
1 comment, last by Shawn619 11 years, 3 months ago

I don't know whether my problem is with Game Programming, Graphics, or OpenGL.

I'm trying to implement a 200px tile map which consists of: 20px tile size, 10 tiles in x-axis, 10 tiles in z-axis.

This is my function code for drawing the tile map:


void
 
 
loadFloor2(){
 
 
int mapSize = 10;
 
 
int tileSize = 20;
?
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, skyTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 
 
for(int i=0; i<mapSize; i++){
 
 
for(int j=0; j<mapSize; j++){
glBegin(GL_QUADS);
glNormal3f(0.0, 1.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f((-tileSize*i), 0.0f, tileSize*j);
glTexCoord2f(1.0f, 0.0f);
glVertex3f((tileSize*i)+tileSize, 0.0f, tileSize*j);
glTexCoord2f(1.0f, 1.0f);
glVertex3f((tileSize*i)+tileSize, 0.0f, (-tileSize*j)+(-tileSize) );
glTexCoord2f(0.0f, 1.0f);
glVertex3f((-tileSize*i), 0.0f, (-tileSize*j)+(-tileSize));
 
glEnd();
}
}
glDisable(GL_TEXTURE_2D);
}
 

My individual tile looks like this:

rs6GH.jpg

Tile map output:

ztennd.jpg

Advertisement
Your glVertex3f-calls look weird. You are drawing quads which get bigger and bigger and this results in z-fighting like on your screenshot.
For example: with (-tileSize*i) you are going left but with (tileSize*i)+tileSize you are going right and therefore stretching the whole quad with each iteration.

Reconsider how you have to place your vertices in order to achieve your goal - try to remove the minus-operators.
Later on you can try to draw triangle-strips which are faster than quads, and even use indices and vertexbuffers.

Best regards
- Martin

Thanks!

The problem was the minus sign. :)

This topic is closed to new replies.

Advertisement