Advertisement

glGenTextures question

Started by February 03, 2004 04:47 PM
3 comments, last by Marty666 21 years, 1 month ago
glGenTextures doesn''t seem to put the texture number in holder. What am i doing wrong? Thanx, Marty PS: This is the source:

GLuint LoadTexture(char *filename)
{
	static GLuint holder;
	AUX_RGBImageRec *TextureImage[1];							// storagespace for 1 texture

	memset(TextureImage,0,sizeof(void *)*1);					// clear the mem

	if (TextureImage[0] = LoadBMP(filename))					// load the file

	{
		glGenTextures(1, &holder);								// create space for texture

		glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
		glBindTexture(GL_TEXTURE_2D, holder);						// bind the loaded texture

		glTexImage2D(	GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, 
						GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); // set params

		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // set params

		gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
		if (TextureImage[0])
		{
			if (TextureImage[0]->data) 
			{
				free(TextureImage[0]->data);		// free the loaded bmp

			}
			free(TextureImage[0]);					// and the memory

		}
	}
	else
	{
		MessageBox(NULL, filename, "Error loading file", MB_OK);
		exit(0);
	}
	return holder;
}
_____ /____ /|| | || MtY | ||_____|/Marty
Are you calling this code before you have a valid OpenGL context?

Enigma
Advertisement
yes. I''m using glut... I do call it before opening the context, because I give feedback in the same window as glut is going to use. I did glEnable(GL_TEXTURE_2D). Isn''t that enough?

Thanx,
Marty
_____ /____ /|| | || MtY | ||_____|/Marty
You have to create a window and set up a context before you do any Opengl calls
You have to have a valid context before you start calling OpenGL commands. With glut I think the context is created when you make the glutCreateWindow call, so just call your OpenGL initialisation after that.

Enigma

This topic is closed to new replies.

Advertisement