PDA

View Full Version : Need help with GL_TRIANGLES



RobertSI
08-02-2000, 08:16 AM
//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();
}

Glenn Upton
08-02-2000, 08:32 PM
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.

Relic
08-02-2000, 11:01 PM
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++)

Gunfighter
08-03-2000, 07:44 PM
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]]);
}
}

RobertSI
08-04-2000, 05:29 PM
Thanks for your answer GUNFIGHTER my printer is warming up to print your reply http://www.opengl.org/discussion_boards/ubb/smile.gif