I'm working on an .obj file loader for an opengl project I'm doing and I don't understand something that is happening. I made the class to load the object file in to certain vectors depending on the vertices, face, vertice normals, so on. But my problem comes from when I try to declare the class. I don't use any functions, all I do is declare it. I made two different projects, one an opengl and one a console so I could test it on both. For some reason it works just fine on the console program, but freezes and stops responding on the opengl project. The code for the class is kind of long so I'll just post what is needed, if anyone needs any more code just say so. And also, the two projects are using the exact same header file. Any help is appreciated!
EDIT: Ok wow... I'm an idiot *SLAMS HEAD ON DESK* I was declaring the class inside the load for the opengl render. It should have been inside the main window or global. It's better now.Code:/*INSIDE THE OPENGL PROGRAM*/ bool InitializeGL() { LOADOBJ obj; //this line is the problem, i comment it out and it works fine //if(obj.LoadObjFromFile("box.obj")) //MessageBox(NULL,"TEST","TEST",MB_OK); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Clear the screen to the specified color. glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); // Set up the information for the first light and set it in GL_LIGHT0. glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight); glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight); glLightfv(GL_LIGHT0, GL_POSITION, LightPosition); glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 130.0f); glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 75.0f); // Enable the first light. glEnable(GL_LIGHT0); // Set up the material information for our objects. glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); glMaterialfv(GL_FRONT, GL_SPECULAR, specularLight); glMateriali(GL_FRONT, GL_SHININESS, 128); // If all went well we return true. return true; } /*INSIDE THE CONSOLE PROGRAM*/ #include <iostream> #include "objloader.h" using namespace std; int main() { LOADOBJ obj; //this works without a problem, but I have no idea why //if(obj.LoadObjFromFile("box.obj")) //this function also works, it's been tested //cout<<"Object file loaded"<<endl; return 0; } /*FUNCTIONS FOR THE CLASS*/ class LOADOBJ { private: ObjectList *head; //head ptr in linked list of loaded object files int obj_load_count; //number of loaded object files void Destroy(); //destroys first link in the list ObjectList* GetNextSpace(); //get next available space in the linked list public: LOADOBJ(); //constructor ~LOADOBJ(); //destructor bool LoadObjFromFile(char*); //load object file int GetFileCount(); //get number of object files that have been loaded bool isEmpty(); //determines if the linked list is empty bool RenderAllObjects(); //render all the objects loaded in the linked list }; //end LOADOBJ class LOADOBJ::LOADOBJ() { obj_load_count = 0; //nothing is loaded so zero head = NULL; //pointer points to nothing } //almost 100% sure this functions works since I tested the loading function in //a console window and it can correctly store all the points, faces, etc. ObjectList* LOADOBJ::GetNextSpace() { if(head == NULL) return head; else{ ObjectList *temp = head; while(temp != NULL) temp = temp->next; return temp; } }



LinkBack URL
About LinkBacks


