Class declaration problems

This is a discussion on Class declaration problems within the C++ Programming forums, part of the General Programming Boards category; I'm working on an .obj file loader for an opengl project I'm doing and I don't understand something that is ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    416

    Class declaration problems

    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!

    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&#37; 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;
        }
    }
    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.
    Last edited by scwizzo; 12-01-2008 at 08:13 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  2. Class Declaration
    By enjoy in forum C++ Programming
    Replies: 4
    Last Post: 03-10-2006, 10:59 AM
  3. Replies: 3
    Last Post: 10-31-2005, 12:05 PM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21