I'm new to OpenGL and I'm trying to make a grid out of triangle strips. Say 10 by 10. I need to use an i and j loop right? What should i and j go up to and where should I place i and j in the triangle strip statements to make a grid? I really need help guys. Thank you in advance. (Note: I have i and j at 1 so people can see what it originally draws)
Code:
#ifdef _WIN32
#include <windows.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -2.0f); /* "zoom" back 2 units */
glRotatef(45.0f, 1.0f, 0.0f, 0.0f); /* rotate to look down at 45 degrees */
/* glutWireTeapot(1.0f); */
/* Wireframe */
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
int i, j; /* Variables for loop */
for(j = 0; j < 1; j ++)
{
for(i = 0; i < 1; i++)
{
glBegin(GL_TRIANGLE_STRIP);
/* -1 */ /* Vertices A-E */
glVertex3f(-1.0f, -0.5f, -4.0f); /* A */
glVertex3f(1.0, -0.5f, -4.0f); /* B */
glVertex3f(0.0f, 0.5f, -4.0f); /* C */
/* Original D code glVertex3f(1.5f, 0.0f, -4.0f); */
glVertex3f(1.5, 0.5f, -4.0f); /* D */
/* Original E code glVertex3f(2.0f, -1.5f, -4.0f); */
/* glVertex3f(3.0f, -1.5f, -4.0f); */ /* E */
} /* End of loop */
}
glEnd();
glutSwapBuffers();
}
void reshape(int w, int h)
{
float aspect = w / (float)h;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(75.0f, aspect, 0.01f, 100.0f);
glMatrixMode(GL_MODELVIEW);
}
void keydown(char key, int x, int y)
{
printf("Toggle wireframe\n");
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Grid Test");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
/* Put wireframe toggle call here */
glutMainLoop();
return 0;
}