I have a couple of problems regarding images that I wonder if others can
duplicate (and explain).
They may be entirely different problems, on the other hand they may
arise from the same
The problems concern errors in displaying images. Images do not display
at all without a delay inserted in the program
and they may not be displayed correctly.
I demonstrate the first with the code example from SDL_GetWindowSurface:
#include <SDL.h> // include SDL header
int main(int argc, char* argv)
SDL_Surface *screen; // even with SDL2, we can still bring ancient
SDL_Init(SDL_INIT_VIDEO); // init video // create the window like normal window = SDL_CreateWindow("SDL2 Example", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
// but instead of creating a renderer, we can draw directly to the
screen = SDL_GetWindowSurface(window);
// let's just show some classic code for reference image = SDL_LoadBMP("box.bmp"); // loads image SDL_BlitSurface(image, NULL, screen, NULL); // blit it to the screen SDL_FreeSurface(image); // this works just like SDL_Flip SDL_UpdateWindowSurface(window); // show image for 2 seconds SDL_Delay(2000); SDL_DestroyWindow(window); SDL_Quit(); return 0;
compiled with: gcc -o example -g -Wall -O0 -D_GNU_SOURCE
sdl2-config --libs --cflags example.c
- The example gives no output to the window.
- Debugging step by step with gdb gives the expected image.
- Inserting ‘SDL_Delay(1000);’ after the ‘screen =
SDL_GetWindowSurface(window);’ command gives the expected result.
The second problem seems to indicate a problem with a specific
resolution of the image.
Using the code with the delay , I try the same image at several resolutions:
- 100x100 works OK
- 1000x1000 works OK
- 200x200 shows some sort of clipping of the image in the region of the
very dark pixels. These areas display in various colours.
If I replace ‘image = SDL_LoadBMP(“horse_200x200.bmp”);’ by ‘image =
IMG_Load(“horse_200x200.bmp”);’, the image is displayed correctly. But I
still need the delay to display anything.
I am running Debian wheezy (current stable) with Linux kernel 3.10.10-amd64.
I have reinstalled SDL2-2.0.1, the results don’t change.