diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-05-30 11:32:58 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-05-30 11:32:58 (GMT) |
| commit | 86746f38b0c0f382f06eb11c59b3dc49641490aa (patch) | |
| tree | e6b6b239f9097c06faa235e2773903f811458519 /src | |
| parent | 7074036b898083cdab1316cedbbade009ce6422d (diff) | |
| download | powder-86746f38b0c0f382f06eb11c59b3dc49641490aa.zip powder-86746f38b0c0f382f06eb11c59b3dc49641490aa.tar.gz | |
Separate SDL from graphics code
Also remove OS X specific project files and update Makefile to ensure
the Element class generator only runs when necessary
Diffstat (limited to 'src')
| -rw-r--r-- | src/Graphics.h | 7 | ||||
| -rw-r--r-- | src/OpenGLGraphics.cpp | 69 | ||||
| -rw-r--r-- | src/PowderToySDL.cpp (renamed from src/PowderToy.cpp) | 58 | ||||
| -rw-r--r-- | src/RasterGraphics.cpp | 25 | ||||
| -rw-r--r-- | src/interface/Engine.cpp | 2 |
5 files changed, 70 insertions, 91 deletions
diff --git a/src/Graphics.h b/src/Graphics.h index 5e43417..d3f891c 100644 --- a/src/Graphics.h +++ b/src/Graphics.h @@ -117,9 +117,7 @@ public: #ifdef OGLR //OpenGL specific instance variables GLuint vidBuf, textTexture; -#else - SDL_Surface * sdl_scrn; -#endif + #endif //Common graphics methods in Graphics.cpp static char * GenerateGradient(pixel * colours, float * points, int pointcount, int size); @@ -147,8 +145,7 @@ public: void draw_icon(int x, int y, Icon icon); void Clear(); - void AttachSDLSurface(SDL_Surface * surface); - void Blit(); + void Finalise(); // int drawtext(int x, int y, const char *s, int r, int g, int b, int a); int drawtext(int x, int y, std::string s, int r, int g, int b, int a); diff --git a/src/OpenGLGraphics.cpp b/src/OpenGLGraphics.cpp index 61c422c..b7d4795 100644 --- a/src/OpenGLGraphics.cpp +++ b/src/OpenGLGraphics.cpp @@ -6,85 +6,60 @@ Graphics::Graphics(): sdl_scale(1) { - -} - -Graphics::~Graphics() -{ -} - -void Graphics::Clear() -{ - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); -} - -void Graphics::AttachSDLSurface(SDL_Surface * surface) -{ - //sdl_scrn = surface; - SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - + //glOrtho(0, (XRES+BARSIZE)*sdl_scale, 0, (YRES+MENUSIZE)*sdl_scale, -1, 1); glOrtho(0, (XRES+BARSIZE)*sdl_scale, (YRES+MENUSIZE)*sdl_scale, 0, -1, 1); - + glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - - + + //glRasterPos2i(0, (YRES+MENUSIZE)); glRasterPos2i(0, 0); glPixelZoom(1, 1); - + glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - + //Texture for main UI glEnable(GL_TEXTURE_2D); - + glGenTextures(1, &vidBuf); glBindTexture(GL_TEXTURE_2D, vidBuf); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, XRES+BARSIZE, YRES+MENUSIZE, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); - + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); - + glBindTexture(GL_TEXTURE_2D, 0); - + glGenTextures(1, &textTexture); glBindTexture(GL_TEXTURE_2D, textTexture); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - + glBindTexture(GL_TEXTURE_2D, 0); - + glDisable(GL_TEXTURE_2D); } -void Graphics::Blit() +Graphics::~Graphics() { - //glDrawPixels(w,h,GL_BGRA,GL_UNSIGNED_BYTE,src); //Why does this still think it's ABGR? - /*glEnable( GL_TEXTURE_2D ); - glBindTexture(GL_TEXTURE_2D, vidBuf); - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES+BARSIZE, YRES+MENUSIZE, GL_BGRA, GL_UNSIGNED_BYTE, vid); - glBegin(GL_QUADS); - glTexCoord2d(1, 0); - glVertex3f((XRES+BARSIZE)*sdl_scale, (YRES+MENUSIZE)*sdl_scale, 1.0); - glTexCoord2d(0, 0); - glVertex3f(0, (YRES+MENUSIZE)*sdl_scale, 1.0); - glTexCoord2d(0, 1); - glVertex3f(0, 0, 1.0); - glTexCoord2d(1, 1); - glVertex3f((XRES+BARSIZE)*sdl_scale, 0, 1.0); - glEnd(); +} + +void Graphics::Clear() +{ + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); +} - glDisable( GL_TEXTURE_2D );*/ +void Graphics::Finalise() +{ glFlush(); - SDL_GL_SwapBuffers (); } int Graphics::drawtext(int x, int y, const char *s, int r, int g, int b, int a) diff --git a/src/PowderToy.cpp b/src/PowderToySDL.cpp index 7e3b534..8ec1abd 100644 --- a/src/PowderToy.cpp +++ b/src/PowderToySDL.cpp @@ -33,6 +33,38 @@ using namespace std; extern "C" IMAGE_DOS_HEADER __ImageBase; #endif +SDL_Surface * sdl_scrn; + +#ifdef OGLR +void blit() +{ + SDL_GL_SwapBuffers(); +} +#else +void blit(pixel * vid) +{ + if(sdl_scrn) + { + pixel * dst; + pixel * src = vid; + int j, x = 0, y = 0, w = XRES+BARSIZE, h = YRES+MENUSIZE, pitch = XRES+BARSIZE; + if (SDL_MUSTLOCK(sdl_scrn)) + if (SDL_LockSurface(sdl_scrn)<0) + return; + dst=(pixel *)sdl_scrn->pixels+y*sdl_scrn->pitch/PIXELSIZE+x; + for (j=0; j<h; j++) + { + memcpy(dst, src, w*PIXELSIZE); + dst+=sdl_scrn->pitch/PIXELSIZE; + src+=pitch; + } + if (SDL_MUSTLOCK(sdl_scrn)) + SDL_UnlockSurface(sdl_scrn); + SDL_UpdateRect(sdl_scrn,0,0,0,0); + } +#endif +} + SDL_Surface * SDLOpen() { SDL_Surface * surface; @@ -93,26 +125,18 @@ SDL_Surface * SDLOpen() return surface; } -/*int SDLPoll(SDL_Event * event) -{ - while (SDL_PollEvent(event)) - { - switch (event->type) - { - case SDL_QUIT: - return 1; - } - } - return 0; -}*/ - int main(int argc, char * argv[]) { int elapsedTime = 0, currentTime = 0, lastTime = 0, currentFrame = 0; float fps = 0, delta = 1.0f; + sdl_scrn = SDLOpen(); +#ifdef OGLR + SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); +#endif + ui::Engine::Ref().g = new Graphics(); - ui::Engine::Ref().g->AttachSDLSurface(SDLOpen()); + //ui::Engine::Ref().g->AttachSDLSurface(SDLOpen()); ui::Engine * engine = &ui::Engine::Ref(); engine->Begin(XRES+BARSIZE, YRES+MENUSIZE); @@ -166,6 +190,12 @@ int main(int argc, char * argv[]) engine->Tick(); engine->Draw(); + +#ifdef OGLR + blit(); +#else + blit(engine->g->vid); +#endif currentFrame++; currentTime = SDL_GetTicks(); diff --git a/src/RasterGraphics.cpp b/src/RasterGraphics.cpp index 563aef2..b807238 100644 --- a/src/RasterGraphics.cpp +++ b/src/RasterGraphics.cpp @@ -20,32 +20,9 @@ void Graphics::Clear() memset(vid, 0, PIXELSIZE * ((XRES+BARSIZE) * (YRES+MENUSIZE))); } -void Graphics::AttachSDLSurface(SDL_Surface * surface) +void Graphics::Finalise() { - sdl_scrn = surface; -} -void Graphics::Blit() -{ - if(sdl_scrn) - { - pixel * dst; - pixel * src = vid; - int j, x = 0, y = 0, w = XRES+BARSIZE, h = YRES+MENUSIZE, pitch = XRES+BARSIZE; - if (SDL_MUSTLOCK(sdl_scrn)) - if (SDL_LockSurface(sdl_scrn)<0) - return; - dst=(pixel *)sdl_scrn->pixels+y*sdl_scrn->pitch/PIXELSIZE+x; - for (j=0; j<h; j++) - { - memcpy(dst, src, w*PIXELSIZE); - dst+=sdl_scrn->pitch/PIXELSIZE; - src+=pitch; - } - if (SDL_MUSTLOCK(sdl_scrn)) - SDL_UnlockSurface(sdl_scrn); - SDL_UpdateRect(sdl_scrn,0,0,0,0); - } } int Graphics::drawtext(int x, int y, const char *s, int r, int g, int b, int a) diff --git a/src/interface/Engine.cpp b/src/interface/Engine.cpp index aea89e7..1304284 100644 --- a/src/interface/Engine.cpp +++ b/src/interface/Engine.cpp @@ -184,7 +184,7 @@ void Engine::Draw() char fpsText[512]; sprintf(fpsText, "FPS: %.2f, Delta: %.3f", fps, dt); ui::Engine::Ref().g->drawtext(10, 10, fpsText, 255, 255, 255, 255); - g->Blit(); + g->Finalise(); } void Engine::SetFps(float fps) |
