Help !
I wrote a code like in lesson 10..drawing an object from files such as nodes.txt(includes indexnumber,x,y,z) triangles.txt(includes indexnumber,nodenumber1,node2,node3,edge1,edge2,edge3)
edge.txt(includes indexnumber,node1,node2). According to this created a structure such as;
struct nodes
{
int nodeno;
float x;
float y;
float z;
} ;
struct edges
{ int edgeno;
int node1;
int node2;
} ;
struct triangles
{ int triangleno;
int node1;
int node2;
int node3;
int edge1;
int edge2;
int edge3;
};
struct nodes n[200];
struct edges e[200];
struct triangles t[200];
...........
And then,I used the following for reading from each file.
This was the firstfile(nodes.txt)
for (int loop1 = 0; loop1 <totalnodes ; loop1++)
{
readstr(filein1,oneline1);
sscanf(oneline1, "%d %f %f %f\n ", &nno, &xx, &yy, &zz);
n[loop1].nodeno=nno;
n[loop1].x=xx;
n[loop1].y=yy;
n[loop1].z =zz;
}
......
And the following is for drawing..
for (int loop_m = 0; loop_m < totaltri; loop_m++)
{
glBegin(GL_TRIANGLES);
glNormal3f( 0.0f, 0.0f, 0.0f);
n1=t[loop_m].node1;
n2=t[loop_m].node2;
n3=t[loop_m].node3;
x_t=n[n1].x;
y_t=n[n1].y;
z_t=n[n1].z;
glVertex3f(x_t,y_t,z_t);
glColor3f(0.0f,1.0f,1.0f);
x_t=n[n2].x;
y_t=n[n2].y;
z_t=n[n2].z;
glVertex3f(x_t,y_t,z_t);
glColor3f(0.0f,1.0f,0.0f);
x_t=n[n3].x;
y_t=n[n3].y;
z_t=n[n3].z;
glVertex3f(x_t,y_t,z_t);
glColor3f(0.0f,0.0f,1.0f);
glEnd(); }
The code has no errors but doesnt work... what seems to be wrong?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement