Jump to content
  • Advertisement
Sign in to follow this  
MickeMan

Texture looks wierd

This topic is 4005 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 have a sphere where I map a texture to it. heres how it looks with the texture: But looking at the texture image we can see that it shouldnt look that way: If I remove the light source the texture looks like a negative image of the original image. Heres my setup:
int GraphicHandler::InitGL(GLvoid)						
{
	glEnable(GL_TEXTURE_2D);
	glShadeModel(GL_SMOOTH);						
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);			
	glClearDepth(1.0f);							
	glEnable(GL_DEPTH_TEST);						
	glDepthFunc(GL_LEQUAL);							
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);		
	GLfloat ambientLight[] = {0.3f, 0.3f, 0.3f, 1.0f};
	GLfloat diffuseLight[] = {0.7f, 0.7f, 0.7f, 1.0f};
	GLfloat specular[] = { 1.0, 0.0, 0.0, 1.0 };
	GLfloat shininess = 65.0;

	glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
	glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
        glLightf(GL_LIGHT0, GL_SHININESS, shininess);
	glEnable(GL_LIGHT0);

	GLfloat lightPos[] = {0.0f, 0.0f, 0.0f, 1.0f };
	glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
	glEnable(GL_LIGHTING);
	glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
	return TRUE;						
}
Heres the render:
int GraphicHandler::RenderGLScene(GLvoid)					
{	
	glEnable(GL_LIGHTING);
	
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
	glEnable(GL_TEXTURE_2D);

	glLoadIdentity();								camera.Render();
	glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
	tmppos -= 0.02f;
	sphere->SetPos(0.0f, 0.0f, tmppos);
	
	sphere->Render();
	
	glDisable(GL_LIGHTING);
	glDisable(GL_TEXTURE_2D);

        //render other stuff here
	
	return TRUE;								
}
And heres the models render function
void Model::Render()
{
	glPushMatrix();
	
	glTranslatef(pos_x, pos_y, pos_z);
	glRotatef(rot_angle, rot_x, rot_y, rot_z);
	
	if(texture == -1)
	{
		glDisable(GL_TEXTURE_2D);
	}
	else
	{
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, texture);
	}
	
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);
	glTexCoordPointer(2, GL_FLOAT, 0, vUVCoords);
	glVertexPointer(3, GL_FLOAT, 0, vVerts);
	glNormalPointer(GL_FLOAT, 0, vNormals);
	glDrawElements(GL_TRIANGLES, numfaces*3, GL_UNSIGNED_SHORT, uiIndexes);

	glPopMatrix();
}

And heres the image loader, using FreeImage
int Texture::Load(char *filename)
{
	
	FIBITMAP* bitmap = FreeImage_Load(FIF_JPEG, filename, JPEG_QUALITYSUPERB);
	
	if(!bitmap)
		return -1;
	
	int free_text = GetLastFree();

	glGenTextures(1, &textures[free_text]);					// Create The Texture

	glBindTexture(GL_TEXTURE_2D, textures[free_text]);
	
	int w = FreeImage_GetWidth(bitmap);
	int h = FreeImage_GetHeight(bitmap);
	
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, FreeImage_GetBits(bitmap));
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	FreeImage_Unload(bitmap);
	return textures[free_text];
}
I figured the problem is with the parameters to glTexImage2D. I've tried setting GL_RGB8 and GL_RGB parameters to pretty much every other availible options, some crashes the application while others make the image look wierder och not displaying the texture at all. I've also tried changing bitdepth on my images and even loading another format, like png, jpeg, but without any success. What am I doing wrong? EDIT: screenshots [Edited by - MickeMan on November 1, 2007 9:57:58 AM]

Share this post


Link to post
Share on other sites
Advertisement
No the problem is still there, the only thing I fixed was the screendumps that displayed the wrong pictures.

After a little bit more research I can detemine that the texture problem is basically this:

Blue colors become red
Red colors become blue
Green colors remain and are displayed accuratly.

Thats basically the problem.

Share this post


Link to post
Share on other sites
I would suspect your texture loading code. I don't know OpenGL, but if it is like you say (colors being swapped), thats what I would suspect.

Share this post


Link to post
Share on other sites


Thank you!


Changed the glTexImage2D to:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, FreeImage_GetBits(bitmap));


:)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!