PDA

View Full Version : missing triangles



zauron
05-03-2002, 01:37 AM
I have a problem loading models into my opengl app, i try to load .vtx files and it works great until the models get big, then there are triangles missing it seams. I use Anim8tor to model and export the files as .vtx. I am not very good at modelling so maybe that is the problem ;) neway here is some of my code that is interesting, i am building on nehe's tutorials.

class VERTEX{
public:
float x, y, z; // 3d coords
float u, v; // texture coords
};

class TRIANGLE{
public:
VERTEX vertex[3]; // the 3 verices
};

class SECTOR{
public:
int numtriangles; // number of triangles in this sector
TRIANGLE *triangle; // pointer to the triangles
VERTEX *normal; // pointer to the normals
};

Loading the file like this:

int ReadVtxString(char *b, FILE *f){
int tmp;
do{
fgets(b, 255, f);
/* nasty hack to get number of vertexes */
if(b[0] == '/'){
tmp = atoi(&b[3]);
if(tmp !=0){
MessageBox(NULL,"Ble ikke null","SHUTDOWN ERROR", 0);
return tmp/3;
}
}
}while(b[0] == '/' | | b[0] == ' ' | | b[0] == '\n' | | b[0] == '.');
return -1;
}

int LoadSectorVtx(SECTOR *s, char *filename){
char buff[255];
float x, y, z, u, v;
float nx, ny, nz;
FILE *file = fopen(filename, "r");
if(!file){
return FALSE;
}
s->numtriangles = ReadVtxString(buff, file);
s->triangle = new TRIANGLE[s->numtriangles];
s->normal = new VERTEX[s->numtriangles];
for (int triloop = 0; triloop < s->numtriangles; triloop++) // Loop Through All The Triangles
{
// Step Through Each Vertex In Triangle
for (int vertloop = 0; vertloop < 3; vertloop++) // Loop Through All The Vertices
{
ReadVtxString(buff, file); // Read String To Work With
// Read Data Into Respective Vertex Values
sscanf(buff, "%f %f %f %f %f %f %f %f", &x, &y, &z, &nx, &ny, &nz, &u, &v);
// Store Values Into Respective Vertices
s->triangle[triloop].vertex[vertloop].x = x; // Sector 1, Triangle triloop, Vertice vertloop, x Value=x
s->triangle[triloop].vertex[vertloop].y = y; // Sector 1, Triangle triloop, Vertice vertloop, y Value=y
s->triangle[triloop].vertex[vertloop].z = z; // Sector 1, Triangle triloop, Vertice vertloop, z Value=z
s->triangle[triloop].vertex[vertloop].u = u; // Sector 1, Triangle triloop, Vertice vertloop, u Value=u
s->triangle[triloop].vertex[vertloop].v = v; // Sector 1, Triangle triloop, Vertice vertloop, v Value=v
s->normal[triloop].x = nx;
s->normal[triloop].y = ny;
s->normal[triloop].z = nz;
}
}
fclose(file);
return TRUE;
}

Rendering like this:

int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(0.0f,0.0f,-36.0f);
glRotatef(deg, rx, ry, rz);
glBindTexture(GL_TEXTURE_2D, texture[0]); // Select Our Texture
for (int i = 0; i < sector1.numtriangles; i++){
glBegin(GL_TRIANGLES); // Start Drawing Triangles
glNormal3f( sector1.normal[i].x, sector1.normal[i].y, sector1.normal[i].z);
glTexCoord2f(sector1.triangle[i].vertex[0].u,sector1.triangle[i].vertex[0].v);
glVertex3f(sector1.triangle[i].vertex[0].x, sector1.triangle[i].vertex[0].y, sector1.triangle[i].vertex[0].z); // Set The TexCoord And Vertice

glTexCoord2f(sector1.triangle[i].vertex[1].u,sector1.triangle[i].vertex[1].v);
glVertex3f(sector1.triangle[i].vertex[1].x, sector1.triangle[i].vertex[1].y, sector1.triangle[i].vertex[1].z); // Set The TexCoord And Vertice

glTexCoord2f(sector1.triangle[i].vertex[2].u,sector1.triangle[i].vertex[2].v);
glVertex3f(sector1.triangle[i].vertex[2].x, sector1.triangle[i].vertex[2].y, sector1.triangle[i].vertex[2].z); // Set The TexCoord And Vertice
glEnd(); // Done Drawing Triangles
}
deg += 0.3f;
return TRUE; // Everything Went OK
}

Am i doing something wrong? Should i try getting another prog to model? or another format for my models?