Skip to main content
GameDev.net gamedev.net
🔒 Locked

Texture Not Showing Up?

Started by Darobat Nov 7, 2004 at 10:37 AM 8 replies 700+ views
Original Post
Darobat
Darobat
Greetings I am working on a wrapper for textures, but for some reason the textures are not showin up. Heres some of the code for it:
bool CTexture::CreateTexture(tString filename)
{
	AUX_RGBImageRec	*textureImage = NULL;

	// Create the texture
	textureImage = LoadBitmap(filename);

	if(!textureImage)
		return false;

	glGenTextures(1, &texture);

	glBindTexture(GL_TEXTURE_2D, texture);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	gluBuild2DMipmaps(GL_TEXTURE_2D, 3, textureImage->sizeX, textureImage->sizeY, GL_RGB, 
		GL_UNSIGNED_BYTE, textureImage->data);

	if(textureImage->data)
		free(textureImage->data);
	free(textureImage);

	return true;
}

void CTexture::Bind()
{
	// Bind the texture
	glBindTexture(GL_TEXTURE_2D, texture);
}

void EnableTextures()
{
	if(!glIsEnabled(GL_TEXTURE_2D))
		glEnable(GL_TEXTURE_2D);
}

void DisableTextures()
{
	if(glIsEnabled(GL_TEXTURE_2D))
		glDisable(GL_TEXTURE_2D);
}

then I have RenderScene() which looks like:
void RenderScene()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	glTranslatef(0.0, 0.0, -6.0f);

	EnableTextures();
	angsty.Bind();
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f,  0.0f);	// Top Left
		glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f,  1.0f,  0.0f);	// Top Right
		glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f,  -1.0f, 0.0f);	// Bottom Right
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f);	// Bottom left
	glEnd();
}

However, the square is still just white. Whats happening? Note, angsty is 218 by 212. This shouldnt be a problem because I'm mipmapping. Also, even if I dont use mipmap it still doesnt show up. This is probably a stupid error that you will notice pretty fast. Thanks.
--------------------C++ Home - Check it out!Lol... - Amazing video
ube
ube

opengl (prior to version 2.0) supports afaik only textures with dimensions which are powers of two. Did you check all return values and / or called glGetError() to find the problem?
mikeman
mikeman
Quote:

opengl (prior to version 2.0) supports afaik only textures with dimensions which are powers of two


gluBuild2DMipmaps scales the texture to a power of 2 image, and then generates the mipmaps, so this isn't the problem.

What is the "LoadBitmap" function? As far as I know, glaux don't have such a function. Also, try setting glPixelStoref(GL_UNPACK_ALIGNMENT,1) and see if that helps.
Darobat
Darobat
LoadBitmap() is my own function. How do I find out what OGL version I have?
--------------------C++ Home - Check it out!Lol... - Amazing video
mikeman
mikeman
It doesn't matter what OGL version you have, this should work everywhere. Are you sure you LoadBitmap() works? Maybe you should post that too. Did you try to set the GL_UNPACK_ALIGNMENT to 1?
Darobat
Darobat
AUX_RGBImageRec *CTexture::LoadBitmap(tString filename){	FILE *file = NULL;	if(filename.empty())		return NULL;	file = fopen(filename.c_str(), "r");	// If it exists, close the file and load it.	if(file)	{		fclose(file);		return auxDIBImageLoad(filename.c_str());	}	return NULL;}


Where would i put the Unpack stuff?
--------------------C++ Home - Check it out!Lol... - Amazing video
Darobat
Darobat
I put the glPixelStoref() after my glTexParameteri()'s and still no texture. CreateTexture() does return true.

if(!angsty.CreateTexture("angsty.bmp"))	{		MessageBox(NULL, "Could not load angsty.bmp!", "Error!", MB_OK);		return 0;	}


It's the first thing in Winmain.

EDIT: I just moved it to after window.CreateWindow() and It loads. Whats with that?
--------------------C++ Home - Check it out!Lol... - Amazing video
mikeman
mikeman
Okay, one last guess: you do have created a valid GL rendering context before you load the textures right? You can't use GL commands if you don't have a rendering context.
I'm saying that because you said the CreateTexture() is the first thing in WinMain.

-EDIT:
Quote:

I just moved it to after window.CreateWindow() and It loads. Whats with that?


I just saw that. Well, I think I just explained what's wrong. You make GL calls, like glGenTextures, before you even create a GL rendering context. You can't do that.
Darobat
Darobat
That makes sense. Thanks!
--------------------C++ Home - Check it out!Lol... - Amazing video

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.