2D in 3D+SDL

Hi !

I need some advice about 2D rendering with a 3D engine.
I have a 2D application, running with SDL 1.2. It computes 2D vector
graphics with a software 2D engine. The image is computed in a user
memory buffer (a int array of RGBA values) than bilt to the SDL screen.
It works fine, but when the resolution is rather high (1680x1050) or if
the host is limited in CPU power, the performance is not very good when
the 2D scene is animated (3 to 10 fps).
I’d like to use a 3D engine to speed up rendering and blit. I am
thinking about using ShivaVG (based on OpenGL, see the
(http://sourceforge.net/projects/shivavg/)).
I converted the ShivaVG tests to SDL (replacing glut by SDL) and that
works fine, with both Linux/X11 and MS Windows.
The problem is that the 2D scene is not often animated and it seems (I
am not an expert at all) that OpenGL needs to be rendered all the time:
if the 3D scene is computed once and than enter the event loop, if the
SDL window gets covered by another, it is not refreshed. That problems
does not exist with ‘non OpenGL’ SDL window (refresh is made by some low
level magic, no need for the application to do some repaint).
Rendering 3D all the time requires CPU / GPU power, with is bad for a
laptop (for example a netbook) or a MID device (more and more low cost
devices have a 3D engine, OpenGL ES and/or OpenVG - see for example
http://www.malideveloper.com/ ).

Is it possible to do things such as:

  • compute an image with the 3D engine when needed than display a
    snapshot in a SDL ‘not OpenGL’ screen
  • take a snapshot of the last image (end of the animation), convert it
    to a texture and display it at no CPU / GPU / power cost, with some
    automatic low level refresh
  • freeze the 3D engine in a mode that would redraw itself automatically
    when needed (window raise, de-iconification, …)
  • other idea …

Thanks for your feedback, regards,
Lo?c

It sounds like, at least to me, that you are doing the rendering job twice,
once in the engine, and once in SDL (or OpenGL). Does the 2d engine you are
currently using have some sort of blitting interface, or does it only draw
to buffers and it’s up to you to render? is it possible to render
individual objects? By that, I mean instead of just blitting the whole
screen, could you just have your background and blit that, then, on top of
that, blit your sprites? That will speed things up dramatically, although
at that rate, you are better off scraping the engine you’re using and just
doing things on your own.

Maybe a good question to ask is what rendering engine are you using?

Take care,
-AlexOn Tue, Mar 30, 2010 at 7:37 AM, Lo?c LAMBERT < llambert at users.sourceforge.net> wrote:

Hi !

I need some advice about 2D rendering with a 3D engine.
I have a 2D application, running with SDL 1.2. It computes 2D vector
graphics with a software 2D engine. The image is computed in a user memory
buffer (a int array of RGBA values) than bilt to the SDL screen. It works
fine, but when the resolution is rather high (1680x1050) or if the host is
limited in CPU power, the performance is not very good when the 2D scene is
animated (3 to 10 fps).
I’d like to use a 3D engine to speed up rendering and blit. I am thinking
about using ShivaVG (based on OpenGL, see the (
http://sourceforge.net/projects/shivavg/)http://sourceforge.net/projects/shivavg/)
).
I converted the ShivaVG tests to SDL (replacing glut by SDL) and that works
fine, with both Linux/X11 and MS Windows.
The problem is that the 2D scene is not often animated and it seems (I am
not an expert at all) that OpenGL needs to be rendered all the time: if the
3D scene is computed once and than enter the event loop, if the SDL window
gets covered by another, it is not refreshed. That problems does not exist
with ‘non OpenGL’ SDL window (refresh is made by some low level magic, no
need for the application to do some repaint).
Rendering 3D all the time requires CPU / GPU power, with is bad for a
laptop (for example a netbook) or a MID device (more and more low cost
devices have a 3D engine, OpenGL ES and/or OpenVG - see for example
http://www.malideveloper.com/ ).

Is it possible to do things such as:

  • compute an image with the 3D engine when needed than display a snapshot
    in a SDL ‘not OpenGL’ screen
  • take a snapshot of the last image (end of the animation), convert it to a
    texture and display it at no CPU / GPU / power cost, with some automatic low
    level refresh
  • freeze the 3D engine in a mode that would redraw itself automatically
    when needed (window raise, de-iconification, …)
  • other idea …

Thanks for your feedback, regards,
Lo?c


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Well, I have not been clear enough on what I plan to do!

The application uses a software 2D engine to render SVG-like drawings
than bilt the image to the SDL screen.
The idea is to give up that 2D engine and to re-write the application to
call OpenVG or ShivaVG/OpenGL to draw lines, arcs circles, gradients,
manage filling, clipping, scaling, opacity, etc and than gain access to
hardware rendering.
A first step is to be in some kind of ‘immediate mode’ (render every
frame by calling the drawing methods for the full scene). Maybe a retain
mode will be possible when I will be an expert in OpenGL, just give me a
couple of weeks :wink:
Some commercial frameworks provides hardware accelerated 2D graphics,
but I am not rich and it is not fun !

So, when the scene is not animated, I’d like to save resources (mainly
CPU) until the next move.
What is the best way to do that? Is there some secret to let the OpenGL
engine refreshing the screen without a full rendering?

Thanks,
Lo?c> It sounds like, at least to me, that you are doing the rendering job

twice,
once in the engine, and once in SDL (or OpenGL). Does the 2d engine
you are
currently using have some sort of blitting interface, or does it only
draw
to buffers and it’s up to you to render? is it possible to render
individual objects? By that, I mean instead of just blitting the whole
screen, could you just have your background and blit that, then, on
top of
that, blit your sprites? That will speed things up dramatically,
although
at that rate, you are better off scraping the engine you’re using and
just
doing things on your own.

Maybe a good question to ask is what rendering engine are you using?

Take care,
-Alex

On Tue, Mar 30, 2010 at 7:37 AM, Lo?c LAMBERT < llambert at users.sourceforge.net> wrote:

Hi !

I need some advice about 2D rendering with a 3D engine.
I have a 2D application, running with SDL 1.2. It computes 2D vector
graphics with a software 2D engine. The image is computed in a user
memory
buffer (a int array of RGBA values) than bilt to the SDL screen. It
works
fine, but when the resolution is rather high (1680x1050) or if the
host is
limited in CPU power, the performance is not very good when the 2D
scene is
animated (3 to 10 fps).
I’d like to use a 3D engine to speed up rendering and blit. I am
thinking
about using ShivaVG (based on OpenGL, see the (

http://sourceforge.net/projects/shivavg/)http://sourceforge.net/projects/shivavg/)

).
I converted the ShivaVG tests to SDL (replacing glut by SDL) and
that works
fine, with both Linux/X11 and MS Windows.
The problem is that the 2D scene is not often animated and it seems
(I am
not an expert at all) that OpenGL needs to be rendered all the time:
if the
3D scene is computed once and than enter the event loop, if the SDL
window
gets covered by another, it is not refreshed. That problems does not
exist
with ‘non OpenGL’ SDL window (refresh is made by some low level
magic, no
need for the application to do some repaint).
Rendering 3D all the time requires CPU / GPU power, with is bad for a
laptop (for example a netbook) or a MID device (more and more low cost
devices have a 3D engine, OpenGL ES and/or OpenVG - see for example
http://www.malideveloper.com/ ).

Is it possible to do things such as:

  • compute an image with the 3D engine when needed than display a
    snapshot
    in a SDL ‘not OpenGL’ screen
  • take a snapshot of the last image (end of the animation), convert
    it to a
    texture and display it at no CPU / GPU / power cost, with some
    automatic low
    level refresh
  • freeze the 3D engine in a mode that would redraw itself automatically
    when needed (window raise, de-iconification, …)
  • other idea …

Thanks for your feedback, regards,
Lo?c