Jump to content
  • Advertisement
Sign in to follow this  
giugio

OpenGL Opengl grids

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

Hy i'm a beginner in opengl ad i have this problem: i not understand this code: glPointSize(4.0); glBegin(GL_POINTS); for (int x = 0; x < 4; x++) for (int z = 0; z < 4; z++) glVertex3f(x, 0, z); glEnd(); Ths code create a points grid,but why? i'm not understand why use the z coordinate(the depth)and not the y coordinate! the grid Indeed appear in 2d. thanks I have the same problem with this grid: glBegin(GL_TRIANGLES); for (int x = 0; x < 3; x++) { for (int z = 0; z < 3; z++) { glVertex3f(x, 0.0, z); glVertex3f((x+1.0), 0.0, z); glVertex3f(x, 0.0, (z+1.0)); } } glEnd(); why the x+1 and z+1?(is a new point?) thanks.

Share this post


Link to post
Share on other sites
Advertisement
Actually this is very simple

Why y is 0 ? Well you don't want the grid to go upwards you want it on the lowest level of height.

Here is how i create a grid :

Gl.glBegin(Gl.GL_LINES);
for (int i = -5; i <= 5; ++i)
{
Gl.glVertex3i(i, 0, -5);
Gl.glVertex3i(i, 0, 5);

Gl.glVertex3i(5, 0, i);
Gl.glVertex3i(-5, 0, i);

}

Share this post


Link to post
Share on other sites
If you want a horizontal grid and not a vertical one, you need to lay it in the xz-plane (since y is up [smile]). So the y-value just sets the height of the grid.

The second loop inserts some points to make a triangle (see the GL_TRIANGLES?). Since most of those points are use more than once (in two iterations of the outer loop x and x+1 are the same: if x = 0 then x + 1 = 1, next iteration x = 1 so x + 1 = 2, you see x + 1 = 1 and x = 1 are the same in two iterations).
That loop basically draws a bunch of triangles like this:

|\

|_\


So the "grid" would look like this:

|\ |\ |\

|_\|_\|_\

|\ |\ |\

|_\|_\|_\

|\ |\ |\

|_\|_\|_\

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!