Jump to content
  • Advertisement
Sign in to follow this  
ekrax

first attempt at 3d platformer ...

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

hello, this is my first attempt at a 3d platformer (really basic) i use a tile map and a height map, so there basically cannot be rooms under blocks or anything, its sorta top down ... it works alright, the only problem i am having is artifacts. if i draw it looking straight down it looks really stupid becasue there is no perspective of depth or the z axis, so i want to rotate everything so i simply call glRotatef and rotate it along the x axis and change the offset on the y axis so everything fits nicely on the screen, but when i do this artifcats pop up everywhere ... the levels are made up of cubes where the front and back are textured 1 image and all sides the other (the map is draw so that z is the height, x and y lengths ... so u dont look down on the map but really look straight at it, giving the appearence of top down) but anyways the code is like this ...
for (int y = 0; y < ySize; y ++)
{
	for (int x = 0; x < xSize; x ++)
	{
		if (tileMap[x][y])
		{
			for (int h = 0; h >= -(heightMap[x][y]); h -- )
			{
				glLoadIdentity ();
				glRotatef (-32.0f, 1.0f, 0.0f, 0.0f);
				glTranslatef ((float) (x * 2) - 24.0f, (float) (y * 2) -12.0f, (-h * 2) - 26.0f);
				drawCube (1, textures[0], textures[1]);
			}
		}
	}
}



im thinking i shoudnt have glRotate there and maybe somewhere else? or should i use a camera and raise it in refrence to the orgin and then angle it so its about 30 degrees? thanks for any help or suggestions in advance. EDIT: i should note the draw cube function will draw in 1 unit from the orgin so, its really a 2x2 cube, and i have the offsets when translating because i want everything centered and about 24 blocks to fit across and up and down the screen.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by ekrax
it works alright, the only problem i am having is artifacts.

I take it you mean graphical artifacts (i.e. polygons drawn over each other, etc.), and the primary reason I can think of for that is that you may not be using the depth buffer.
Off the top of my head, try adding this to the beginning of your drawing code (before any drawing code is called, and you may have to check your window is created with about 8 bits of depth)

glEnable(GL_DEPTH_TEST):
glDepthFunc(GL_LEQUAL);


Hope this helps,

SwiftCoder

Share this post


Link to post
Share on other sites
it was enabled and my window is using 16 bits, is it possible that this is resulting from how i draw my cubes?


void drawCube (float size, GLuint texture1, GLuint texture2)
{
glEnable (GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, texture1);
glColor3f (1.0f, 1.0f, 1.0f);
for (int z = -1; z < 2; z += 2)
{
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 1.0f); glVertex3f (-size, -size, (GLfloat) z * size);
glTexCoord2f (1.0f, 1.0f); glVertex3f (size, -size, (GLfloat) z * size);
glTexCoord2f (1.0f, 0.0f); glVertex3f (size, size, (GLfloat) z * size);
glTexCoord2f (0.0f, 0.0f); glVertex3f (-size, size, (GLfloat) z * size);
glEnd ();
}
glBindTexture (GL_TEXTURE_2D, texture2);
for (int z = -1; z < 2; z += 2)
{
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 1.0f); glVertex3f (-size, (GLfloat) z * size, -size);
glTexCoord2f (1.0f, 1.0f); glVertex3f (size, (GLfloat) z * size, -size);
glTexCoord2f (1.0f, 0.0f); glVertex3f (size, (GLfloat) z * size, size);
glTexCoord2f (0.0f, 0.0f); glVertex3f (-size, (GLfloat) z * size, size);
glEnd ();
}
for (int z = -1; z < 2; z += 2)
{
glBegin (GL_QUADS);
glTexCoord2f (0.0f, 1.0f); glVertex3f ((GLfloat) z * size, -size, -size);
glTexCoord2f (1.0f, 1.0f); glVertex3f ((GLfloat) z * size, size, -size);
glTexCoord2f (1.0f, 0.0f); glVertex3f ((GLfloat) z * size, size, size);
glTexCoord2f (0.0f, 0.0f); glVertex3f ((GLfloat) z * size, -size, size);
glEnd ();
}
glDisable (GL_TEXTURE_2D);
}




it just draws front back, top bottom, then left right ... should i by using GL_TRIANGLES or something?

Share this post


Link to post
Share on other sites
i guess actually they arent artifacts but pieces of the side textures that show throught the ground, if i put a 8 cuvbs by 8 cubes together i can see in some sopots the texture that is on the side of the cube but it shows on top.

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!