Assigning pointers

I seem to have a problem with assigning either display lists or textures in a class.

I have a class variable relating to a list or a texture which is instanciated when the object is created (for example a mesh object)

But when I use GenLists or whatever command is used to return a number in a method (say for example GetTexture which assigns a texture to the object) (GLuint) it returns rubbish , I know there is nothing wrong with the code itself as I have had to transfer it to Main() where it works fine.

What I am having to do is use GenList or the get texture command in Main() and pass the GLuint back to the class.

Any Ideas why it doesnt work?


when researching, i use similar methods.
a sphere class, for example, will hold informations with display lists and texture objects.
i got no troubles so far.

rubbish… makes me think about a recent problem i had with multithreading: is your application single-threaded ?


I assume it is single threaded as i am using windows 98.

My method is public and my variable that holds the pointer is protected. Just a thought, would I have to declare my class as public? at present I call it:

class objectname




where are you creating the display list? into the constructor?
if it so, make sure to instantiate your object only after opengl is initialized.

personally, i prefer to call a method like object.init() into a startup function wich is called when the application is running.


Yes I think your right!

Im trying to call it in the instanciation method, this explains a lot. I’ll follow your advice and create an init method.


Originally posted by David:

My method is public and my variable that holds the pointer is protected.

If you are you using a pointer like this:

int *list;
glGenLists(1, list);


Right ways:

  1. single list
    int list;
    glGenLists(1m, &list);

  2. array of lists
    int list[3];
    glGenLists(3, list);