   Slow SDL app
  Here is a small SDL program that does *nothing*:   #include "SDL.h"#include <fstream>using namespace std;int main(int argc, char *argv[]) {bool quit = false;SDL_Event event;SDL_Init(SDL_INIT_VIDEO);SDL_Surface *screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);Uint32 time, temp;float fps = 200.0;time = SDL_GetTicks();while(!quit) {while(SDL_PollEvent(&event)) {if(event.type == SDL_KEYDOWN) quit = true;}temp = time;time = SDL_GetTicks();fps = (0.9 * fps) + ((1000 / (time - temp)) * 0.1);SDL_Flip(screen);}ofstream timefile("time.txt");timefile << "FPS: " << fps;return 0;}Now why on earth does it only produce 4-500 fps? And why does it crash when I enable fullscreen mode?[edited by - robinei on August 1, 2003 9:43:02 AM]
  For some reason SDL fullscreen mode doesnt work very well (at least in windows which i''ll assume your using).Some people have had luck by using SDL_SWSURFACE instead of SDL_HWSURFACE. If that doesnt work try disabling double buffering. ;  How exactly does your fps calculation work?I mean you start it as 200 and then you you use the previous value in your calculation?isn''t each frame completely different and why start at 200?;  What''s the accuracy of SDL_GetTicks?The maximum FPS you can measure using such a measure is directly determined by this accuracy. If this accuracy is 2 milliseconds, you won''t be able to measure anything below that. And 2 milliseconds accuracy means instant FPS of 500. So you''re not measuring above 500 FPS (correctly, that is) using this method.Another method is counting how many frames are made each second (or other lapse of time). const int Delta = 100; // 100 should be minimumwhile( running ) {//do a frameFrameCount++;if( time - SDL_GetTicks() > Delta ) {    FPS = FrameCount / ( time - SDL_GetTicks( ) );    time = SDL_GetTicks( );    FrameCount = 0;}ToohrVyk;  There were som errors in your code, I think. But this works: if((SDL_GetTicks() - time) > delta) {fps = frame_count * 1000 / (SDL_GetTicks() - time);time = SDL_GetTicks();frame_count = 0;}Thanks for the idea.Anyone got som experience on the fullscreen issue? I do lock the surface so that shouldn''t be the problem. ;quote:Original post by ToohrVyk  What''s the accuracy of SDL_GetTicks?There was some discussion about this on one of the Enginuity article threads (don''t remember which one off hand, though).  On Windows machines, if they''re available, SDL_GetTicks uses the high performance counters; otherwise, it uses the generic GetTicks.  Not sure about Macs.  And Linux apparently uses GetTimeOfDay; though it has support for rtdsc, it''s commented out.More info than you wanted?  Probably.  -Odd the Hermit ;  i have a Fullscreen SDL app and it works fine, under windows. when you use SDL_Flip(), it waits for the monitor vsync refresh rate, meaning that you shouldnt get any more fps than what your monitor can handle. you''re calculations are incorrect, because i dont know any monitor that has a refresh rate of 500mhz. what you should do, is count the TRUE fps. get the time by running SDL_GetTicks(). every loop increment a frame counter. and test to see if a second went by:realframes++;if(SDL_GetTicks() - StartTime >= 1000){   // a second has passed  cout << realframes << endl;  realframes = 0;  StartTime = SDL_GetTicks();}if you use something simiular to that, you will notice that the number it puts out will be the exact number of your refresh rate.... hmmm! ;  This could be why:SDL_Surface *screen=SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);In windowed mode, it's best to not specify bitdepth, and let SDL pick the fastest one, then convert your images to that format on load (using SDL_DisplayFormat)Try it like this:SDL_Surface *screen=SDL_SetVideoMode(640, 480, 0, SDL_DOUBLEBUF|SDL_ANYFORMAT);EDIT: Oh yeah, it crashes in fullscreen because you're not checking if SDL_SetVideoMode fails. I supposed it is for some reason (maybe your video driver doesn't like doing 640x480x16, double buffered), and since you don't check if it does, the SDL_Flip is crashing your app.   [edited by - TravisWells on August 1, 2003 12:46:05 AM]