Tom's Guide > Forum > Linux/Free BSD > Linux/Free BSD General Discussion > Threading and video with SDL

Threading and video with SDL

Forum Linux/Free BSD : Linux/Free BSD General Discussion - Threading and video with SDL

TomsGuide.com: Over 800,000 questions and answers to address all your high-tech questions. Sign up now! Its free!
Word :    Username :           
 

I've recently installed SuSE Pro 9.1 and am using KDevelop - which, BTW, feels great - to make a per-pixel renderer that can effectively propagate any two-dimensional wave (well... I'm a physicist, and it's just for curiosity).

I'm using SDL (Simple DirectMedia Layer from <A HREF="http://www.libsdl.org" target="_new">libsdl.org</A> to do the graphics bit; I've coded the renderer myself and the wave propagation also.

I've faced the following problems:

<b>1- No SDL Reference Guide </b> or any sort of extensive and comprehensive help files seem to be available anywhere. It's terrible. The libsdl site only mentions initializing the video part and drawing pixels (which is kinda all I need), but the pixels are "soft" - they get drawn only once, and if something like another window gets in front of those pixels, they don't get redrawn anymore ever.

<b>2 - SDL offers a defficient threading implementation</b>; I've tried the SDL_CreateThread functions. They work, I do actually manage to get two threads up and running and do math simultaneously (I've got a dual P3 933Mhz), but I get a 0% (!) performance increase in the multithreaded version, and the SDL_WaitThread function doesn't even work properly! What am I missing? How can I possibly get the same performance with a two-threaded per-pixel render (it's the ideal parallel-design scenario!) that I get with a single-thread renderer???

Anyone know a better way to do threading? Any libraries to do so? Anything more low-level on C++ or a guide on how to do this in C++ or anything?

Also, does anyone know SDL enough to help or to point to a good and complete reference guide??

Thanks in advance!

Sponsored Links
Register or log in to remove.

I know how to program a calculator... but that's about it.

s signature has been formatted to fit your scr

Reply to silverpig

You mean... a calculator in SDL?.......

(or was that just a joke? I can never tell...)

Reply to Mephistopheles

Try these out...
<A HREF="http://sdldoc.csn.ul.ie/index.php" target="_new">http://sdldoc.csn.ul.ie/index.php</A>
and the wiki if you missed it...
<A HREF="http://www.libsdl.org/cgi/docwiki.cgi/SDL_20API" target="_new">http://www.libsdl.org/cgi/docwiki.cgi/SDL_20API</A>

What function are you using to draw the pixels? Better yet, can you post a code snippet? remove any propietary info... I'll give it a shot and see what I come up with.

The threads library to look into for Linux in general is Pthreads.


<i>Nemo me impune lacesset</i><P ID="edit"><FONT SIZE=-1><EM>Edited by raretech on 11/01/04 02:55 PM.</EM></FONT></P>

Reply to raretech

I mean in like java, or perl, or c++... :)

Basically I was trying to say I'd help if I could but I know jack about that stuff. I guess I'm the resident linux fanboy trying to get as many on it and sticking with it as possible.

s signature has been formatted to fit your scr

Reply to silverpig

Thanks a lot. I checked those two out, but apparently, my implementation of multithreading works - i.e., it gives the correct results and runs two threads simultaneously - but it is apparently unable to give any performance boosts.

What I've been doing is this... I have a central, critical function that's called Pixel(x,y). It returns an integer value from 0 to 255 (it's B&W) that is the color of that particular pixel. Then, what I do is create an indexed array that goes like screen(1,1) all the way to screen(640,480) or some other resolution. Then I define two functions to be executed simultaneously:

<b>void Function 1</b> (for thread A)
<font color=green><b>for</b></font color=green>(c1==1,c1<641,c1==c1+2)
<font color=green><b>for</b></font color=green>(c2==1,c2<481,c2++)
screen(c1,c2)=Pixel(c1,c2);

<b>void Function 2</b> (for thread A)
<font color=green><b>for</b></font color=green>(c1==2,c1<642,c1==c1+2)
<font color=green><b>for</b></font color=green>(c2==1,c2<481,c2++)
screen(c1,c2)=Pixel(c1,c2);

(this is just to give you an idea, I wrote this quickly, the syntax isn't correct, but that's essentially it. Haven't done a lot since my last post, and that's already a while back, so I... well, I don't quite remember the exact syntax... I'll look it up. But the basics were just this.)

Now you'd think that starting these two intedepently would immediately return excellent performance gain with SDL threading, but it does NOT. I don't know what I'm missing. Also, the final picture is perfect, but it takes like 20s to do it single-threadedly and 21-22s to do it with multithreading.

I'm definitely missing something out here!!!

I'll try pthreads instead.

Reply to Mephistopheles

Oh man, this part of the forums gets like 1/100 of the posts the CPU section gets, doesn't it??.... :frown: .... sad.....

Reply to Mephistopheles

Apparently, I must be getting conflicts regarding variable access. So the processes don't actually run at 100% speed because they can only access a given variable one-at-a-time...

I wonder If I can make the two threads independent?...

It's not as easy as I thought...

Reply to Mephistopheles

Well... I'm now facing a few problems regarding the "update screen" functions. How come I need to tell the device to update the screen every time the user feels like switching windows?

I'm afraid some things don't quite appear on reference guides. Isn't there a manual for SDL around? I needed one...

Reply to Mephistopheles
Tom's Guide > Forum > Linux/Free BSD > Linux/Free BSD General Discussion > Threading and video with SDL
Go to:

There are 8 identified and unidentified users. To see the list of identified users, Click here.

Please mind

You are about to answer a thread that has been inactive for more than 6 months.
If you still wish to proceed, please ensure that your posting is original and does not duplicate or overlap any prior responses to this thread.

Add a reply Cancel
Google ads