#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
[SDL] Smooth/Colourful png
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):
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement