Sdl 2D surfaces & opengl surfaces

Hello everybody!

I’d like to start making a game using sdl and opengl. However, once I started, I
stumbled on what appeard to be a limitation of the sdl library, that a sdl 2D
surface cannot be bliped on a opengl surface.

I want to build a GUI system and the most natural way would be to create the GUI
components as 2D surfaces and blip them on an opengl surface. It seems that’s
not possible.

I know this subject have been discussed over and over. I’ve seen some
work-arrounds suggested, like glDrawPixels and creating a texture from the 2D
surface and so on.

I’m not interested in those work-arrounds. I want to find a solution to this
problem. I want this fixed once and for all. I’m pretty sure it can be done.

So, what do you think? What could be done to find a permanent, consistent
solution to this problem?

cheers,
Daniel.

Hello everybody!

I’d like to start making a game using sdl and opengl. However, once I started, I
stumbled on what appeard to be a limitation of the sdl library, that a sdl 2D
surface cannot be bliped on a opengl surface.

I want to build a GUI system and the most natural way would be to create the GUI
components as 2D surfaces and blip them on an opengl surface. It seems that’s
not possible.

I know this subject have been discussed over and over. I’ve seen some
work-arrounds suggested, like glDrawPixels and creating a texture from the 2D
surface and so on.

I’m not interested in those work-arrounds. I want to find a solution to this
problem. I want this fixed once and for all. I’m pretty sure it can be done.

So, what do you think? What could be done to find a permanent, consistent
solution to this problem?

Hmmm, if I understand you correctly, then you want some way to SDL_BlitSurface() with normal SDL_Surface on OGL context? Sorry, AFAIK it’s impossible and you can’t expect that it will be added to SDL.

However, that “work around”, as you called “creating a texture from the 2D surface”, is IMHO best way to achieve what you want. Just create some functions that will load image from disk, create from SDL_Surface OGL texture, delete old surface, and then use only proper OGL texture object.
I’m using this approach for almost a year and there weren’t any problems so far, so it’s not that bad as you think.

HTH

Koshmaar

[…SDL->OpenGL blit…]

So, what do you think? What could be done to find a permanent,
consistent solution to this problem?

Well, glSDL (both the wrapper and the backend) actually does what you
want. It’s just that it’s behavior in relation to an application
sharing it’s OpenGL state is undefined. This is to ensure that the
glSDL backend implementation can be improved and optimized without
working around more problems than the current SDL API is already
causing.

I suppose one could add an API extension that applications can use
when they want to take over the OpenGL state for a moment, or return
it to glSDL. This would ensure that the glSDL implementation has a
chance of working properly together with OpenGL applications, and it
would allow OpenGL applications to use glSDL with native OpenGL
without depending on glSDL internals.

Still, something like this will never have quite the performance and
flexibility of using native OpenGL all the way through. Due to
limitations of the OpenGL API, it’ll never be completely transparent
anyway. Though pretty much any SDL 2D code should work with glSDL,
there are operations that will invariably result in very slow
rendering, and there’s nothing we can do about that without relying
on features that are not yet widely available.

So, what’s the point in (ab)using a 2D rendering API when you depend
on OpenGL anyway, really?

IMHO, the only truly valid answer to that is “code reuse.” It would be
very handy to be able to pull in SDL 2D code and make it work in an
OpenGL application, just like that. However, my experience is that
GUI toolkits, drop-down consoles and things like that - the most
interesting stuff in this context, I guess - will not perform well
with glSDL without changes.

Then again, the changes you have to make would help other h/w
accelerated backends as well, since it’s mostly a matter of adapting
to the way modern computers handle graphics. Should be a good thing,
provided the changes are fed back into the official versions of the
code.

Conclusion:
It shouldn’t be all that hard to add an API extension that
allows applications to mix glSDL and OpenGL in a well
defined manner. It’s not optimal, and cannot be 100% SDL 2D
compatible, but should be sufficient as a shortcut to make
code work in both SDL 2D and OpenGL applications. Also, the
changes made to adapt SDL 2D code are often relevant to h/w
accelerated backends in general.

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Sunday 08 May 2005 13.11, Daniel Secrieru wrote:

I’m not interested in those work-arrounds. I want to find a solution to this
problem. I want this fixed once and for all. I’m pretty sure it can be done.

http://openglgui.sourceforge.net/

This site will show you how to build a GUI system using OpenGL. If I
remember from a previous post, blit-ing to an OGL context can (and
probably will) destroy it. Those work arounds and the safest way of
doing it. Building a GUI system that uses OGL is a better way, IMHO.

HTH,
Richard–
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.11.6 - Release Date: 06-May-05

Why is it impossible? Please explain. I used to do it on Windows (not with SDL,
of course), so it’s possible, at least on Windows.

I think a lot of ppl would like to have this feature in SDL, why wouldn’t it get
added?

Sorry for my poor English, I’m not a native speaker. “work-arround” == “work
around” of course :-).

SDL is not only a 2D rendering API, last time I checked. It has support for
multi-threading, sound, networking and other stuff as well.

I really don’t understand why it’s so complicated. On Windows was as simple as
making a call to wglMakeCurrent.

I’m starting to think the same. Build the GUI system directly into OpenGL, stop
pulling hair with SDL surfaces limitations.

Would have been a nice feature, though… :frowning:

Ok, I might have overreacted. It does seem that rendering the SDL 2D surface
into a texture and applying it to a quad is the only acceptable solution and
also elegant enough.

I just wished that SDL would have done that internally and transparent.

