[SDL] OpenGL-surface + "2D-surface"

David Olofson david.olofson at reologica.se
Wed Sep 18 05:29:01 PDT 2002


On Wednesday 18 September 2002 13:16, Andreas Schou Vaerge wrote:
> I am programming a Risk-game (standard-tile 2D-game) for training
> bots, however I want to make a mini-map in the lower left corner made
> by a rendered opengl-sphere, with the map as a texture.

IMHO, it's very hard to motivate the use of OpenGL for something like 
that in an application that doesn't require OpenGL for anything else...

Besides, if you end up with software OpenGL, it's going to be *very* 
slow.


> All this I have
> already coded, however my problem is finding a way to add the
> opengl-sphere to the background-surface, which is used by a lot of
> pictures blitted onto by a blitting function and then added using
> SDL_flip. First adding the opengl-rendering the application crashed
> when using the SDL_flip. Then I found that using the bit SDL_OPENGLBLIT
> in the SDL_surface made the problem disappear.

No!!! Don't use that. Use OpenGL directly for all rendering, or 
*possibly* use glSDL for the 2D stuff.


> But at no time could I
> see the 2D-graphics any longer... To make it short (too late, but
> still) - Can I render an opengl-sphere with a texture on a 2D-blitted
> surface? ...

Well, yes, but unless you feel like doing a deep SDL hack that relies on 
the driver and accelerator supporting rendering into whatever memory area 
you specify, you'll have to use Mesa or some other software OpenGL 
implementation.


> Can i capture the opengl-output somewhere in the
> "background" and blit it onto the surface as 2D?

AFAIK, it should be possible to render into textures on most reasonably 
modern 3D cards, but I'm not sure about the availability of OpenGL 
support for that feature. Anyway, you'll probably still need to use 
OpenGL for rendering the whole screen, which basically eliminates SDL 
surfaces from the picture; you'll have OpenGL rendering that texture as 
another quad to the screne, along with the rest of the graphics.


IMHO, you should seriously consider a software lens/sphere effect filter. 
It's very simple in theory (just a table of read/write offsets, 
basically), and these days you can probably implement it with 
interpolation (or oversampling, to avoid multiplications) and a simple 
lightmap without it getting too slow. I'm quite sure a sphere with 
software OpenGL will be much slower - and still, the OpenGL sphere will 
be constructed out of polygons, while a sphere filter can be perfectly 
pixel accurate.


//David Olofson --- Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
|      Multimedia Application Integration Architecture      |
| A Free/Open Source Plugin API for Professional Multimedia |
`----------------------------> http://www.linuxdj.com/maia -'
.- David Olofson -------------------------------------------.
| Audio Hacker - Open Source Advocate - Singer - Songwriter |
`-------------------------------------> http://olofson.net -'




More information about the SDL mailing list