Login  Register

Jogl not drawing within a loop

Posted by Nicholas on Sep 19, 2013; 1:23am
URL: https://forum.jogamp.org/Jogl-not-drawing-within-a-loop-tp4030066.html

I have working on an OBJ model loader in JoGL for a few days, and can obtain the vertices in the array draw: draw[face][vertex][x,y,z,or w] I have tried several ways to render this array (i.e. VBO's) but none have worked so far. I decided to attempt to render the face within a loop, however, when I run the program nothing is rendered. Here is my code:

 for(int i = 0; i < draw.length; i++){
        gl.glBegin(GL.GL_TRIANGLE_STRIP);
            //start drawing
            for(int i2=0;i2<draw[i].length;i2++){
                float[] xyzw = new float[4];
                //grab all the vertex values
                for(int i3=0; i3<draw[i][i2].length;i3++){
                    xyzw[i3]=draw[i][i2][i3];
                }
                gl.glColor3f(1.0f, 0.0f, 0.0f);    // Set the current drawing color to red
                gl.glVertex3f(xyzw[0], xyzw[1], xyzw[2]);
            }
        gl.glEnd();
    }
The peculiar thing is if I do this:

    for(int i = 0; i < draw.length; i++){
        gl.glBegin(GL.GL_TRIANGLE_STRIP);
            //start drawing
            for(int i2=0;i2<draw[i].length;i2++){
                float[] xyzw = new float[4];
                //grab all the vertex values
                for(int i3=0; i3<draw[i][i2].length;i3++){
                    xyzw[i3]=draw[i][i2][i3];
                }
                gl.glColor3f(1.0f, 0.0f, 0.0f);    // Set the current drawing color to red
                gl.glVertex3f(xyzw[0], xyzw[1], xyzw[2]);
                gl.glVertex3f(0.0f, 0.0f, 0.0f);   // Top
                gl.glColor3f(0.0f, 1.0f, 0.0f);    // Set the current drawing color to green
                gl.glVertex3f(1.0f, 0.0f, 1.0f); // Bottom Left
                gl.glColor3f(0.0f, 0.0f, 1.0f);    // Set the current drawing color to blue
                gl.glVertex3f(0.0f, 0.0f, 1.0f);  // Bottom Right
            }
        gl.glEnd();
    }
then I get a contorted shape, however without those extraneous vertices nothing is rendered.