Jump to content
  • Advertisement
Sign in to follow this  
Decrius

[SDL] Smooth/Colourful png

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

Hi, I load an .png into memory using SDL and C++. The image has a very smooth background gradient, but when I load it and display it, the gradient consists of thick bars (10 px approximatly) that looks a bit greenish or redish -> apparently it cannot find the colour defined in the png and looks for the nearest colour. I guess it has something to do with bits per pixel, but I dont know how. This is the code (not everything is included):
#ifdef __cplusplus
    #include <cstdlib>
#else
    #include <stdlib.h>
#endif
#ifdef __APPLE__
#include <SDL/SDL.h>
#else
#include <SDL.h>
#endif

#include <SDL_image.h>

int main (int argc, char** argv)
{
bool done = false;

if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0)
    {
        printf("Unable to init SDL: %s\n", SDL_GetError());
        return 1;
    }
    atexit(SDL_Quit);

SDL_Surface *screen = SDL_SetVideoMode(320, 120, 16, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_NOFRAME);
    if (!screen)
    {
        printf("Unable to set 640x480 video: %s\n", SDL_GetError());
        return 1;
    }

SDL_Surface *bg = IMG_Load("data/loading.png");

SDL_Rect dest;
dest.x = 0;
dest.y = 0;

while (!done)
    {
        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            switch (event.type)
            {
                case SDL_QUIT:
                {
                    done = true;
                    break;
                }

                case SDL_KEYDOWN:
                {
                    if (event.key.keysym.sym == SDLK_ESCAPE)
                    {
                        done = true;
                    }
                    break;
                }
            }
        }

        SDL_FillRect(screen, 0, color_bg);

        SDL_BlitSurface(bg, NULL, screen, &dest);

        SDL_Flip(screen);
    }

SDL_FreeSurface(bg);
return 0;
}
Thank you, Decrius

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!