Jump to content
  • Advertisement
Sign in to follow this  
xu564856686

SDL_image PNG's displayed with wrong colors

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

My program is a simple tic tac toe game, where x's and o's are represented by two PNG files, both solid color shapes with transparent backgrounds. They are loaded into memory with IMG_Load( "pathname" ) and blitted onto the game board SDL_Surface, which is then rendered to the screen.

 

The problem is that while the PNG for the x is green and the PNG for the o is red, in the game the x gets drawn as black and the o gets drawn as yellow. Originally the o was drawn as black as well, but changed to yellow after I added yellow text to the background PNG image. The other PNG images that get blitted onto the background (which do not have transparent backgrounds) show up with the correct colors.

 

This is my code for screen rendering:

 

// clear screen
SDL_RenderClear( renderer );
// get surface
SDL_Surface* surface = state->getSurface();
// create texture from surface
SDL_Texture* texture = SDL_CreateTextureFromSurface( renderer, surface );
//Render texture to screen
SDL_RenderCopy( renderer, texture, NULL, NULL );
//Update screen
SDL_RenderPresent( renderer );
// remove texture
SDL_DestroyTexture( texture );

 

I'm not sure if this is a problem with my screen rendering, surface blitting, or something else.

Share this post


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