Jogl not drawing within a loop

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Jogl not drawing within a loop

Nicholas
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.

Reply | Threaded
Open this post in threaded view
|

Re: Jogl not drawing within a loop

gouessej
Administrator
Hi

If you don't succeed in using your own OBJ loader, why not using one of the build-in OBJ loader from JOGL, JOGL-utils or Ardor3D?

Maybe your mesh is not in the view frustum.
Julien Gouesse | Personal blog | Website