Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Tilemap problem

This topic is 2148 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:


int mapSize = 10;
int tileSize = 20;
glBindTexture(GL_TEXTURE_2D, skyTexture);
for(int i=0; i<mapSize; i++){
for(int j=0; j<mapSize; j++){
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));



My individual tile looks like this:



Tile map output:


Share this post

Link to post
Share on other sites
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!