SDL novice questions

Hello,

I just started to use SDL, and I am using singleton pattern in which I have
static variable (ofstream). However my app hangs on place which has nothing
to do with error I get. It redirects me to xmtx.c, and there is some problem
with threads/concurency. I tried changing PollEvent with PeepEvent, but I
get same results. At the end I had to change code so I dont use static
ofstream variable, which works, but is not what I wanted in beginning. Is
there way to use singlethreaded SDL, I could live without events, timers,
etc. Is there any other solution to singleton problem, or I have to write
thread safe singletons? Can I expect more problems because of
multithreading?

Another question is that I am blitting 640x480 image and I get 58 fps on
geforce 6600. It seems thats because my image surface is in system memory. How
can I load image into video memory? I open hw display and double buffering in
fullscreen and that works, I checked flags, but I cant figure out how to load
image into vidoe memory, is that possible with SDL?

Thank you in advance,

A.Cicak

Is
there way to use singlethreaded SDL, I could live without events, timers,
etc. Is there any other solution to singleton problem, or I have to write
thread safe singletons?

AFAIK, you have to use multithreaded DLL in VisualC++ (I think you’re using it because its the only C++ compiler I know, which allows you to change single / multi threaded library versions… but may be wrong, haven’t used many of them). Also, there’s nothing such as “singlethreaded SDL” - you don’t need to use events, timers etc. if you don’t want to, but you don’t know / can’t change what SDL is using at certain platforms. And on some of them, some features may be implemented using threads (ie. events queue).

Can I expect more problems because of multithreading?

If you aren’t using multithreading explicitely, then you shouldn’t have any problems. If you are using multithreading explicitely, then your on your own, you have to design your code in such a way so that it’ll be thread safe. And in that case - yes, you may run into some not-trivial problems.

Another question is that I am blitting 640x480 image and I get 58 fps on
geforce 6600. It seems thats because my image surface is in system memory. How
can I load image into video memory? I open hw display and double buffering in
fullscreen and that works, I checked flags, but I cant figure out how to load
image into vidoe memory, is that possible with SDL?

You can’t always have all surfaces in video memory, there’s always probability that your platform / video card doesn’t support storing surfaces in it.

However, if you’d like to have surface stored in video memory, try passing SDL_HWSURFACE to function which creates your surfaces. Then, you can check whether it’s stored in video-ram using this code:

if (0 == (surface->flags & SDL_HWSURFACE))
fprintf(stderr, “This surface isn’t stored in video memory”);

Also, I’d suggest to use SDL_GetVideInfo() to obtain current video mode specs, and check for hw_available.

Btw, in OpenGL all textures are stored in video memory, so if performance is very important to you, and you plan many blits, IMHO you should try OGL - it is very easy to setup and use with SDL.

Koshmaar