SDL backend changes

This commit is contained in:
James Turk 2003-08-02 01:18:45 +00:00
parent 10aca6a817
commit d8e6296de7
13 changed files with 71 additions and 41 deletions

View File

@ -22,20 +22,14 @@
//Defines- undefine any of these if you dont have the indicated SDL extension// //Defines- undefine any of these if you dont have the indicated SDL extension//
/*!
\brief Defines for graphics backend selection.
Various graphics backends, default is OpenGL, but to port to systems with SDL but no OpenGL //! OpenGL 2D Rendering Target.
use of SDL is possible. . #define ZE_OGL (1)
**/ //! SDL Rendering Target.
enum GFXBackend #define ZE_SDL (2)
{ //! Define the graphics backend for ZEngine to use. (Options are ZE_OGL,ZE_SDL,ZE_D3D)
OGL, /*!< OpenGL 2D Rendering Target. */ #define GFX_BACKEND (ZE_SDL)
SDL /*!< SDL Rendering Target. */
};
//! Define the graphics backend for ZEngine to use. (Options are OGL,SDL,DX)
#define GFX_BACKEND OGL
//! Define to include font support. //! Define to include font support.
#define USE_SDL_TTF #define USE_SDL_TTF
//! Define to include non-bmp image file support. //! Define to include non-bmp image file support.

View File

@ -24,7 +24,7 @@
#include "ZE_Defines.h" #include "ZE_Defines.h"
#include "SDL.h" #include "SDL.h"
#if GFX_BACKEND == OGL #if (GFX_BACKEND == ZE_OGL)
#include "SDL_opengl.h" #include "SDL_opengl.h"
#include "external/SDLGL_Util.h" #include "external/SDLGL_Util.h"
#endif #endif

View File

@ -13,7 +13,7 @@
\brief Definition file for core ZEngine class. \brief Definition file for core ZEngine class.
ZEngine Game Engine core Engine definition. ZEngine Game Engine core Engine definition.
<br>$Id: ZE_ZEngine.h,v 1.45 2003/08/01 21:57:32 cozman Exp $<br> <br>$Id: ZE_ZEngine.h,v 1.46 2003/08/02 01:18:45 cozman Exp $<br>
\author James Turk \author James Turk
**/ **/
@ -240,7 +240,7 @@ class ZEngine
**/ **/
void Clear(Uint8 red=0, Uint8 green=0, Uint8 blue=0, Uint8 alpha=255); void Clear(Uint8 red=0, Uint8 green=0, Uint8 blue=0, Uint8 alpha=255);
#if GFX_BACKEND == OGL #if (GFX_BACKEND == ZE_OGL)
///////////////////////////// /////////////////////////////
//OpenGL Specific Functions// //OpenGL Specific Functions//
///////////////////////////// /////////////////////////////

View File

@ -13,7 +13,7 @@
\brief Definition file for ZImage. \brief Definition file for ZImage.
Definition file for ZImage, the OpenGL version of the ZImage class for ZEngine. Definition file for ZImage, the OpenGL version of the ZImage class for ZEngine.
<br>$Id: ZE_ZImage.h,v 1.20 2003/08/01 21:57:32 cozman Exp $<br> <br>$Id: ZE_ZImage.h,v 1.21 2003/08/02 01:18:45 cozman Exp $<br>
\author James Turk \author James Turk
**/ **/
@ -39,7 +39,7 @@ class ZImage
SDL_Surface *rImage; SDL_Surface *rImage;
//! Stored alpha value for drawing texture. //! Stored alpha value for drawing texture.
Uint8 rAlpha; Uint8 rAlpha;
#if GFX_BACKEND == OGL #if (GFX_BACKEND == ZE_OGL)
//! Texture lower X, used internally for flip. //! Texture lower X, used internally for flip.
GLfloat rTexMinX; GLfloat rTexMinX;
//! Texture lower Y, used internally for flip //! Texture lower Y, used internally for flip
@ -214,7 +214,7 @@ class ZImage
**/ **/
void Draw(int x, int y) const; void Draw(int x, int y) const;
#if GFX_BACKEND == OGL #if (GFX_BACKEND == ZE_OGL)
/*! /*!
\brief Draw Image to Screen. \brief Draw Image to Screen.

View File

@ -14,7 +14,7 @@
Definition and implementation file for ZEngine simple particle system, ZSimpleParticleSystem based on ZBaseParticleSystem. Definition and implementation file for ZEngine simple particle system, ZSimpleParticleSystem based on ZBaseParticleSystem.
Due to problems with template classes the template implementation needs to be in the same file as the declaration. Due to problems with template classes the template implementation needs to be in the same file as the declaration.
<br>$Id: ZE_ZSimpleParticleSystem.h,v 1.3 2003/07/10 23:45:09 cozman Exp $<br> <br>$Id: ZE_ZSimpleParticleSystem.h,v 1.4 2003/08/02 01:18:45 cozman Exp $<br>
\author James Turk \author James Turk
**/ **/
@ -283,6 +283,8 @@ void ZSimpleParticleSystem<particleType>::UpdateParticle(int index, float elapse
rParticles[index].energy = 0; rParticles[index].energy = 0;
} }
#if (GFX_BACKEND == ZE_OGL)
template <class particleType> template <class particleType>
void ZSimpleParticleSystem<particleType>::Render() void ZSimpleParticleSystem<particleType>::Render()
{ {
@ -332,6 +334,36 @@ void ZSimpleParticleSystem<particleType>::Render()
} }
} }
#elif (GFX_BACKEND == ZE_SDL)
template <class particleType>
void ZSimpleParticleSystem<particleType>::Render()
{
switch(rStyle)
{
case DS_POINT:
for(unsigned int i=0; i < rCurParticles; i++)
{
//draw point
}
break;
case DS_LINE:
for(unsigned int i=0; i < rCurParticles; i++)
{
//draw line
}
break;
case DS_IMAGE:
for(unsigned int i=0; i < rCurParticles; i++)
{
//draw image
}
break;
}
}
#endif //GFX_BACKEND
template <class particleType> template <class particleType>
void ZSimpleParticleSystem<particleType>::ReloadImage() void ZSimpleParticleSystem<particleType>::ReloadImage()
{ {

View File

@ -6,7 +6,7 @@
#include "ZE_Includes.h" #include "ZE_Includes.h"
#if GFX_BACKEND == OGL #if (GFX_BACKEND == ZE_OGL)
int power_of_two(int input); int power_of_two(int input);
GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord); GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord);
#endif #endif

View File

