Jump to content
  • Advertisement
Sign in to follow this  
SelethD

texture mapping problem

This topic is 4652 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
glTexImage2D(GL_TEXTURE_2D, 0, texture->bpp / 8,texture->width, texture->height, 0, texture->type, GL_UNSIGNED_BYTE, texture->imageData);

This line seems kinda funky. The third argument should be the number of color components in the picture (1, 2, 3 or 4), not bits per pixel. Especially not bitsperpixel / 8 (i'm guessing bpp means bit per pixel?). Also, I don't know what your sTexture->type is. Check out the spec on glTexImage2D and make sure you know what each argument should be.
Do you check for errors with glGetError and gluErrorString? You should. Always. Good luck,

Erik

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
glTexImage2D(GL_TEXTURE_2D, 0, texture->bpp / 8,texture->width, texture->height, 0, texture->type, GL_UNSIGNED_BYTE, texture->imageData);

This line seems kinda funky. The third argument should be the number of color components in the picture (1, 2, 3 or 4), not bits per pixel. Especially not bitsperpixel / 8 (i'm guessing bpp means bit per pixel?). Also, I don't know what your sTexture->type is. Check out the spec on glTexImage2D and make sure you know what each argument should be.
Do you check for errors with glGetError and gluErrorString? You should. Always. Good luck,

Erik

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!