Jump to content
  • Advertisement
Sign in to follow this  
Shawn619

OpenGL Tilemap problem

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

Share this post


Link to post
Share on other sites
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 Edited by MausGames

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!