@ -13,7 +13,7 @@
\brief Central source file for ZEngine. \brief Central source file for ZEngine.
Actual implementation of ZEngine singleton class, the core of ZEngine. Actual implementation of ZEngine singleton class, the core of ZEngine.
<br>$Id: ZE_ZEngine.cpp,v 1.54 2003/08/01 21:56:58 cozman Exp $<br> <br>$Id: ZE_ZEngine.cpp,v 1.55 2003/08/02 01:18:45 cozman Exp $<br>
\author James Turk \author James Turk
**/ **/
@ -84,7 +84,7 @@ bool ZEngine::CreateDisplay(std::string title, std::string icon)
SDL_Surface *iconImg; SDL_Surface *iconImg;
bool status=true; //status of setup, only true if everything went flawless bool status=true; //status of setup, only true if everything went flawless
int bpp; int bpp;
#if GFX_BACKEND == OGL #if (GFX_BACKEND == ZE_OGL)
int rgb_size[3]; int rgb_size[3];
#endif #endif
@ -136,7 +136,7 @@ bool ZEngine::CreateDisplay(std::string title, std::string icon)
} }
} }
#if GFX_BACKEND == OGL #if (GFX_BACKEND == ZE_OGL)
//buffer sizes //buffer sizes
switch (mBPP) switch (mBPP)
{ {
@ -171,7 +171,7 @@ bool ZEngine::CreateDisplay(std::string title, std::string icon)
SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 0); SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 0);
flags |= SDL_OPENGL; flags |= SDL_OPENGL;
#elif GFX_BACKEND == SDL #elif (GFX_BACKEND == ZE_SDL)
flags |= SDL_DOUBLEBUF; flags |= SDL_DOUBLEBUF;
#endif //GFX_BACKEND #endif //GFX_BACKEND
@ -208,7 +208,7 @@ bool ZEngine::CreateDisplay(std::string title, std::string icon)
mHeight = mScreen->h; mHeight = mScreen->h;
mBPP = mScreen->format->BitsPerPixel; mBPP = mScreen->format->BitsPerPixel;
#if GFX_BACKEND == OGL #if (GFX_BACKEND == ZE_OGL)
SetGL2D(); SetGL2D();
#endif #endif
@ -304,9 +304,9 @@ SDL_Surface *ZEngine::Display()
void ZEngine::Update() void ZEngine::Update()
{ {
#if GFX_BACKEND == OGL #if (GFX_BACKEND == ZE_OGL)
SDL_GL_SwapBuffers(); SDL_GL_SwapBuffers();
#elif GFX_BACKEND == SDL #elif (GFX_BACKEND == ZE_SDL)
SDL_Flip(mScreen); SDL_Flip(mScreen);
#endif #endif
@ -323,7 +323,7 @@ void ZEngine::Update()
} }
} }
#if GFX_BACKEND == OGL #if (GFX_BACKEND == ZE_OGL)
void ZEngine::Clear(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha) void ZEngine::Clear(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha)
{ {
@ -359,7 +359,7 @@ void ZEngine::SetGL2D()
glLoadIdentity(); glLoadIdentity();
} }
#elif GFX_BACKEND == SDL #elif (GFX_BACKEND == ZE_SDL)
void ZEngine::Clear(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha) void ZEngine::Clear(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha)
{ {

View File

@ -13,7 +13,7 @@
\brief Source file for ZImage. \brief Source file for ZImage.
Implementation of ZImage, the Image class for ZEngine. Implementation of ZImage, the Image class for ZEngine.
<br>$Id: ZE_ZImage.cpp,v 1.38 2003/08/01 21:56:58 cozman Exp $<br> <br>$Id: ZE_ZImage.cpp,v 1.39 2003/08/02 01:18:45 cozman Exp $<br>
\author James Turk \author James Turk
**/ **/
@ -116,7 +116,7 @@ void ZImage::OpenFromImage(const ZImage &img, Sint16 x, Sint16 y, Sint16 w, Sint
OpenFromImage(img.Surface(),x,y,w,h); OpenFromImage(img.Surface(),x,y,w,h);
} }
#if GFX_BACKEND == OGL #if (GFX_BACKEND == ZE_OGL)
//attach is really the core of ZImage, everything calls it, it converts SDL_Surface->OpenGL Texture->ZImage //attach is really the core of ZImage, everything calls it, it converts SDL_Surface->OpenGL Texture->ZImage
void ZImage::Attach(SDL_Surface *surface) void ZImage::Attach(SDL_Surface *surface)
@ -292,7 +292,7 @@ bool ZImage::IsLoaded() const
return glIsTexture(rTexID) == GL_TRUE; return glIsTexture(rTexID) == GL_TRUE;
} }
#elif GFX_BACKEND == SDL #elif (GFX_BACKEND == ZE_SDL)
void ZImage::Attach(SDL_Surface *surface) void ZImage::Attach(SDL_Surface *surface)
{ {

View File

@ -13,7 +13,7 @@
\brief Source file for ZRect. \brief Source file for ZRect.
Implementation of ZRect, the Rectangle class for ZEngine. Implementation of ZRect, the Rectangle class for ZEngine.
<br>$Id: ZE_ZRect.cpp,v 1.13 2003/08/01 21:56:58 cozman Exp $<br> <br>$Id: ZE_ZRect.cpp,v 1.14 2003/08/02 01:18:45 cozman Exp $<br>
\author James Turk \author James Turk
**/ **/
@ -100,7 +100,7 @@ bool ZRect::operator<(const ZRect &rhs) const
void ZRect::Draw(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha) const void ZRect::Draw(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha) const
{ {
#if GFX_BACKEND == OGL #if (GFX_BACKEND == ZE_OGL)
glBindTexture(GL_TEXTURE_2D,0); //reset to blank texture glBindTexture(GL_TEXTURE_2D,0); //reset to blank texture
glColor4ub(red,green,blue,alpha); glColor4ub(red,green,blue,alpha);
glBegin(GL_QUADS); glBegin(GL_QUADS);
@ -110,7 +110,7 @@ void ZRect::Draw(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha) const
glVertex2f(rX, rY+rHeight); glVertex2f(rX, rY+rHeight);
glEnd(); glEnd();
glColor4ub(255,255,255,255); //restore color setting glColor4ub(255,255,255,255); //restore color setting
#elif GFX_BACKEND == SDL #elif (GFX_BACKEND == ZE_SDL)
SDL_Rect rect = SDLrect(); SDL_Rect rect = SDLrect();
SDL_FillRect(rEngine->Display(), &rect, SDL_MapRGBA(rEngine->Display()->format,red,green,blue,alpha)); SDL_FillRect(rEngine->Display(), &rect, SDL_MapRGBA(rEngine->Display()->format,red,green,blue,alpha));
#endif //GFX_BACKEND #endif //GFX_BACKEND

View File

@ -4,7 +4,7 @@
#include "external/SDLGL_Util.h" #include "external/SDLGL_Util.h"
#if GFX_BACKEND == OGL #if (GFX_BACKEND == ZE_OGL)
//finds nearest power of two (going up), needed for surfaces //finds nearest power of two (going up), needed for surfaces
int power_of_two(int input) int power_of_two(int input)

View File

@ -9,7 +9,7 @@ This example file is in the public domain, it may be used with no restrictions.
and the home of this Library is http://www.zengine.sourceforge.net and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/ *******************************************************************************/
/*$Id: ZFontTest.cpp,v 1.13 2003/07/10 20:45:39 cozman Exp $*/ /*$Id: ZFontTest.cpp,v 1.14 2003/08/02 01:18:45 cozman Exp $*/
#include <ZEngine.h> #include <ZEngine.h>
#include <string> #include <string>
@ -70,7 +70,7 @@ void Test()
engine->Clear(); //clear screen engine->Clear(); //clear screen
//draw the images// //draw the images//
for(int i=0; i <= 5; i++) for(int i=0; i <= 5; i++)
text[i].Draw(10.0f*i,50.0f*i); text[i].Draw(10*i,50*i);
engine->Update(); //update the screen engine->Update(); //update the screen
} }

View File

@ -9,7 +9,7 @@ This example file is in the public domain, it may be used with no restrictions.
and the home of this Library is http://www.zengine.sourceforge.net and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/ *******************************************************************************/
/*$Id: ZImageTest.cpp,v 1.19 2003/07/10 20:45:39 cozman Exp $*/ /*$Id: ZImageTest.cpp,v 1.20 2003/08/02 01:18:45 cozman Exp $*/
#include <ZEngine.h> #include <ZEngine.h>
#include <string> #include <string>
@ -91,9 +91,13 @@ void Test()
image1.SetAlpha(alpha); image1.SetAlpha(alpha);
image1.Draw(0,0); image1.Draw(0,0);
#if (GFX_BACKEND == ZE_OGL)
image2.DrawRotated(100,0,angle); image2.DrawRotated(100,0,angle);
if(++angle > 360) if(++angle > 360)
angle = 0.0f; angle = 0.0f;
#elif (GFX_BACKEND == ZE_SDL)
image2.Draw(100,0);
#endif
image3.Draw(200,0); image3.Draw(200,0);
textImage.Draw(0,100); textImage.Draw(0,100);

View File

@ -9,7 +9,7 @@ This example file is in the public domain, it may be used with no restrictions.
and the home of this Library is http://www.zengine.sourceforge.net and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/ *******************************************************************************/
/*$Id: ZParticleTest.cpp,v 1.2 2003/07/11 20:51:45 cozman Exp $*/ /*$Id: ZParticleTest.cpp,v 1.3 2003/08/02 01:18:45 cozman Exp $*/
#include <ZEngine.h> #include <ZEngine.h>
#include <string> #include <string>
@ -76,7 +76,7 @@ void Test()
effect[2].SetImage("data/particle2.tga"); effect[2].SetImage("data/particle2.tga");
bg.Open("data/rainbow.bmp"); bg.Open("data/rainbow.bmp");
bg.Resize(engine->DisplayWidth()/2,engine->DisplayHeight()); //gives perspective on alpha on half of screen //bg.Resize(engine->DisplayWidth()/2,engine->DisplayHeight()); //gives perspective on alpha on half of screen
font.DrawText("(P)ause (U)npause (C)lear",text[0]); font.DrawText("(P)ause (U)npause (C)lear",text[0]);
font.DrawText("1-3 : Change System Being Controlled",text[1]); font.DrawText("1-3 : Change System Being Controlled",text[1]);