Skip to main content
gamedev.net
🔒 Locked

Obj Loader Display List

Started by claptonguy 1 reply 1.3k views
Original Post
claptonguy
claptonguy
Hello. I made an obj loader as part of a game engine I am working on. It runs on GLUT and so far does not accept textures. The problem I have been having is that when I try to call the display list, or just draw the model over again, nothing shows up. I know the vertices are correct because the first few times I made it print out the vertices. I really would appreciate any help. Here is the code. object.h #ifndef OBJECT_H #define OBJECT_H #define MAX_VERTICES 10000 #define MAX_FACES 1000 #include #include #include #include #include class Object{ public: Object(char* filename, int objType); ~Object(); void draw(); protected: void loadObjFile(char* filename, int objType); void loadList(int objType); float vertices[MAX_VERTICES][3]; float normals[MAX_VERTICES][3]; float texCoords[MAX_VERTICES][3]; int faces[MAX_FACES][3][3]; int counter[5]; int otype; GLuint model; }; #endif and for object.cpp #include "object.h" Object::Object(char* filename, int objType) { loadObjFile(filename, objType); } Object::~Object() { } void Object::loadObjFile(char* filename, int objType) { FILE *fptr; fptr = fopen(filename, "r"); char token[1000]; while(!feof(fptr)) { fscanf(fptr, "%s", token); if(!strcmp(token,"v")) { fscanf(fptr,"%f %f %f", &vertices[counter[1]][0], &vertices[counter[1]][1], &vertices[counter[1]][2]); counter[1]++; } if(!strcmp(token, "vn")) { fscanf(fptr,"%f %f %f", &normals[counter[2]][0], &normals[counter[2]][1], &normals[counter[2]][2]); counter[2]++; } if(!strcmp(token, "vt")) { fscanf(fptr,"%f %f %f", &texCoords[counter[3]][0], &texCoords[counter[3]][1], &texCoords[counter[3]][2]); counter[3]++; } if(!strcmp(token, "f")) { if(objType==2) { fscanf(fptr,"%d/%d/%d", &faces[counter[4]][0], &faces[counter[4]][1], &faces[counter[4]][2]); }else{ fscanf(fptr,"%d//%d", &faces[counter[4]][0], &faces[counter[4]][2]); } counter[4]++; } counter[0]++; } fclose(fptr); } void Object::loadList(int objType) { model=glGenLists(1); glNewList(model,GL_COMPILE); int x=0; while(x[0],normals[1],normals[2]); glVertex3f(vertices

[0],vertices

[1],vertices

[2]); y++; } printf("\n"); glEnd(); x++; } glEndList(); } void Object::draw() { int x=0; while(x[0],normals[1],normals[2]); glVertex3f(vertices

[0],vertices

[1],vertices

[2]); y++; } printf("\n"); glEnd(); x++; } } Thanks

xZekex
xZekex
Its because display lists can't change. You have to use vertex buffer objects. And stop using FILE in C++ >.<. and use the source tags >.<
claptonguy
claptonguy
I am only loading the display list once. I don't understand how it's changing. And also the void Object::draw() is just supposed to be

void Object::draw()
{
glCallList(model);
}

not what is posted before.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.