GL ON SDL Surfaces

I tried this the other day. It was a relativly simple matter of
just taking the XWindow of an SDL Surface and attaching a GL Context
to it through a couple of GLX calls and it worked fine. If anyone
is interested I can send the patch. Doing this more generally, especially
making it support fullscreen will be more tricky… and of course it
should also be done for other platforms (primarily in WGL for win32)
so it is portable - I can’t do this because I’m not able to compile
SDL for windows.

Still, all you really require of SDL is the ability to attach a GL-context;
after that its just straight (portable) GL.

Is someone working on something like this? If not I can continue with
it, allthough I’d prefer that someone with more knowledge of the internals
of SDL did it.

(Hello all BTW, I’m new on the list :)On Wed, Oct 27, 1999 at 04:05:44PM -0400, John Garrison wrote:

Yes, we considered that, but the problem was doing it in software on
computers without 3D accelerators.

Letting Mesa (or whatever) do it in software will probably kill you out
of boredom (or maybe from attrition after waiting for the next frame to
appear). Requiring a 3D accelerator for a 2D game is just plain crazy
(or so we feel).

So you end up needing at least a decent software implementation.

One way to do this is to use two different backends, for example with my
PowerDraw library which uses SDL I considered also writing an OpenGL
backend and letting the user decide which shared library to use (or
compile as the case may be) The only problem is I couldn’t figure out
how (if it is even possible) to use SDL surfaces with OpenGL and decided
that I should wait and add other features instead of rewriting all of
the surface code and image loaders etc.


! /-/\ “this too
! ( `.’ ) shall pass”
! \ o / @Jonas_Minnberg

I would be VERY interesting in seeing this code, I’ve wanted the ability
to use GL within SDL for a while now.

I tried this the other day. It was a relativly simple matter of
just taking the XWindow of an SDL Surface and attaching a GL Context
to it through a couple of GLX calls and it worked fine. If anyone
is interested I can send the patch. Doing this more generally, especially
making it support fullscreen will be more tricky… and of course it
should also be done for other platforms (primarily in WGL for win32)
so it is portable - I can’t do this because I’m not able to compile
SDL for windows.

This signature has been infected by the signature virus.
Please help me spread and copy me to your .signature.

(Andy Hefner)

I tried this the other day. It was a relativly simple matter of
just taking the XWindow of an SDL Surface and attaching a GL Context
to it through a couple of GLX calls and it worked fine. If anyone
is interested I can send the patch. Doing this more generally, especially
making it support fullscreen will be more tricky… and of course it
should also be done for other platforms (primarily in WGL for win32)
so it is portable - I can’t do this because I’m not able to compile
SDL for windows.

Doesn’t that method just provide window management functions to OpenGL
though, or will it allow you to access the GL screenbuffer as if it were
the SDL buffer? I saw some SDL-OpenGL example code in the demos
directory but I think all that does is provide a window for OpenGL to
draw on sorta like glx or whatever it is Windows uses (wgl did you say?)
If SDL can’t draw to OpenGL buffers than I would have to still rewrite
my whole PowerDraw lib.

(Hello all BTW, I’m new on the list :slight_smile:

Welcome! :slight_smile:

I tried this the other day. It was a relativly simple matter of
just taking the XWindow of an SDL Surface and attaching a GL Context
to it through a couple of GLX calls and it worked fine. If anyone
is interested I can send the patch. Doing this more generally, especially
making it support fullscreen will be more tricky… and of course it
should also be done for other platforms (primarily in WGL for win32)
so it is portable - I can’t do this because I’m not able to compile
SDL for windows.

Doesn’t that method just provide window management functions to OpenGL
though, or will it allow you to access the GL screenbuffer as if it were
the SDL buffer? I saw some SDL-OpenGL example code in the demos
directory but I think all that does is provide a window for OpenGL to
draw on sorta like glx or whatever it is Windows uses (wgl did you say?)
If SDL can’t draw to OpenGL buffers than I would have to still rewrite
my whole PowerDraw lib.

I’m not sure exactly how GL and X shares this buffer - at the least it
should be possible to remove the context will doing 2D rendering in
the SDL buffer and then attaching it again for the gl-calls. Personally
I dont really need this ability since all GL-calls will work, and
are much more powerful then plain 2D. I can see why you would like it
to work both ways though :slight_smile:

I’ve attached the patch, I hope I gave the right arguments to diff :slight_smile:
It should let you do
./configure --enable-glx and then give you the ability to do something
like this.

// Init & Create surface

SDL_GL_InitContext(SDL_Surface *s)

loop() {

// Do your GL rendering here

SDL_Flip(SDL_Surface *s) // Switch buffers

}

SDL_GL_DestroyContext(SDL_Surface *s)

All 2D rendering to the SDL-buffer is propably broken after this
(havent’t tried) but it seems to work fine for GL.On Thu, Oct 28, 1999 at 02:42:38AM -0400, John Garrison wrote:


! /-/\ “this too
! ( `.’ ) shall pass”
! \ o / @Jonas_Minnberg
-------------- next part --------------
A non-text attachment was scrubbed…
Name: gldiff.gz
Type: application/octet-stream
Size: 2068 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/19991028/3c3ace80/attachment.obj

Andy Hefner wrote:

I would be VERY interesting in seeing this code, I’ve wanted the ability
to use GL within SDL for a while now.

This is on my TODO list for SDL. We have to ship this year’s games
before I can get into it though. I plan on adding a Quake-style
OpenGL DLL loading mechanism including context, with some support
for logging/debug. This way of handling things was originally
conceived for Win32 (in particular VG/V2 boards that will never
have ICD’s).

                                                  b.-- 

“Problem solving is hunting. It is savage pleasure,
and we are born to it.” Thomas Harris, Silence of the Lambs