glGenTextures problem in MFC app

I am doing a very elementary OpenGL application under Windows, and am using MFC. I know, it’s a performance pig, but I’m just trying to get my head around the big picture of OpenGL.

However, whenever I call glGenTextures in the application, no texture number is generated. glGetError returns GL_INVALID_OPERATION. According to the documentation, this only can happen if glGenTextures is called between glBegin and glEnd.

I have checked exhaustively, including adding code at the earliest possible place in my code, and am certain that I am not calling glBegin before the glGenTextures call.

I’ve built some GLUT demos on my machine that use texture objects and traced through them, and they all perform as expected. Has anyone seen anything like this, or can anyone help a flustered newbie with this?

Thanks in advance for any suggestions!

  • Steve

Does your code look something like this:

  glGenTextures	(1, &textureID[0]);					// Generate space for Texture Objects

I have a class I am using for maintaining individual textures, so it’s more along the lines of:

GLuint m_nTextureID; // this is declared in the header file
.
.
.

glGenTextures (1, &m_nTextureID); // this is called when I load a texture

I’m hoping that there is something really obvious I’m doing here, and I’ve just being staring at the code too long to see it.

  • Steve

Dunno… I was hoping for summit obvious 2.

Can you post a pointer to the code?

When you call glGenTextures have you created a resource context and set it up as the current context? I am fairly sure that no GL functions will work till you have done that

Yeah, Make sure you call glGenTex after you make the context current. Otherwise you would get the INVALID_OPERATION error that you noted…

Jeremy

Well, I feel sheepish. Yes, I was trying to call the function outside of a valid render context. Things are working much better now the performance gain is pretty staggering too.

Thanks to all who replied!

  • Steve