sdl distorted SDL_FillRect and images

Started by
3 comments, last by leagal4ever 11 years, 4 months ago
Hello i have problem with distorted rectangle, this problem also happen with images.

examplejy.png
Distorted rectangle looks like this.

Its happen only for moment every few seconds, it become obvious while moving ,any idea how to fix it?
Advertisement
Sounds like screen tearing. What does your rendering code look like?
Yeah its tearning.

// init
SDL_Init(SDL_INIT_EVERYTHING);
screen = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE | SDL_DOUBLEBUF);

// render
SDL_FillRect(screen, NULL, 0);
for(int i=0; i<box_vec.size(); i++)
{
SDL_FillRect(screen, &box_vec->rect, box_vec->color); // problem rect
}
SDL_Flip(screen);

// update
box_vec->rect.x += box_vec->xvel;
box_vec->rect.y += box_vec->yvel;
You're not calling SDL_Init and SDL_SetVideoMode every frame, are you? Those are a at-initialization-resource-loading things and should not be mixed with realtime code...
No, Init(); is in constructor it run only once, Render(); , Update(); and Fps(); run every frame

This topic is closed to new replies.

Advertisement