Hi, I have a question relating to my use of SDL.
Below is the code. it seems to compile fine. However, it doesn’t
function as it is intended and I don’t know why. Hopefully somebody can
shed some light on the matter. My question is:
Even though (i think) I’m using SDL_DOUBLEBUF with SDL_flip, i still get
splits in my screen. It appears not to be updating on the screen
refresh. Now, I am using a Laptop with a TFT screen. Is this going to
affect things?
Many Thanks
Henry Gomersall
/test.c/
#include “SDL/SDL.h”
#include <stdio.h>
#include <sfftw.h>
#define DISPLAY_RES_X 320
#define DISPLAY_RES_Y 240
int main() {
/* set various SDL variables */
SDL_Surface *screen;
SDL_Color colour[1];
SDL_Event keyboard_check;
SDL_PixelFormat *colour_format;
/* Initilise SDL */
printf(" SDL.\n");
/* Initialize the SDL library */
if( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr,
“Couldn’t initialize SDL: %s\n”, SDL_GetError());
exit(1);
}
if(SDL_VideoModeOK(DISPLAY_RES_X, DISPLAY_RES_Y, 32, SDL_FULLSCREEN |
SDL_HWSURFACE | SDL_DOUBLEBUF) != 32)
fprintf(stderr, “video mode not possible on this hardware\n”);
/* requesting a 32 bit hardware surface with a hardware palette */
screen = SDL_SetVideoMode(DISPLAY_RES_X, DISPLAY_RES_Y, 32,
SDL_FULLSCREEN | SDL_HWSURFACE | SDL_DOUBLEBUF);
if ( screen == NULL ) {
fprintf(stderr, “Couldn’t set %ix%ix8 video mode: %s\n”,
DISPLAY_RES_X, DISPLAY_RES_Y, SDL_GetError());
exit(1);
}
colour[0].r = 255;
colour[0].g = 0;
colour[0].b = 0;
colour_format=screen->format;
for(;;){
while(SDL_PollEvent(&keyboard_check)){
switch(keyboard_check.type) {
case SDL_KEYDOWN:
exit(0);
}
}
colour[0].r = (int)(rand() % 255);
SDL_FillRect(screen, 0, SDL_MapRGB(colour_format, colour[0].r, 0,
0));
// Update the screen
SDL_Flip(screen);
}
printf(“SDL initialized.\n”);
printf(“Quiting SDL.\n”);
/* Shutdown all subsystems */
SDL_Quit();
printf(“Quiting…\n”);
exit(0);
}
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20021126/a34acde1/attachment.pgp