#include <cstdlib>
#include <iostream>
#include <SDL/sdl.h>
SDL_Surface *Screen;
SDL_Event event;
void SetPixel(SDL_Surface *pSurface,long x,long y,char r,char g,char b)
{
Uint32 Color=SDL_MapRGB(pSurface->format,(Uint8)r,(Uint8)g,(Uint8)b);
char *Pos=(char *)pSurface->pixels;
Pos+=(pSurface->pitch*y);
Pos+=(pSurface->format->BytesPerPixel*x);
memcpy(Pos,&Color,pSurface->format->BytesPerPixel);
}
int main(int argc, char *argv[])
{
if (SDL_Init(SDL_INIT_VIDEO)==-1)
{
return 0;
}
Screen=SDL_SetVideoMode(1024,768,32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN );
if(NULL==Screen)
{
return 0;
}
for (int i=0;i<Screen->w;i++)
{
for (int j=0;j<Screen->h;j++)
{
SetPixel(Screen,i,j,i+j*2,i*2+j,i*2+j*2);
}
}
SDL_PollEvent(&event);
while (event.type!=SDL_QUIT)
{
if (event.type==SDL_KEYDOWN)
{
exit(0);
}
SDL_Flip(Screen);
SDL_PollEvent(&event);
}
return 0;
}
SDL screen refresh rate is giving me an headache
I try to run SDL on a full screen, in 1024*768*32 but it seems that the refresh rate of the screen is something like 50hz and this is really not nice... here is the code I use for the basic main loop:
How appropriate, you fight like a cow!
You are setting individual pixels. That's slow :). I'm not surprised you're getting a headache watching that.
Not to mention you're flipping from a non-initialized backbuffer to the frontbuffer with data. This will probably cause a lot of flickering. Don't use double buffering, or blit to the backbuffer too (placing the drawing code inside the loop).
If this is for a simple test, it's not a problem, but your event system is a bit awkward.
If this is for a simple test, it's not a problem, but your event system is a bit awkward.
Quote:
Original post by Maega
You are setting individual pixels. That's slow :). I'm not surprised you're getting a headache watching that.
I'm doing this only once.
Quote:
Original post by Gyrbo
Not to mention you're flipping from a non-initialized backbuffer to the frontbuffer with data. This will probably cause a lot of flickering. Don't use double buffering, or blit to the backbuffer too (placing the drawing code inside the loop).
If this is for a simple test, it's not a problem, but your event system is a bit awkward.
the problem is not flickering screen, the problem is the refrashe rate is too slow, if you are using windows try to change in the Display Propreties->settings->advanced the refresh rate of the screen, this is the effect I get.
ohh well but I guess this is how SDL does it, never mind I'll use another library I guess...
[Edited by - Ilankt on January 12, 2005 7:36:23 AM]
How appropriate, you fight like a cow!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement