Thread: C OpenGL Triangle Strips Grid

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    2

    C OpenGL Triangle Strips Grid

    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;
    }
    Last edited by opengluser; 03-23-2012 at 11:18 PM.

  2. #2
    Registered User
    Join Date
    Jun 2010
    Location
    In a house
    Posts
    15
    glbegin() is really old way. check out how to use VBO so you can just do one triangle then translate it to make your grid.

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    2
    I have solved the issue! I read up more on triangle strips and made an ultra loop! =D

    Edit: Also thanks for the tip, I'll check out VBO.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with the grid
    By wannabec++ in forum C++ Programming
    Replies: 2
    Last Post: 12-05-2010, 02:43 PM
  2. The Strips algorithm
    By Adak in forum General AI Programming
    Replies: 3
    Last Post: 10-19-2009, 02:08 PM
  3. comic strips
    By kermit in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 07-17-2005, 03:15 PM
  4. normals for triangle strips (oGL)
    By Perspective in forum Game Programming
    Replies: 8
    Last Post: 04-01-2003, 06:59 PM
  5. OpenGL Question...simple (triangle drawing stuff)
    By incognito in forum Game Programming
    Replies: 7
    Last Post: 03-15-2003, 08:47 PM

Tags for this Thread