[SDL][noob]Schlieren
-
Ich habe sin problem mit sdl: es gibt immer Schlieren
screen: *klick*CODE:
#include <cstdio> #include <cstdlib> #include <SDL/SDL.h> #include <stack> #include <iostream> #include <string> using namespace std; int main (void) { SDL_Surface *screen, *tmp, *pic; SDL_Event e; SDL_Rect rect; Uint8 *alle_tasten; if (SDL_Init (SDL_INIT_VIDEO) == -1) { cerr << "Kann SDL nicht initialisieren: "<< SDL_GetError()<< endl; exit (1); } atexit (SDL_Quit); screen = SDL_SetVideoMode (800, 600, 32, SDL_HWSURFACE); if (screen == NULL) { cerr << "Video Modus kann nicht eingerichtet werden: " << SDL_GetError() <<"\n"; exit (1); } /* *BILD */ if ((tmp = SDL_LoadBMP ("gleiter.bmp")) == NULL) { cerr << "Bild konnte nicht geladen werden: " << SDL_GetError()<<endl; exit (EXIT_FAILURE); } SDL_SetColorKey(tmp, SDL_SRCCOLORKEY, SDL_MapRGB (tmp->format, 255, 255, 255)); pic = SDL_DisplayFormat (tmp); SDL_FreeSurface (tmp); rect.x = 10; rect.y = 510; rect.w = 64; rect.h = 64; SDL_BlitSurface(pic, NULL, screen, &rect); SDL_UpdateRect (screen, rect.x, rect.y, rect.w, rect.h); SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, 0); bool running = true; while (running) { SDL_PollEvent (&e); alle_tasten = SDL_GetKeyState (NULL); if (alle_tasten [SDLK_ESCAPE]) running = false; if (alle_tasten [SDLK_LEFT] && rect.x > 0) rect.x--; if (alle_tasten [SDLK_RIGHT] && rect.x < 736) rect.x++; SDL_BlitSurface(pic, NULL, screen, &rect); SDL_UpdateRect (screen, rect.x, rect.y, rect.w, rect.h); //SDL_UpdateRect (screen, 0, 0, 640, 480); SDL_Delay(2); } return 0; }
-
Ich seh keine Schlieren, ich glaub dein Bildschirm ist dreckig *g*
(vielleicht jeden Schleifendurchlauf das Fenster füllen mit einer Farbe?)
SDL_FillRect(screen, 0, 0x000000); // ganzen Bildschirm mit Schwarz füllen
-
und doublebuffering verwenden:
SDL_Surface *screen = SDL_SetVideoMode(800,600,32,SDL_HWSURFACE | SDL_DOUBLEBUF); while(running) { //... //... //... SDL_Flip(screen); }
-
Danke es geht.
*IRONIE* noch kurz ein Spiel schreiben und fertig.