# OpenGL 2d grids

This topic is 3799 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
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 ViewportgluOrtho2D(0, p_iWidth, p_iHeight, 0);

and then use glVertex2f instead of glVertex3f

1. 1
Rutin
38
2. 2
3. 3
4. 4
5. 5

• 12
• 16
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633357
• Total Posts
3011502
• ### Who's Online (See full list)

There are no registered users currently online

×