Starting my new project

Published May 03, 2005
Advertisement
Well, a few days ago I started looking into moving into OpenGL for 2d stuff again. I took about a whole day of fiddling around with stuff and I got a good start thanks to using the hxRender library by PnP Bios. Now I want to move on and make an SDL like library for my own knowledge as well as hopefully give something back to the community as well. The main thing i am looking for now is how to render to a specific texture instead of the screen and how to switch back and forth. Otherwise the SDL like functions of specifying a destination to blit to won't quite feel right. I suppose that is my own opinion but ow well...

Here is a quick look at the header for the library. I haven't written any actual code yet since most of my time has been spent researching how to do most of these tasks. I still don't know how to change a colorkey value for a texture or if it is even possible and the rotation thing is kind of giving me a headache with the pushing and popping matrix thing which I don't even know if it is necessary yet.

Well, here it is so far.

/*************************************************************************** *  GL2D_defs.h                                                            * *                                                                         * *  GL2D #define macros                                                    * *  type defines for using the GL2D library                                * *  prototypes for library functions                                       * *                                                                         * ***************************************************************************/// for the most part functions with a return value that isn't a pointer// return 0 for success and -1 if a failure occured// use these macros as -1 will be true and 0 will be false on most machines#define	GL2D_ERROR		-1#define	GL2D_SUCCESS	 0// an easy way to check if functions failed or not#define GL2D_OK(val)	( (val)==GL2D_SUCCESS ? TRUE : FALSE )// GL2D's version of a color// almost the same as SDL :)typedef struct GL2D_COLOR{	unsigned char	red;	unsigned char	green;	unsigned char	blue;	unsigned char	alpha;};// GL2D's version of a rectangle with integer// will be used in some API blit functions// to resemble SDL_Blit*typedef struct GL2D_RECTI{	GLint	x;	GLint	y;	GLuint	w;	GLuint	h;};// GL2D's version of a rectangle with floating point values// for better translation by opengl.// will be used in some API blit functions// to resemble SDL_Blit*typedef struct GL2D_RECTF{	float	x;	float	y;	float	w;	float	h;};// GL2D version of a vertextypedef struct GL2D_VERTEX{	float	x;	float	y;};// if it helps to name it differently:typedef GL2D_VERTEX		GL2D_POINT;// GL2D structure to hold 4 verticies making up a quadtypedef struct GL2D_QUAD{	GL2D_VERTEX		v0;	GL2D_VERTEX		v1;	GL2D_VERTEX		v2;	GL2D_VERTEX		v3;};// GL2D's version of an SDL surface.// Since surfaces have some large differences// from OpenGL textures I am sure this will // operate differently than most people are used to but// the purpose of this library is to hide the 3d bs from// the user so I won't go into too much detail.typedef struct GL2D_SURFACE{	GLuint	texture_id;	// the texture id of the surface	GLuint	width;		// the width in pixels of the surface	GLuint	height;		// the height in pixels of the surface	GLuint	bpp;		// the bits per pixel of the surface	GLuint	pitch;		// the pitch of the surface (the actual width of a scanline in memory)	GLuint	colors;		// number of colors in the palette ( 0 if bpp > 8 )	void	*palette;	// pointer to the palette colors ( NULL if bpp > 8 )	void	*pixeldata;	// pointer to raw pixel data of the surface};// lirary startup/quit functionsGLint	GL2D_Init(); // init GL2D - not sure if this will be necessaryGLint	GL2D_Quit(); // exit GL2D - or if they will wrap regular SDL_Init and Quit// init the video surface// the return value isn't very useful since rendering functions in OpenGL// do not require a destination surface/texture to render. The screen is the// default render target.GL2D_SURFACE	*GL2D_SetVideoMode( GLuint width, GLuint height GLuint bpp, GLboolean fullscreen );// Surface creationGL2D_SURFACE	*GL2D_CreateRGBSurface( GLuint width, GLuint height, GLuint bpp );GL2D_SURFACE	*GL2D_CreateRGBSurfaceFrom( void *pixeldata, GLuint width, GLuint height, GLuint bpp );GL2D_SURFACE	*GL2D_LoadBMP( char *bitmap );// free a GL2D_SURFACE from memoryvoid	GL2D_FreeSurface( GL2D_SURFACE *surface );//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// pixel and primitives drawing functions//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// pixel functionsGLint	GL2D_GetPixel( GL2D_SURFACE *surface, GLuint x, GLuint y, GL2D_COLOR *pixel );GLint	GL2D_SetPixel( GL2D_SURFACE *surface, GLuint x, GLuint y, GL2D_COLOR *pixel );// line functionGLint	GL2D_DrawLine( GL2D_SURFACE *surface, GL2D_VERTEX *start, GL2D_VERTEX *end, GL2D_COLOR *color );GLint	GL2D_DrawLine( GL2D_SURFACE *surface, GLuint x1, GLuint y1, GLuint x2, GLuint y2, GL2D_COLOR *color );GLint	GL2D_DrawLine( GL2D_SURFACE *surface, float x1, float y1, float x2, float y2, GL2D_COLOR *color );// rectangle functionsGLint	GL2D_DrawRect( GL2D_SURFACE *surface, GL2D_RECTI *rect, GL2D_COLOR *color );GLint	GL2D_FillRect( GL2D_SURFACE *surface, GL2D_RECTI *rect, GL2D_COLOR *color );// circle functions// no idea how to do this in a good way other than points or as a polygon/*GLint	GL2D_DrawCircle( GL2D_SURFACE *surface, float origin_x, float origin_y, float radius, GL2D_COLOR *color );GLint	GL2D_FillCircle( GL2D_SURFACE *surface, float origin_x, float origin_y, float radius, GL2D_COLOR *color );*/// polygon functionsGLint	GL2D_DrawPolygon( GL2D_SURFACE *surface, GL2D_VERTEX *verts, GLuint num_verts, GL2D_COLOR *color );GLint	GL2D_FillPolygon( GL2D_SURFACE *surface, GL2D_VERTEX *verts, GLuint num_verts, GL2D_COLOR *color );//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Blitting functions//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// If the destination quad differs in size from the source quad then scaling is done.// If the alpha value is less than 1.0 then alpha blending is applied.// Returns 0 on success and -1 if failure.GLint	GL2D_BlitSurface( GL2D_SURFACE *source_surface, GL2D_QUAD *source_quad, GL2D_SURFACE *destination_surface, GL2D_QUAD *destination_quad, float alpha );GLint	GL2D_BlitSurface( GL2D_SURFACE *source_surface, GL2D_RECTI *source_rect, GL2D_SURFACE *destination_surface, GL2D_RECTI *destination_rect, float alpha );GLint	GL2D_BlitSurface( GL2D_SURFACE *source_surface, GL2D_RECTF *source_rect, GL2D_SURFACE *destination_surface, GL2D_RECTF *destination_rect, float alpha );//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Conversion functions//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////GL2D_QUAD	GL2D_RECTF_TO_QUAD( GL2D_RECTF *rect );GL2D_QUAD	GL2D_RECTI_TO_QUAD( GL2D_RECTI *rect );GL2D_RECTF	GL2D_RECTF_TO_QUAD( GL2D_QUAD  *quad );GL2D_RECTI	GL2D_RECTI_TO_QUAD( GL2D_QUAD  *quad );


I will keep posting stuff here as I continue to work on it. I am planning on keeping the C style functions since both OpenGL and SDL use them but I imagine this stuff should be easy to wrap up into a class or classes of some sort.


Previous Entry work sucks!!!
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