of includes in a few source files.legacy
| @@ -6,7 +6,8 @@ noinst_LIBRARIES = libcommon.a | |||||
| libcommon_a_SOURCES = \ | libcommon_a_SOURCES = \ | ||||
| game.cpp game.h tiler.cpp tiler.h tileset.cpp tileset.h \ | game.cpp game.h tiler.cpp tiler.h tileset.cpp tileset.h \ | ||||
| scene.cpp scene.h font.cpp font.h layer.cpp layer.h map.cpp map.h \ | scene.cpp scene.h font.cpp font.h layer.cpp layer.h map.cpp map.h \ | ||||
| joystick.cpp joystick.h asset.cpp asset.h ticker.cpp ticker.h | |||||
| joystick.cpp joystick.h asset.cpp asset.h ticker.cpp ticker.h \ | |||||
| video.cpp video.h | |||||
| libcommon_a_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image` | libcommon_a_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image` | ||||
| test_map_SOURCES = test-map.cpp sdlvideo.cpp sdlvideo.h sdlinput.cpp sdlinput.h | test_map_SOURCES = test-map.cpp sdlvideo.cpp sdlvideo.h sdlinput.cpp sdlinput.h | ||||
| @@ -10,11 +10,8 @@ | |||||
| #include <cstdio> | #include <cstdio> | ||||
| #include <cmath> | #include <cmath> | ||||
| #include <SDL.h> | |||||
| #include <gtk/gtk.h> | #include <gtk/gtk.h> | ||||
| #include <gtkgl/gtkglarea.h> | #include <gtkgl/gtkglarea.h> | ||||
| #include <GL/gl.h> | |||||
| #include "gtkvideo.h" | #include "gtkvideo.h" | ||||
| #include "ticker.h" | #include "ticker.h" | ||||
| @@ -12,18 +12,8 @@ | |||||
| #include <gtk/gtk.h> | #include <gtk/gtk.h> | ||||
| #include <gtkgl/gtkglarea.h> | #include <gtkgl/gtkglarea.h> | ||||
| #ifdef WIN32 | |||||
| # define WIN32_LEAN_AND_MEAN | |||||
| # include <windows.h> | |||||
| #endif | |||||
| #if defined __APPLE__ && defined __MACH__ | |||||
| # include <OpenGL/gl.h> | |||||
| #else | |||||
| # define GL_GLEXT_PROTOTYPES | |||||
| # include <GL/gl.h> | |||||
| #endif | |||||
| #include "gtkvideo.h" | #include "gtkvideo.h" | ||||
| #include "video.h" | |||||
| /* | /* | ||||
| * Gtk Video implementation class | * Gtk Video implementation class | ||||
| @@ -34,30 +24,6 @@ class GtkVideoData | |||||
| friend class GtkVideo; | friend class GtkVideo; | ||||
| private: | private: | ||||
| void SetupView() | |||||
| { | |||||
| glViewport(0, 0, widget->allocation.width, | |||||
| widget->allocation.height); | |||||
| glMatrixMode(GL_PROJECTION); | |||||
| glLoadIdentity(); | |||||
| glOrtho(0, widget->allocation.width, | |||||
| widget->allocation.height, 0, -1, 10); | |||||
| glMatrixMode(GL_MODELVIEW); | |||||
| glLoadIdentity(); | |||||
| glEnable(GL_TEXTURE_2D); | |||||
| glShadeModel(GL_SMOOTH); | |||||
| glClearColor(0.0f, 0.0f, 0.0f, 0.0f); | |||||
| glClearDepth(1.0); | |||||
| glEnable(GL_DEPTH_TEST); | |||||
| glDepthFunc(GL_LEQUAL); | |||||
| glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); | |||||
| glEnable(GL_BLEND); | |||||
| glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |||||
| } | |||||
| static gint init(GtkWidget *widget) | static gint init(GtkWidget *widget) | ||||
| { | { | ||||
| GtkVideoData *data = (GtkVideoData *) | GtkVideoData *data = (GtkVideoData *) | ||||
| @@ -66,7 +32,8 @@ private: | |||||
| /* OpenGL functions can be called only if make_current returns true */ | /* OpenGL functions can be called only if make_current returns true */ | ||||
| if (gtk_gl_area_make_current(GTK_GL_AREA(widget))) | if (gtk_gl_area_make_current(GTK_GL_AREA(widget))) | ||||
| { | { | ||||
| data->SetupView(); | |||||
| Video::Setup(widget->allocation.width, | |||||
| widget->allocation.height); | |||||
| } | } | ||||
| return TRUE; | return TRUE; | ||||
| } | } | ||||
| @@ -95,7 +62,8 @@ private: | |||||
| if (gtk_gl_area_make_current(GTK_GL_AREA(widget))) | if (gtk_gl_area_make_current(GTK_GL_AREA(widget))) | ||||
| { | { | ||||
| data->SetupView(); | |||||
| Video::Setup(widget->allocation.width, | |||||
| widget->allocation.height); | |||||
| } | } | ||||
| return TRUE; | return TRUE; | ||||
| } | } | ||||
| @@ -167,8 +135,7 @@ void GtkVideo::PreRender() | |||||
| /// XXX: is this right? | /// XXX: is this right? | ||||
| gtk_gl_area_make_current(GTK_GL_AREA(data->widget)); | gtk_gl_area_make_current(GTK_GL_AREA(data->widget)); | ||||
| glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||||
| glLoadIdentity(); | |||||
| Video::Clear(); | |||||
| data->drawing = 1; | data->drawing = 1; | ||||
| } | } | ||||
| @@ -189,13 +156,3 @@ void GtkVideo::PostRender(float milliseconds) | |||||
| #endif | #endif | ||||
| } | } | ||||
| void GtkVideo::FullScreen() | |||||
| { | |||||
| // FIXME | |||||
| } | |||||
| GtkVideo::~GtkVideo() | |||||
| { | |||||
| // FIXME | |||||
| } | |||||
| @@ -11,22 +11,18 @@ | |||||
| #if !defined __DH_GTKVIDEO_H__ | #if !defined __DH_GTKVIDEO_H__ | ||||
| #define __DH_GTKVIDEO_H__ | #define __DH_GTKVIDEO_H__ | ||||
| #include "video.h" | |||||
| class GtkVideoData; | class GtkVideoData; | ||||
| class GtkVideo : public Video | |||||
| class GtkVideo | |||||
| { | { | ||||
| public: | public: | ||||
| GtkVideo(char const *title, int width, int height); | GtkVideo(char const *title, int width, int height); | ||||
| virtual ~GtkVideo(); | |||||
| // Inherited | // Inherited | ||||
| virtual int GetWidth() const; | |||||
| virtual int GetHeight() const; | |||||
| virtual void PreRender(); | |||||
| virtual void PostRender(float milliseconds); | |||||
| virtual void FullScreen(); | |||||
| int GetWidth() const; | |||||
| int GetHeight() const; | |||||
| void PreRender(); | |||||
| void PostRender(float milliseconds); | |||||
| // New | // New | ||||
| void *GetWidget(); | void *GetWidget(); | ||||
| @@ -7,20 +7,10 @@ | |||||
| # include "config.h" | # include "config.h" | ||||
| #endif | #endif | ||||
| #ifdef WIN32 | |||||
| # define WIN32_LEAN_AND_MEAN | |||||
| # include <windows.h> | |||||
| #endif | |||||
| #if defined __APPLE__ && defined __MACH__ | |||||
| # include <OpenGL/gl.h> | |||||
| #else | |||||
| # define GL_GLEXT_PROTOTYPES | |||||
| # include <GL/gl.h> | |||||
| #endif | |||||
| #include <SDL.h> | #include <SDL.h> | ||||
| #include "sdlvideo.h" | #include "sdlvideo.h" | ||||
| #include "video.h" | |||||
| /* | /* | ||||
| * SDL Video implementation class | * SDL Video implementation class | ||||
| @@ -63,24 +53,7 @@ SdlVideo::SdlVideo(char const *title, int width, int height) | |||||
| SDL_ShowCursor(0); | SDL_ShowCursor(0); | ||||
| SDL_WM_GrabInput(SDL_GRAB_ON); | SDL_WM_GrabInput(SDL_GRAB_ON); | ||||
| /* Initialise OpenGL */ | |||||
| glViewport(0, 0, data->video->w, data->video->h); | |||||
| glMatrixMode(GL_PROJECTION); | |||||
| glLoadIdentity(); | |||||
| glOrtho(0, data->video->w, data->video->h, 0, -1, 10); | |||||
| glMatrixMode(GL_MODELVIEW); | |||||
| glLoadIdentity(); | |||||
| glEnable(GL_TEXTURE_2D); | |||||
| glShadeModel(GL_SMOOTH); | |||||
| glClearColor(0.0f, 0.0f, 0.0f, 0.0f); | |||||
| glClearDepth(1.0); | |||||
| glEnable(GL_DEPTH_TEST); | |||||
| glDepthFunc(GL_LEQUAL); | |||||
| glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); | |||||
| glEnable(GL_BLEND); | |||||
| glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |||||
| Video::Setup(data->video->w, data->video->h); | |||||
| /* Initialise timer */ | /* Initialise timer */ | ||||
| data->start = data->ticks = SDL_GetTicks(); | data->start = data->ticks = SDL_GetTicks(); | ||||
| @@ -99,8 +72,7 @@ int SdlVideo::GetHeight() const | |||||
| void SdlVideo::PreRender() | void SdlVideo::PreRender() | ||||
| { | { | ||||
| glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||||
| glLoadIdentity(); | |||||
| Video::Clear(); | |||||
| } | } | ||||
| void SdlVideo::PostRender(float milliseconds) | void SdlVideo::PostRender(float milliseconds) | ||||
| @@ -11,21 +11,19 @@ | |||||
| #if !defined __DH_SDLVIDEO_H__ | #if !defined __DH_SDLVIDEO_H__ | ||||
| #define __DH_SDLVIDEO_H__ | #define __DH_SDLVIDEO_H__ | ||||
| #include "video.h" | |||||
| class SdlVideoData; | class SdlVideoData; | ||||
| class SdlVideo : public Video | |||||
| class SdlVideo | |||||
| { | { | ||||
| public: | public: | ||||
| SdlVideo(char const *title, int width, int height); | SdlVideo(char const *title, int width, int height); | ||||
| virtual ~SdlVideo(); | |||||
| ~SdlVideo(); | |||||
| virtual int GetWidth() const; | |||||
| virtual int GetHeight() const; | |||||
| virtual void PreRender(); | |||||
| virtual void PostRender(float milliseconds); | |||||
| virtual void FullScreen(); | |||||
| int GetWidth() const; | |||||
| int GetHeight() const; | |||||
| void PreRender(); | |||||
| void PostRender(float milliseconds); | |||||
| void FullScreen(); | |||||
| private: | private: | ||||
| SdlVideoData *data; | SdlVideoData *data; | ||||
| @@ -19,7 +19,7 @@ | |||||
| int main(int argc, char **argv) | int main(int argc, char **argv) | ||||
| { | { | ||||
| Video *video = new SdlVideo("Deus Hax", 640, 480); | |||||
| SdlVideo *video = new SdlVideo("Deus Hax", 640, 480); | |||||
| Game *game = new Game("maps/testmap.tmx"); | Game *game = new Game("maps/testmap.tmx"); | ||||
| /* Register the input driver */ | /* Register the input driver */ | ||||
| @@ -73,6 +73,11 @@ TileSet::~TileSet() | |||||
| delete data; | delete data; | ||||
| } | } | ||||
| Asset::Group TileSet::GetGroup() | |||||
| { | |||||
| return GROUP_BEFORE; | |||||
| } | |||||
| void TileSet::TickRender(float delta_time) | void TileSet::TickRender(float delta_time) | ||||
| { | { | ||||
| Asset::TickRender(delta_time); | Asset::TickRender(delta_time); | ||||
| @@ -26,9 +26,12 @@ public: | |||||
| TileSet(char const *path); | TileSet(char const *path); | ||||
| virtual ~TileSet(); | virtual ~TileSet(); | ||||
| protected: | |||||
| /* Inherited from Asset */ | /* Inherited from Asset */ | ||||
| virtual Group GetGroup(); | |||||
| virtual void TickRender(float delta_time); | virtual void TickRender(float delta_time); | ||||
| public: | |||||
| /* New implementations */ | /* New implementations */ | ||||
| char const *GetName(); | char const *GetName(); | ||||
| @@ -0,0 +1,54 @@ | |||||
| // | |||||
| // Deus Hax (working title) | |||||
| // Copyright (c) 2010 Sam Hocevar <sam@hocevar.net> | |||||
| // | |||||
| #if defined HAVE_CONFIG_H | |||||
| # include "config.h" | |||||
| #endif | |||||
| #ifdef WIN32 | |||||
| # define WIN32_LEAN_AND_MEAN | |||||
| # include <windows.h> | |||||
| #endif | |||||
| #if defined __APPLE__ && defined __MACH__ | |||||
| # include <OpenGL/gl.h> | |||||
| #else | |||||
| # define GL_GLEXT_PROTOTYPES | |||||
| # include <GL/gl.h> | |||||
| #endif | |||||
| #include "video.h" | |||||
| /* | |||||
| * Public Video class | |||||
| */ | |||||
| void Video::Setup(int width, int height) | |||||
| { | |||||
| /* Initialise OpenGL */ | |||||
| glViewport(0, 0, width, height); | |||||
| glMatrixMode(GL_PROJECTION); | |||||
| glLoadIdentity(); | |||||
| glOrtho(0, width, height, 0, -1, 10); | |||||
| glMatrixMode(GL_MODELVIEW); | |||||
| glLoadIdentity(); | |||||
| glEnable(GL_TEXTURE_2D); | |||||
| glShadeModel(GL_SMOOTH); | |||||
| glClearColor(0.0f, 0.0f, 0.0f, 0.0f); | |||||
| glClearDepth(1.0); | |||||
| glEnable(GL_DEPTH_TEST); | |||||
| glDepthFunc(GL_LEQUAL); | |||||
| glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); | |||||
| glEnable(GL_BLEND); | |||||
| glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |||||
| } | |||||
| void Video::Clear() | |||||
| { | |||||
| glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||||
| glLoadIdentity(); | |||||
| } | |||||
| @@ -6,7 +6,7 @@ | |||||
| // | // | ||||
| // The Video interface | // The Video interface | ||||
| // ------------------- | // ------------------- | ||||
| // Not sure yet whether this should exist. | |||||
| // Helper GL functions to set up the scene. | |||||
| // | // | ||||
| #if !defined __DH_VIDEO_H__ | #if !defined __DH_VIDEO_H__ | ||||
| @@ -15,11 +15,8 @@ | |||||
| class Video | class Video | ||||
| { | { | ||||
| public: | public: | ||||
| virtual int GetWidth() const = 0; | |||||
| virtual int GetHeight() const = 0; | |||||
| virtual void PreRender() = 0; | |||||
| virtual void PostRender(float milliseconds) = 0; | |||||
| virtual void FullScreen() = 0; | |||||
| static void Setup(int width, int height); | |||||
| static void Clear(); | |||||
| }; | }; | ||||
| #endif // __DH_VIDEO_H__ | #endif // __DH_VIDEO_H__ | ||||