Archived

This topic is now archived and is closed to further replies.

DuncanBojangles

SDL and OpenGL, should it be so slow?

Recommended Posts

I''m using Linux and SDL to get an OpenGL rendering context. I just came from the rabbit-hole known as Windows and my programs ran okay. Now that I''m using SDL, though, it runs very slowly! Has this happened to anyone else? I used the code that SDL had in their documentation and I can''t find any glaring bottlenecks. Does anyone know why this might be happening? Oh, and it definitely isn''t the graphics card, ''cause I don''t have one "Donkey, if it were me, you''d be dead." I cna ytpe 300 wrods pre mniute.

Share this post


Link to post
Share on other sites
What is your code doing? how fast is it running?

And, um, if you don''t have a graphics card, how can you see the screen to type? Last I checked, computers didn''t usually have line printers anymore.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
Heh, I meant that I didn't have a good graphics card. The graphics capabilities I have are built into the motherboard of my computer. My computer is not top of the line, but it usually isn't this slow, even when they are my programs! All my program does is create a doublebuffered RGB OpenGL rendering context and spins a cube! Terribly slow, I believe at around 3 - 5 frames per second. I'm not sure, but you might be able to find the code I'm using on SDL's site, libSDL.org .

"Donkey, if it were me, you'd be dead."
I cna ytpe 300 wrods pre mniute.

[edited by - duncanbojangles on October 22, 2003 5:43:52 PM]

Share this post


Link to post
Share on other sites
Maybe the problem is that your linux has no hw accelerated OpenGL drivers for your graphics card. Does everything run fine in Windows? Also using SDL?
What kind of chipset is it?
edit: try running 'glxgears' in X, see if it works ok.


SwSh website!

[edited by - SwSh on October 22, 2003 5:51:35 PM]

Share this post


Link to post
Share on other sites
Everything ran fine in Windows, but I was using GLUT. Glxgears also runs fine. Is there another option to obtain a rendering context for OpenGL without SDL? The chipset is a generic SiS and I''m running Slackware 9.0.

"Donkey, if it were me, you''d be dead."
I cna ytpe 300 wrods pre mniute.

Share this post


Link to post
Share on other sites
Well, you could use Glut in linux too. Or make your hands dirty by using pure X calls, but that sounds like black magic to me.
edit: also, what do you get when you run 'glxinfo' ?
If you get an error saying that the GLX extension could not be found, that means you don't have hardware accelerated drivers for OpenGL in linux.
edit: uh, yeah, you probably have GLX, otherwise you couldn't run glxgears. I need some sleep


SwSh website!

[edited by - SwSh on October 22, 2003 6:37:15 PM]

[edited by - SwSh on October 22, 2003 6:40:20 PM]

Share this post


Link to post
Share on other sites
Well, after finally using my 2 week old GLUT that I couldn''t get to work, I realized I forgot to link to the X libraries. Stupid me! Oh, SDL and OpenGL don''t mix. I tried out OpenGL with GLUT, so much better. Now I have to port all my programs from Windows to Linux. Shouldn''t be too hard, except for GetAsyncKeyState( ) ;
Thanks for all your help, though!

"Donkey, if it were me, you''d be dead."
I cna ytpe 300 wrods pre mniute.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hmm, thats odd. SDL works great with OpenGL for me (under Linux and Windows). SDL just creates the OpenGL context for you and gets out of the way (except for its I/O and audio APIs you might want to use).

SDL is much more reasonable for games than GLUT I believe.

Take it easy.

Share this post


Link to post
Share on other sites
Hey Anonymous Poster, are you using basically the same code that the SDL documentation uses? I tried it and it takes forever for it to handle events such as keypresses. Just using GLUT is okay for me, because most of my programs aren''t that intensive. By the way, what kind of hardware acceleration do you have?

"Donkey, if it were me, you''d be dead."
I cna ytpe 300 wrods pre mniute.

Share this post


Link to post
Share on other sites
SDL and OpenGL in Linux work great for me. What does glxinfo report for you? If it shows MESA, that means you are using software rendering. This is what I get:

OpenGL vendor string: ATI Technologies Inc.
OpenGL renderer string: Radeon 9700 PRO Athlon (3DNow!)
OpenGL version string: 1.3 (X4.2.0-3.2.8)
OpenGL extensions:
And a ton of extensions are listed. Granted I have a fast 3D card, but if all you see is MESA you are using software rendering and are at a disadvantage. Just for kicks, I can run glxgears in software at around 380 FPS I believe. With hardware acceleration I get over 4000 FPS. Has been a while since I ran in software mode once ATI released their Linux drivers and nVidia release AGPGART drivers.

