Project SGL

Published October 15, 2005
Advertisement
I started my SDL+OpenGL framework today. I am going to get something finished if it kills me this time. This is mainly spawned from wanting to use SDL but SDL not having the *oomf* I want or may want in the future.

I find myself re-writing a ton of the same code all the time, re-writing it slightly different each time. This time I am making a library I can edit and re-use all the time.

Here's a breakdown of how it will work in theory:
(Things with a * next to them have a working implementation already although not optimized)

SGL_XXX will be the naming convention used for classes and function calls specific to the library.

SGL relies on the STL quite a bit but only internally. In the instance of std:string it is pretty well hidden behind the class interfaces which all ask for const char * pointers and return the same. This was a decision I made to make my life with file i/o much simpler and will be the case throughout since it is quite easy to use the std::string.c_str() method to get a character array.

*SGL_Surface is a class I am working on that has most of the functionality of an SDL_Surface along with built in pixel manipulation. the BlitSurfaceEx member function supports scaling, rotation, and alpha blending while the BlitSurface functions support scaling and blending. It also supports multiple color keys where you can specify the level of alpha for different colors.

*SGL_Point is a class that acts as a 2D point in space and has integer and floating point interfaces.

*SGL_Vertex is a class that acts as an OpenGL vertex with x,y,z coordinates and a color. This class is mainly used behind the scenes as the SGL library is meant to be used for 2D applications.

*SGL_Rect is a class that contains an SDL_Rect but has the added functionality of being able to internally convert to texture coordinates while keeping the original integer level of a SDL_Rect intact for usefulness. Can also be rendered as a filled or empty polygon. Features interfaces for collision detection between other SGL_Rectangle and SGL_Point objects.

**(In the works)SGL_Circle:
**(In the works)SGL_Polygon:
**(In the works)SGL_Line:

*SGL_Sprite is a simple sprite class that has almost no internal data except for a source surface and source rectangle. It is meant to be a base class for more complex graphical objects. Using the DrawSpriteEx member function, you can scale, rotate, and/or blend a sprite. Think of an SGL_Sprite as a textured quad that can be stretched and/or rotated.

*SGL_File is a simple file i/o class that wraps C style file I/O. I love the ease of working with text files but hate writing specialized code every time to read/write my files. Most notably it has interfaces for reading single or quoted words as one token and reading multiple line strings by specifying an end_of_string character. There are also integer and floating point reading interfaces.

(**somewhat working)SGL_Font/SGL_Glyph is a simple bitmap font library for using bitmap fonts generated with "Bitmap Font Builder" (I will refer to it as BFB). It generates a stand alone font file from the bitmap and widths file from BFB so you don't have to keep the bulky bitmaps. This is just a simple library and is meant to be expanded as needed. Writing strings in printf style is supported but word wrapping is not.

Some notes on rotation and scaling:
Scaling is done by changing the size of the destination rectangle in the BlitSurface and DrawXXX functions. Rotation is available through specifying a SDL_Point of origin to rotate around and an angle of rotation from 0.0f to 1.0f.

I will start posting a link to the working code in a tarball in my next post.
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement