Jump to content
  • Advertisement
Sign in to follow this  
xissburg

OpenGL OpenGL rendering incorrect texture colors

This topic is 3208 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

To load a texture from file and properly render it in OpenGL has been seriously boring me and...well that turned into a whole history now.. Since I'm using SDL in the project, I chose to use SDL_LoadBMP to load a texture (this project is very simple CG wise). And SDL loads it, and correctly. But when I render it as a texture in OpenGL The texture gets a greenish-brownish appearance. Then I loaded a texture with 100% red, blue and green large strips, took a screenshot of my app and color picked it in Photoshop (lighting is off). Then I noticed that the red and green are at 100% but the blue is at 50%. I really don't know what else I can do :/ HALP My simple load texture code:
SDL_Surface* surface = SDL_LoadBMP("groundTexture.bmp");

	if(surface == NULL)
	{
		std::cout << "Failed to load groundTexture.bmp" << std::endl;
		return;
	}

	Uint8 nOfColors = surface->format->BytesPerPixel;
	GLenum textureFormat = GL_RGBA;

    if (nOfColors == 4)     // contains an alpha channel
    {
        if (surface->format->Rmask == 0x000000ff)
                textureFormat = GL_RGBA;
        else
                textureFormat = GL_BGRA_EXT;
    } 
	else if (nOfColors == 3)     // no alpha channel
    {
        if (surface->format->Rmask == 0x000000ff)
                textureFormat = GL_RGB;
        else
                textureFormat = GL_BGR_EXT;
    }
        
	glGenTextures( 1, &groundTexture );
	glBindTexture( GL_TEXTURE_2D, groundTexture );
 
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	//glTexParameterf(GL_TEXTURE_2D, 0x84FE, 8);//hardcoded anisotropy
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);

	gluBuild2DMipmaps(GL_TEXTURE_2D, nOfColors, surface->w, surface->h, 
						textureFormat, GL_UNSIGNED_BYTE, surface->pixels);
	/*glTexImage2D( GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0,
                      textureFormat, GL_UNSIGNED_BYTE, surface->pixels );*/
	glBindTexture(GL_TEXTURE_2D, 0);

Thanks

Share this post


Link to post
Share on other sites
Advertisement
Do you have other states set that affects the final color? For example, unless changed, the default texture combiner function is to modulate the primary color by the texture color, so if the primary color is set to some brown tone, you will have a brown tone on your texture also. Either set the primary color to white, or, which is the proper solution, set the combiner function to GL_REPLACE if you don't want anything to output the texture color without modification.

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!