If you would like please send me your code and I will run it and see just how slow it is under accelerated drivers. Just an FYI, but I have a program that spits out a render for a .ply file and get plenty of speed from it.

Clutch


[edit] -- Added specs with OpenGL acceleration

[edited by - clutch on October 22, 2003 12:59:26 AM]

[edited by - clutch on October 23, 2003 1:01:42 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by DuncanBojangles
Oh, SDL and OpenGL don''t mix.


This is simply due to misconfiguration of your system, as there are literally thousands of examples of machines that have no issues with running them together.

Share this post


Link to post
Share on other sites
name of display: :0.0
display: :0 screen: 0
direct rendering: No
server glx vendor string: SGI
server glx version string: 1.2
server glx extensions:
GLX_EXT_visual_info, GLX_EXT_visual_rating, GLX_EXT_import_context
client glx vendor string: SGI
client glx version string: 1.2
client glx extensions:
GLX_EXT_visual_info, GLX_EXT_visual_rating, GLX_EXT_import_context
GLX extensions:
GLX_EXT_visual_info, GLX_EXT_visual_rating, GLX_EXT_import_context
OpenGL vendor string: Mesa project: www.mesa3d.org
OpenGL renderer string: Mesa GLX Indirect
OpenGL version string: 1.3 Mesa 4.0.4
OpenGL extensions:
GL_ARB_imaging, GL_ARB_multitexture, GL_ARB_texture_border_clamp,
GL_ARB_texture_cube_map, GL_ARB_texture_env_add,
GL_ARB_texture_env_combine, GL_ARB_texture_env_dot3,
GL_ARB_transpose_matrix, GL_EXT_abgr, GL_EXT_blend_color,
GL_EXT_blend_minmax, GL_EXT_blend_subtract, GL_EXT_texture_env_add,
GL_EXT_texture_env_combine, GL_EXT_texture_env_dot3,
GL_EXT_texture_lod_bias
glu version: 1.3
glu extensions:
GLU_EXT_nurbs_tessellator, GLU_EXT_object_space_tess

visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav
id dep cl sp sz l ci b ro r g b a bf th cl r g b a ns b eat
----------------------------------------------------------------------
0x22 24 tc 1 24 0 r y . 8 8 8 0 0 16 0 0 0 0 0 0 0 None
0x23 24 tc 1 24 0 r y . 8 8 8 0 0 16 8 16 16 16 0 0 0 None
0x24 24 tc 1 24 0 r y . 8 8 8 8 0 16 8 16 16 16 16 0 0 None
0x25 24 tc 1 24 0 r . . 8 8 8 8 0 16 8 16 16 16 16 0 0 None

Hmm, you were right. I am using Mesa. I really need to get a graphics card so I can stop using the built in SiS one on my crappy Compaq. Sadly, my machine only runs at 475 MhZ. Oh well, using GLUT is giving me fine and predictable results. The only thing I''ll miss from SDL will be the 2d blitting in an OpenGL screen Thanks for pointing that out to me, Clutch.

"Donkey, if it were me, you''d be dead."
I cna ytpe 300 wrods pre mniute.

Share this post


Link to post
Share on other sites
Goto console and type glxgears you should find something that says OpenGL renderer string if it says there Mesa then you are using a software render. If it says DRI or Mesa DRI then it uses opensource hardware accelteration(maybe not be as fast as the offical hardware makers drivers) Most graphics cards(even on board) have linux drivers. If you have a onboard nvidia graphics card your good to go because nvidia makes linux drivers for all there cards just goto nvidia.com and download them. ATI makes linux drivers for all there cards 8000 and up last I checked but I dont think ATI has onboard cards. Intel(what you probly have) makes linux drivers for most of theres just goto intel.com and search for them.

Hope it helps!

nuke

Share this post


Link to post
Share on other sites
quote:
Original post by Luke Philpot
You should be able to pick up an old TNT2 or GeForce which should do the trick


I just bought a nvidia fx 5900 ultra, probly out of your price range but while I was looking I saw that you could get the geforce 2 for $30 and geforce fx 5200 128meg for $100

Share this post


Link to post
Share on other sites
On newegg.com I found a refurbished ATI Radeon 9000 for $60. Affordable and fast, too. Thanks for the help, but one more question. Would it be too weird to use GLUT to create the window and let SDL handle timing, image loading, input, and everything else? Or is there just some reason SDL code runs slow on my system(other than the whole software rendering deal)? I wonder who got the GeForce2 NeHe was giving away? Thanks for helping!

"Donkey, if it were me, you''d be dead."
I cna ytpe 300 wrods pre mniute.

Share this post


Link to post
Share on other sites
SDL is truly amazing when it comes to everything but 3d graphics for me. Oh well, I''ll just have this weird hybrid of SDL and GLUT, because I really hate the way GLUT handles events. Thanks for the help, though.

"Donkey, if it were me, you''d be dead."
I cna ytpe 300 wrods pre mniute.

Share this post


Link to post
Share on other sites
An alternative to GLUT/SDL, try ClanLib. It is a swiss knife type of lib but it is what I am using right now for the simple fact that it also includes GUI in it. I hate reinventing the wheel!

Clutch

Share this post


Link to post
Share on other sites
I don''t think I''m ready to switch yet, ''cause I''ve used GLUT for a while now. I tried using SDL''s input and GLUT together, but I found out that the only way to have them both is if you open an SDL window. I found that this is because SDL''s keyboard event handling is included with their Video stuff. So, you have to initialize video and then setvideomode which brings up a window. Is there any way I can throw some NULLs in there and set up the keyboard but not open an SDL window? ''Cause SDL runs OpenGL very slowly on my machine.

"Donkey, if it were me, you''d be dead."
I cna ytpe 300 wrods pre mniute.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
''Cause SDL runs OpenGL very slowly on my machine.

That''s funny because my sdl+opengl programs have always run well over 300 FPS, not slow at all. Are you enabling Vsync? Did you set up the window properly? It sounds like you just passed in SDL_OPENGL to setvideomode and when that didn''t work, you started looking elsewhere. Things are not always simple in programming or work as you expect the first time.

Did you look at the glSDL library? I hear that speeds up SDL''s opengl more than plain SDL does.

Share this post


Link to post
Share on other sites
I set up my window exactly like the SDL documentation does, so I''m not sure why it would run so slowly. One reason, extremely slow graphics card. But that can''t be the only factor, because my programs are slow to respond to event handling. Using GLUT and the dummy SDL window, my programs handled input flawlessly. It''s not just a frames per second problem, it''s total program. I just want to use the combination that works for me, and that happens to be GLUT and SDL event handling.

"Donkey, if it were me, you''d be dead."
I cna ytpe 300 wrods pre mniute.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Sure but just because you can''t figure out the right way to make SDL and opengl work (which isn''t even the real problem it seems since you keep talking about your input) doesn''t mean you should tell people it doesn''t work at all, becuase that isn''t true.

" One reason, extremely slow graphics card."
That''s a big factor. If you want to use new 3D graphics you''ll need a decent 3D card. You can get one for $50 nowadays so there is really no excuse anymore for people not to have some kind of card (especially programmers)

" my programs are slow to respond to event handling."
There different ways to handle input when using SDL you know.
Were you using input code from the docs? Because that''s a bad way to do it and was choppy when I tried it. My compiler won''t even accept that code anymore.

Try reading keypresses each frame with
Uint8 *keys = SDL_GetKeyPresses() and then use if tests to test if a certain key was pressed. That''s what I did and it works much much smoother.

"I just want to use the combination that works for me"
Sure but you are making it harder and more inefficiant than you need to by using 2 different API''s that do essentially the exact same things (SDL being much better of course)
Are you saying you need multi-windows? One for opengl one for SDL? Because you really are ok using just an SDL window. Multi windows support may come in SDL 2.0

Share this post


Link to post
Share on other sites
I understood that the documentation handled events slowly, so I did end up using SDL_GetKeyPresses() and it works just like my old Windows functions did. I don''t need two windows, I need GLUT for OpenGL because when I use SDL, the exact same program runs slowly. But to get SDL''s event handling(which isn''t slow when I don''t use SDL to do OpenGL commands), I need to initialize and open an SDL window because Keyboard handling is jumbled with video in SDL. I know what I''m doing, I''ve been programming for a couple years now, but the switch to Linux has thrown some wrenches into the gears. So, let''s review:
1. SDL runs OpenGL very slowly.
2. When SDL runs OpenGL, events are processed very slowly.
3. GLUT runs my programs fine.
4. When GLUT does OpenGL, SDL handles events extremely well, and on time.
5. But to get GLUT with SDL''s keyboard handling, I''m forced to open an SDL window.
6. I don''t need two windows.

I''m really annoyed with this, and I just want to be crystal clear on what is happening on my computer. If anyone can help me, that would be great. One last thing, is there High Resolution timer support in Linux? And does anyone know of a command similar to GetAsyncKeyState() on linux? Sorry to sound like a jackass, and thanks for all your help.

"Donkey, if it were me, you''d be dead."
I cna ytpe 300 wrods pre mniute.

Share this post


Link to post
Share on other sites