Skip to main content
gamedev.net
🔒 Locked

texture mapping problem

Started by SelethD Sep 24, 2005 at 11:33 AM 4 replies 450+ views
Original Post
SelethD
SelethD
I am loading a .tga image to texture a quad, however somewhere along the way, something is wrong. My quad comes out white. I dont think the problem is in loading the .tga I think its in the 'binding' of that texture (not sure if thats the correct term) Or in the drawing of the quad with the texture. Here is some of the code I am placing the loaded .tga in this struct

struct sTexture									
{
	GLubyte	* imageData;	
	GLuint	bpp;	
	GLuint	width;									GLuint	height;									GLuint	texID;									GLuint	type;								

	sTexture() {imageData = NULL;}
	~sTexture() {Destroy();}
	void Destroy() {if (imageData!=NULL) free(imageData);imageData=NULL;}
};	

I believe that all .tga is correctly loaded into this struct, its the next step, the 'binding' that i think is incorrect, here is the function that does this.

bool LoadGLTexture(sTexture *texture,char *filename)				
{
	if (LoadTGA(texture,filename))
	{
		glGenTextures(1,&texture->texID);			
		glBindTexture(GL_TEXTURE_2D,texture->texID);
		glTexImage2D(GL_TEXTURE_2D, 0, texture->bpp / 8,texture->width, texture->height, 0, texture->type, GL_UNSIGNED_BYTE, texture->imageData);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

		texture->Destroy();		
		return true;
	}
	return false;								
}


now my main program creates an object of sTexture called text sTexture text; then then 'text' is sent to the above program like this LoadGLTexture (&text,"testpic.tga"); then the draw routine is ran, (below)

void Draw (void)
{
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity ();
	glTranslatef (0.0f, 0.0f, -6.0f);

	glBindTexture(GL_TEXTURE_2D, text.texID);
	
	glBegin(GL_QUADS);							
		glTexCoord2f(0.0f, 0.0f);glVertex3f( -1.0f, -1.0f,1.0f);
		glTexCoord2f(1.0f, 0.0f);glVertex3f(1.0f, -1.0f,1.0f);	
		glTexCoord2f(1.0f, 1.0f);glVertex3f(1.0f, 1.0f, 1.0f);
		glTexCoord2f(0.0f, 1.0f);glVertex3f( -1.0f, 1.0f, 1.0f);
	glEnd();
	glFlush ();
}

Thanks for any help you can give.
_the_phantom_
_the_phantom_
is the texture a power of two dimentions wise?
SelethD
SelethD
I guess I dont understand what that third arguement means.

I looked it up and it said 'internalformat'

can anyone explaine what that means?

In my loader program it takes the value of sTexture.bpp (which is 24, since its a 24bpp pic)


then it assigns GL_RGB to sTexture.type

I use this sTexture.type on the 'format' argument

my image is 128x128x24

SelethD
SelethD
I solved the problem

It was a stupid mistake

I forgot the line

glEnable(GL_TEXTURE_2D);


Topic Locked

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

Sign in to reply to this topic.