Problem with blitting [SDL]

Started by
-1 comments, last by prh99 14 years, 9 months ago
Hi, there! I have the following problem: In my SDL program I must blit one bmp image frequently on the screen. But there is a problem! Sometimes not displayed on the screen several blit. Here is how look like: BAD - http://img199.imageshack.us/img199/8510/badm.jpg What I want - http://img32.imageshack.us/img32/7909/goode.jpg Do you know where is the problem? Here is the source code: #include <SDL/SDL.h> #include <stdio.h> const int SCREEN_WIDTH = 510; const int SCREEN_HEIGHT = 510; SDL_Surface *DisplaySurface = NULL; SDL_Surface *RedBallSurface = NULL; SDL_Rect DestinationRect; SDL_Rect RedBallRectBMP; SDL_Event g_Event; void DrawRedBalls(int offset); int main(int argc, char* argv[]) { if(SDL_Init(SDL_INIT_VIDEO) == -1) { fprintf(stderr, "Gre6ka pri inicializirane na VIDEO-to:\n\t%s\n\n", SDL_GetError()); SDL_Delay(1000); exit(1); } atexit(SDL_Quit); DisplaySurface = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 0, SDL_ANYFORMAT); if(DisplaySurface == NULL) { fprintf(stderr, "Nemoje da se suzdade DisplaySurface:\n\t%s\n\n", SDL_GetError()); SDL_Delay(1000); exit(1); } RedBallSurface = SDL_LoadBMP("balls/red_ball.bmp"); Uint32 ColorKey = SDL_MapRGB(DisplaySurface->format, 0, 0, 0); if(SDL_SetColorKey(RedBallSurface, SDL_SRCCOLORKEY, ColorKey) == -1) { fprintf(stderr, "Nemoje da se inicializira color key na RedBallSurface:\n\t%s\n\n", SDL_GetError()); SDL_Delay(1000); exit(1); } RedBallRectBMP.w = DestinationRect.w =RedBallSurface->w; RedBallRectBMP.h = DestinationRect.h = RedBallSurface->h; RedBallRectBMP.x = RedBallRectBMP.y = 0; int g = 0; for(;;) { if(SDL_PollEvent(&g_Event) == 0 && g!=1) { DrawRedBalls(0); g=1; } else { if(g_Event.type == SDL_QUIT) break; } } return 0; } void DrawRedBalls(int offset) { int x, y; int SizeBMP = RedBallSurface->w; int winsize = SCREEN_WIDTH - offset; //for(y = offset; y < SCREEN_HEIGHT; y += SizeBMP) y = offset; while(y < SCREEN_HEIGHT) { for(x = offset; x < winsize; x += SizeBMP) { if(SDL_PollEvent(&g_Event) == 0) { DestinationRect.x = x; DestinationRect.y = y; SDL_BlitSurface(RedBallSurface, &RedBallRectBMP, DisplaySurface, &DestinationRect); SDL_UpdateRect(DisplaySurface, 0, 0, 0, 0); } else { if(g_Event.type == SDL_QUIT) exit(0); } fprintf(stderr, "%d, %d\n", x, y); //SDL_Delay(50); } y += SizeBMP; } }

This topic is closed to new replies.

Advertisement