Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Need help with GL_TRIANGLES

  1. #1
    Intern Contributor
    Join Date
    Apr 2000
    Location
    Staten Island New York
    Posts
    53

    Need help with GL_TRIANGLES

    //I converted a simple bent tube in 3dMax to a 3ds file and got the coordinates with Crossroads.
    //and changed the array around to GLfloat Tube01[][3] = {........etc.};
    //The shape renders in GL_POINTS, but is all screwed up in GL_TRIANGLES, please help.
    //No lighting is used, triangles seem missing.
    //I didnt use any of the OpenGL array functions because I don't know if you can get unknown nth elements with them
    void display(void)
    {
    int i,arraySize,numVertx;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(1.0,0.0,0.0);

    //this finds the number of elements and vertices in n-Array
    //num of bytes in array divided by size of element type 'GLfloat'
    arraySize = sizeof(Tube01)/4;
    //num of elements in vertex - x,y,z
    numVertx = arraySize/3;

    glPushMatrix();
    glRotatef(rotate,1.0,0.0,0.0);

    glBegin(GL_POINTS);
    //step through the array vertices
    for(i = 1; i <= numVertx;i++)
    {
    glVertex3fv(Tube01[i]);
    }
    glEnd();
    glPopMatrix();

    glutSwapBuffers();
    }

  2. #2
    Intern Contributor
    Join Date
    May 2000
    Location
    Ottawa, Ontario, Canada
    Posts
    77

    Re: Need help with GL_TRIANGLES

    Could be stupid answer but look at your file and put an 'f' after each number, also make sure that each number has a decimal point as in '0.0f,'. Seems dunb to me too but is what I had to do when I generated normals to a file and then put them into an array.

  3. #3
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,527

    Re: Need help with GL_TRIANGLES

    Looks like a typical Pascal to C problem:
    Are you sure that the array is from 1 to numVertex?
    C arrays start at 0.
    Try this
    for(i = 0; i < numVertx; i++)

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2000
    Location
    Volta Redonda, RJ, Brazil
    Posts
    9

    Re: Need help with GL_TRIANGLES

    It seems that you are only storing Vertices data (You have only a n x 3 matrix of float). That does fine for GL_POINTS, but if you intend using faces, you need Faces data too.

    (If I'm wrong and you're storing faces data elsewhere, please ignore this post)

    In my own Model Loading code, I used a vector of vertices, and a vector of Faces, each face being a Triplet of vertex indices.

    E.G. : For a simple Quadrilateral :

    1 3 5

    2 4 6

    Vertices : 1,2,3,4,5,6 (their coords are in the vertices vector)
    Faces :
    1-1,2,3
    2-2,3,4
    3-3,4,5
    4-4,5,6

    Thus, the code for making points is the one you've made, but for making Faces, it would be :

    glBegin(GL_TRIANGLES)
    for j from 1 to maxfaces {
    for i from 1 to 3 {
    glvertex(vertices[faces[j][i]]);
    }
    }

  5. #5
    Intern Contributor
    Join Date
    Apr 2000
    Location
    Staten Island New York
    Posts
    53

    Re: Need help with GL_TRIANGLES

    Thanks for your answer GUNFIGHTER my printer is warming up to print your reply

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •