PDA

View Full Version : Using OpenGL & SDL Together



WILL
12-10-2006, 10:09 AM
What exactly is involved in using OpenGL with SDL to take care of the rotations, scaling and blending effects one would nowadays task to their GPU?

How does this work?

jdarling
12-10-2006, 01:02 PM
Not much, initialize SDL, setup SDL for OpenGL, push the matrix, rotate, scale, transform as normal, pop matrix, flip and proceed as normal.

The problem I found was that you can't combine SDL and OpenGL surfaces successfully on all systems. You can find hacks that work on this, that, or some other thing, but not everything. So up front you have to decide on SDL or OpenGL IMHO.

For this reason I went with pure SDL inside my JumpStart engine, though Project Phoenix uses OpenGL through SDL. You can take a look at that project if you want to see how its done.

savage
12-10-2006, 01:56 PM
If you have a look at the JEDI-SDL OpenGL demos, I ported one of the nehe 2D games that uses OpenGL. Have a look at the code and play around with it. I think it's Nehe's tutorial 21, the game is called Grid Crazy. C code and explanation can be see here - http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=21.

WILL
13-10-2006, 01:58 AM
Thanks Dom, I'll do that. :)

Jeremy: Hmm... well that does give me quite a bit to think on. I think I will have to do more research before I make a choice like that though. Going pure OpenGL sounds like I'd have to redo quite a bit of my graphics routines in my game engine. (and my already established codebase for all my projects)

WILL
13-10-2006, 04:35 AM
Ok I've looked a bit at your ported NeHe tutorial.

Automatically it doesn't compile in Lazarus. :P But I think that is a no duff. It looks like if I do want to use OpenGL and SDL together I'll have to resolve the SDL & FPC issues first.

So seeing as how I do use Lazarus and there is an issue here, I might as well see if I cannot help to make JEDI-SDL's gl.pas unit compatable on Lazarus + Win32. (I'm using the latest version of Laz 0.9.18 & it uses FPC 2.0.4 and I'm running WinXP Home. Yay me! :))

Running in Delphi Compatability mode, first error I get is...


C:\Documents and Settings\WILL\My Documents\Pascal Projects\JEDI-SDLv1.0\OpenGL\Pas\gl.pas(80,2) Fatal: Can't open include file "jedi-sdl.inc"

So I comment that line out and try again. Next one is on line 1584.


C:\Documents and Settings\WILL\My Documents\Pascal Projects\JEDI-SDLv1.0\OpenGL\Pas\gl.pas(1584,3) Error: Can't assign values to an address

Then I get nothing but 49 more just like 'em. :P (debugger stops after this amount)

I take it that this is not suported on FPC? What would be the FPC/Lazarus equivalent?

cairnswm
13-10-2006, 05:33 AM
Hi WILL

S2DL (http:\\www.cairnsgames.co.za\files\s2dlv1-10.zip) is already a fully OpenGL and SDL (JEDI-SDL) implementation. It uses OpenGL for all the resizing, rotating and alpha drawing.

Cheers

savage
13-10-2006, 07:11 AM
Running in Delphi Compatability mode, first error I get is...


C:\Documents and Settings\WILL\My Documents\Pascal Projects\JEDI-SDLv1.0\OpenGL\Pas\gl.pas(80,2) Fatal: Can't open include file "jedi-sdl.inc"

I take it that this is not suported on FPC? What would be the FPC/Lazarus equivalent?

It is all supported under FPC, if you set up the paths correctly. Ensure that the path for the projects include libraries point to where jedi-sdl.inc is located. If you do that, all your other paths are correct it WILL compile using FPC and I assume Laz. I have only ever used FPC to compile these demos and never used Laz.

WILL
13-10-2006, 10:47 AM
Ok I figured out what I was doing wrong. It works in Lazarus just fine.

2 things to note however...

1st: Make sure you put the jedi-sdl.pas in the 'Include' path NOT the 'Other Unit Files' path in the Compiler Options settings of your project.

2nd: Don't forget to turn on Delphi Compatability :doh: Gets me every time.

:lol:

I'll see what I can make of this. If it allows me to do ADD/SUB/MUL + Fade/Alpha + Rotate + Scale at the same time then I'm set.


Thanks William, I'll take a look at S2DL too if I can. Could provide me some more insight.

jdarling
13-10-2006, 01:02 PM
Will, you can use the JEDI-SDL stuff w/o Delphi Compat mode, but you have to completely re-write the application. The SDL headers all work fine with no compat mode on :). You do have to make a few result to function name switches, but hey it works :).

I've done this for a few of the demos myself, nothing to be proud of so I haven't posted them up. I might have to take the time to throw together a simple SDL sample, but I'm starting to like Lua integration too much, so it would have Lua support in it as well :).

grudzio
13-10-2006, 01:09 PM
There is {$MODE DELPHI} switch in jedi_sdl.inc, so you don't have to turn on
delphi comatibility, unless some of your headers does not include jedi_sdl.inc.

WILL
13-10-2006, 09:58 PM
Well once I figured out how to slow down this GridCrazy game enough to see whats going on I was able to check it out a little better. Really FAST, but I guess thats a good thing. :D It shows me how I setup OpenGL within SDL so I know a bit more that portion now.

But since it doesn't use OpenGL textures, I'll still have to figure that one out.

grudzio
14-10-2006, 11:31 AM
But since it doesn't use OpenGL textures, I'll still have to figure that one out.

Check the glFont and glMovie demos in SDL_TTF and SMPEG. They both use GL textures and show how to create them from SDL surfaces.