Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Tilemap problem

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 Shawn619   Members   

342
Like
0Likes
Like

Posted 29 December 2012 - 09:07 PM

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



#2 Maus   Members   

1027
Like
0Likes
Like

Posted 30 December 2012 - 05:04 AM

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, 30 December 2012 - 05:05 AM.


#3 Shawn619   Members   

342
Like
0Likes
Like

Posted 30 December 2012 - 01:17 PM

Thanks!

The problem was the minus sign. :)






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.