Skip to main content
GameDev.net gamedev.net
🔒 Locked

Tilemap problem

Started by Shawn619 Dec 30, 2012 at 3:07 AM 1 replies 1.7k views
Original Post
Shawn619
Shawn619

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

MausGames
MausGames
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
Thank you for playing! 🐬
Shawn619
Shawn619

Thanks!

The problem was the minus sign. :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.