[SDL] IMHO OpenGL is the best 2D API for Linux, was Re: SDL1.3 - surface for created windows?
Bob Pendleton
bob at pendleton.com
Mon May 11 11:33:44 PDT 2009
Great minds and all that... I have a tiny 2D GL like API buried in one
of my font libraries. Its layered on top of software and OpenGL, no
DirectX.
Bob Pendleton
On Mon, May 11, 2009 at 11:21 AM, David Olofson <david at olofson.net> wrote:
> On Sunday 10 May 2009, Bob Pendleton wrote:
> [...]
>> Not suggesting, just asking, how would people like a *simple* 2D API
>> that is compatible with SDL but uses OpenGL for all operations. What
>> would you want in it? And, most importantly, what would be in it
>> that isn't already in SDL?
>
> Some people have been using modified versions of glSDL, which *is* the
> SDL 2D API, with a few (OpenGL mode only) extensions:
>
> ---------------------------------------------------------------
> /*
> * Set alpha multiplier. This is multiplied with any full
> * surface alpha or alpha channels of surfaces.
> *
> * The default value is 255, which makes glSDL render like
> * the standard SDL 2D backends, ie based only on the
> * surface settings.
> *
> * This function affects the global state of glSDL.
> *
> * NOTE: NOT available without OpenGL acceleration!
> */
> void glSDL_SetBlendAlpha(Uint8 alpha);
>
> /*
> * Set color multipliers. These are multiplied with the
> * respective color channers of rendered surfaces,
> * modulating the brightness of the resulting output.
> *
> * The default values are 255, which makes glSDL render
> * like the standard SDL 2D backends.
> *
> * This function affects the global state of glSDL.
> *
> * NOTE: NOT available without OpenGL acceleration!
> */
> void glSDL_SetBlendColor(Uint8 r, Uint8 g, Uint8 b);
>
> /*
> * Set center offset in pixels for scaling and rotation.
> *
> * The default is (0, 0), which makes surfaces rotate and
> * scale around their centers.
> *
> * This function affects the global state of glSDL.
> *
> * NOTE: NOT available without OpenGL acceleration!
> */
> void glSDL_SetCenter(float x, float y);
>
>
> /*
> * Set rotation angle in degrees. Rotation is done around
> * the center point, which is defined as
> * (w/2 + cx, h/2 + cy)
> * where w and h are the width and height of the source
> * surface, and cx and cy are the center offsets set by
> * glSDL_SetCenter().
> *
> * The default value is 0.0f, which makes glSDL render
> * like a normal SDL 2D backend.
> *
> * This function affects the global state of glSDL.
> *
> * NOTE: NOT available without OpenGL acceleration!
> */
> void glSDL_SetRotation(float angle);
>
> /*
> * Set scale factor. Scaling is centered around around
> * the point
> * (w/2 + cx, h/2 + cy)
> * where w and h are the width and height of the source
> * surface, and cx and cy are the center offsets set by
> * glSDL_SetCenter().
> *
> * The default value is 1.0f, which makes glSDL render
> * like a normal SDL 2D backend.
> *
> * This function affects the global state of glSDL.
> *
> * NOTE: NOT available without OpenGL acceleration!
> */
> void glSDL_SetScale(float x, float y);
>
> /*
> * Reset glSDL global state to defaults.
> */
> void glSDL_ResetState(void);
> ---------------------------------------------------------------
>
>
> Personally, I'd prefer something slightly more flexible than the SDL
> API for rendering, more like the OpenGL style API below. (Started
> hacking this in 2006, but never got around to finish it. The idea was
> to implement it over OpenGL, Direct3D and software.)
>
> ---------------------------------------------------------------
> /*
> * Primitives for A2D_Begin()
> */
> typedef enum
> {
> A2D_POINTS,
> A2D_LINES,
> A2D_LINE_LOOP,
> A2D_LINE_STRIP,
> A2D_TRIANGLES,
> A2D_TRIANGLE_STRIP,
> A2D_TRIANGLE_FAN,
> A2D_QUADS,
> A2D_QUAD_STRIP,
> A2D_POLYGON
> } A2D_Primitives;
>
>
> /*
> * Modes for A2D_FilterMode()
> */
> typedef enum
> {
> A2D_NEAREST,
> A2D_NEAREST_MIPMAP,
> A2D_LINEAR,
> A2D_LINEAR_MIPMAP,
> A2D_CUBIC,
> A2D_CUBIC_MIPMAP
> } A2D_FilterModes;
>
>
> /*
> * Modes for A2D_BlendMode()
> */
> typedef enum
> {
> A2D_OPAQUE, /* Opaque rendering */
> A2D_MASK, /* Copy if src alpha > 0 */
> A2D_SRCALPHA, /* Source alpha blending */
> A2D_DSTALPHA, /* Destination alpha blending */
> A2D_ADD, /* Additive blending */
> A2D_SUBTRACT, /* Subtractive blending */
> A2D_MODULATE /* Modulation (multiplication) */
> } A2D_BlendModes;
>
>
> /*
> * Select target surface for subsequent rendering.
> */
> void A2D_Target(SDL_Surface *target);
>
>
> /*
> * Select texture for subsequent rendering.
> * Pass 0 for 'texid' to disable texturing, for
> * same results as using an opaque white texture.
> */
> void A2D_Texture(SDL_TextureID texid);
>
>
> /*
> * Set texture filtering mode.
> */
> void A2D_FilterMode(A2D_FilterModes fm);
>
>
> /*
> * Set rendering blend function.
> */
> void A2D_BlendMode(A2D_BlendModes mode);
>
>
> /*
> * Rendering functions
> */
> void A2D_Begin(A2D_Primitives prim);
> void A2D_Vertex(float x, float y);
> void A2D_TexCoord(float x, float y);
> void A2D_ColorRGB(float r, float g, float b);
> void A2D_ColorRGBA(float r, float g, float b, float a);
> void A2D_End(void);
>
>
> /*
> * Ensure that changes to the current target surface are
> * made visible.
> */
> void A2D_Update(void);
>
>
> /*
> * Quickly fill the current target surface with the
> * specified color.
> */
> void A2D_Clear(float r, float g, float b, float a);
> ---------------------------------------------------------------
>
>
> --
> //David Olofson - Programmer, Composer, Open Source Advocate
>
> .------- http://olofson.net - Games, SDL examples -------.
> | http://zeespace.net - 2.5D rendering engine |
> | http://audiality.org - Music/audio engine |
> | http://eel.olofson.net - Real time scripting |
> '-- http://www.reologica.se - Rheology instrumentation --'
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
--
+-----------------------------------------------------------
+ Bob Pendleton: writer and programmer
+ email: Bob at Pendleton.com
+ web: www.TheGrumpyProgrammer.com
More information about the SDL
mailing list