As a side note, is there still any development done on SDL? I got the impression
that it stopped and that worries me. I would hate to see such a good library
slipping slowly into oblivion :(.

Although if you REALLY want to use SDL to do the menus, try this (I
think deprecated) option. When creating the screen surface, pass
SDL_OPENGLBLIT instead of SDL_OPENGL. Note that you would have to use
SDL_UpdateRects instead of SDL_GL_SwapBuffers.

However, if you do decide to do that, you have been warned about the
problems with it.

Note: glSDL may be a safe alternative but I havn’t used it so I can’t
speak much for it.

Richard

Daniel Secrieru wrote:>I’m starting to think the same. Build the GUI system directly into OpenGL, stop

pulling hair with SDL surfaces limitations.

Would have been a nice feature, though… :frowning:


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.11.6 - Release Date: 06-May-05

yeah, i really thind an SDL_OGL_BLIT( SDL_Surface * , RECt , etc )
could be possible by convertign the rect to a quad and the surface to a texture

i madea function to make an sdl surface into an ogl texture but the
colours are wrong, mainly because i’m not sure what the rgba masks are
( do they specify which bytes represent red, green and blue) and waht
way to arrange the format & i wasn’t 100% on the old bitwise
operations at the time

perhaps a function that binds a gl texture from a SDL_Surface would be
the handiest. people could then use it for 3 or 2 D texturing as they
see fit.

since many people have implemented this arleady( probably ), it
shouldn’t be hard to add

Hi there.

Maybe it would not be so hard to add a funcion that
would receive a SDL_SURFACE, make all the steps needed
and return a texture.
I am still on the beginning of OpenGL Study.

Talking about OpenGL and SDL, reading the docs I’ve
found out that SDL do all the ‘behind the scenes’
(replacing GLUT) to get OpenGL working properly, but,
there is another difference in using OpenGL with/
without SDL?

Thanks in Advance,

In?cio.

— Brian Barrett <brian.ripoff at gmail.com> escreveu:

yeah, i really thind an SDL_OGL_BLIT( SDL_Surface *
, RECt , etc )
could be possible by convertign the rect to a quad
and the surface to a texture

i madea function to make an sdl surface into an ogl
texture but the
colours are wrong, mainly because i’m not sure what
the rgba masks are
( do they specify which bytes represent red, green
and blue) and waht
way to arrange the format & i wasn’t 100% on the old
bitwise
operations at the time

perhaps a function that binds a gl texture from a
SDL_Surface would be
the handiest. people could then use it for 3 or 2 D
texturing as they
see fit.

since many people have implemented this arleady(
probably ), it
shouldn’t be hard to add


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

____________________________________________________Yahoo! Mail, cada vez melhor: agora com 1GB de espa?o gr?tis! http://mail.yahoo.com.br

J Inacio wrote:

Hi there.

Maybe it would not be so hard to add a funcion that
would receive a SDL_SURFACE, make all the steps needed
and return a texture.

There’s not much to do to get such functionality.

If the surface is RGBA8, you can feed the surface->pixels directly to
glTexImage2D().

Talking about OpenGL and SDL, reading the docs I’ve
found out that SDL do all the ‘behind the scenes’
(replacing GLUT) to get OpenGL working properly, but,
there is another difference in using OpenGL with/
without SDL?

There’s no difference, SDL just initializes OpenGL as found on your
platform. And then you have to use OpenGL directly.

Stephane

Hi there.

Maybe it would not be so hard to add a funcion that
would receive a SDL_SURFACE, make all the steps needed
and return a texture.
I am still on the beginning of OpenGL Study.

There is a function that does exactly what you want in the testgl.c
program in the test directory of the source distribution of SDL.

The test directory has a bunch of programs in it. That code is freely
reusable. In fact, the COPYING file tells us that they are public
domain. A huge number of the questions that are asked on this list are
answered by the test programs.

	Bob PendletonOn Tue, 2005-05-10 at 11:21 -0300, J Inacio wrote:

Talking about OpenGL and SDL, reading the docs I’ve
found out that SDL do all the ‘behind the scenes’
(replacing GLUT) to get OpenGL working properly, but,
there is another difference in using OpenGL with/
without SDL?

Thanks in Advance,

In?cio.

— Brian Barrett <brian.ripoff at gmail.com> escreveu:

yeah, i really thind an SDL_OGL_BLIT( SDL_Surface *
, RECt , etc )
could be possible by convertign the rect to a quad
and the surface to a texture

i madea function to make an sdl surface into an ogl
texture but the
colours are wrong, mainly because i’m not sure what
the rgba masks are
( do they specify which bytes represent red, green
and blue) and waht
way to arrange the format & i wasn’t 100% on the old
bitwise
operations at the time

perhaps a function that binds a gl texture from a
SDL_Surface would be
the handiest. people could then use it for 3 or 2 D
texturing as they
see fit.

since many people have implemented this arleady(
probably ), it
shouldn’t be hard to add


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

____________________________________________________Yahoo! Mail, cada vez melhor: agora com 1GB de espa?o gr?tis! http://mail.yahoo.com.br


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


±-------------------------------------+

Brian Barrett wrote:

i madea function to make an sdl surface into an ogl texture but the
colours are wrong, mainly because i’m not sure what the rgba masks are
( do they specify which bytes represent red, green and blue) and waht
way to arrange the format & i wasn’t 100% on the old bitwise
operations at the time

perhaps a function that binds a gl texture from a SDL_Surface would be
the handiest. people could then use it for 3 or 2 D texturing as they
see fit.

since many people have implemented this arleady( probably ), it
shouldn’t be hard to add

See this message:

It includes my (C++) code for this task, based on testgl.c in the SDL
source’s test directory.–
Jon