Jump to content
  • Advertisement
Sign in to follow this  
giugio

OpenGL 2d grids

This topic is 3708 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 begin to learn opengl , with the book "Beginning OpenGL Game Programming". I find 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(); this code generate a 2d grid of point ,but why if it's a 2d grid increment the z coordinate? i have the same problem whith this code: 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(); thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
I think the phrase "2D Grid" is used to describe what is seen rather than the actual functionality in the code.

The grid drawn changes in the X and Z axis, therefore resulting in a flat grid and when viewed from above looks 2D.

If you want to use propper 2D graphics define the 2D orthographic projection matrix


glViewport(p_iXPosition, p_iYPosition, p_iWidth, p_iHeight);

//Set Up Ortho Mode To Fit the Viewport
gluOrtho2D(0, p_iWidth, p_iHeight, 0);


and then use glVertex2f instead of glVertex3f

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!