save me from glGenTextures-induced baldness!

Can people please tell my what kind of variable you’re using to store what glGenTextures() gives you.

Currently I have

unsigned int textureID[MAX_TEXTURES];

and I call

glGenTextures(1, &textureID[0]);

and when I do an
fprintf(f, “%d”, texture[0]);

I usually get a 0, or sometimes a negative number…

this is vexing me more than I can say, as I have identical code running in two projects, and one texturemaps, and the other doesnt…

Heeeeeelpp!!!

At least for the negative values there is a simple explanation:
Don’t use %d but %u cause %d is for SIGNED ints only!
The type you’re using is correct. Although you should use the OpenGL type GLuint instead.

void glGenTextures(GLsizei n, GLuint *textures);

So GLuint is right, but unsigned int would also almost certainly work.

  • Matt

Are you sure you have set your rendering context and everything before you do your glGenTextures? Otherwise, I think it will give you zeros.

What a %d%umbass!

Thankyou for your help guys, it’s working like a dream!

It was being called in my init code before the window was actually created…

Cheers!