Browse Source

Create a helper class for easy scene setup. Highly reduces the number

of includes in a few source files.
legacy
Sam Hocevar sam 14 years ago
parent
commit
9112d94d19
11 changed files with 89 additions and 109 deletions
  1. +2
    -1
      src/Makefile.am
  2. +0
    -3
      src/gtk/editor.cpp
  3. +6
    -49
      src/gtk/gtkvideo.cpp
  4. +5
    -9
      src/gtk/gtkvideo.h
  5. +3
    -31
      src/sdlvideo.cpp
  6. +7
    -9
      src/sdlvideo.h
  7. +1
    -1
      src/test-map.cpp
  8. +5
    -0
      src/tileset.cpp
  9. +3
    -0
      src/tileset.h
  10. +54
    -0
      src/video.cpp
  11. +3
    -6
      src/video.h

+ 2
- 1
src/Makefile.am View File

@@ -6,7 +6,8 @@ noinst_LIBRARIES = libcommon.a
libcommon_a_SOURCES = \
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 \
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`

test_map_SOURCES = test-map.cpp sdlvideo.cpp sdlvideo.h sdlinput.cpp sdlinput.h


+ 0
- 3
src/gtk/editor.cpp View File

@@ -10,11 +10,8 @@
#include <cstdio>
#include <cmath>

#include <SDL.h>

#include <gtk/gtk.h>
#include <gtkgl/gtkglarea.h>
#include <GL/gl.h>

#include "gtkvideo.h"
#include "ticker.h"


+ 6
- 49
src/gtk/gtkvideo.cpp View File

@@ -12,18 +12,8 @@
#include <gtk/gtk.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 "video.h"

/*
* Gtk Video implementation class
@@ -34,30 +24,6 @@ class GtkVideoData
friend class GtkVideo;

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)
{
GtkVideoData *data = (GtkVideoData *)
@@ -66,7 +32,8 @@ private:
/* OpenGL functions can be called only if make_current returns true */
if (gtk_gl_area_make_current(GTK_GL_AREA(widget)))
{
data->SetupView();
Video::Setup(widget->allocation.width,
widget->allocation.height);
}
return TRUE;
}
@@ -95,7 +62,8 @@ private:

if (gtk_gl_area_make_current(GTK_GL_AREA(widget)))
{
data->SetupView();
Video::Setup(widget->allocation.width,
widget->allocation.height);
}
return TRUE;
}
@@ -167,8 +135,7 @@ void GtkVideo::PreRender()
/// XXX: is this right?
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;
}
@@ -189,13 +156,3 @@ void GtkVideo::PostRender(float milliseconds)
#endif
}

void GtkVideo::FullScreen()
{
// FIXME
}

GtkVideo::~GtkVideo()
{
// FIXME
}


+ 5
- 9
src/gtk/gtkvideo.h View File

@@ -11,22 +11,18 @@
#if !defined __DH_GTKVIDEO_H__
#define __DH_GTKVIDEO_H__

#include "video.h"

class GtkVideoData;

class GtkVideo : public Video
class GtkVideo
{
public:
GtkVideo(char const *title, int width, int height);
virtual ~GtkVideo();

// 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
void *GetWidget();


+ 3
- 31
src/sdlvideo.cpp View File

@@ -7,20 +7,10 @@
# 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 <SDL.h>

#include "sdlvideo.h"
#include "video.h"

/*
* SDL Video implementation class
@@ -63,24 +53,7 @@ SdlVideo::SdlVideo(char const *title, int width, int height)
SDL_ShowCursor(0);
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 */
data->start = data->ticks = SDL_GetTicks();
@@ -99,8 +72,7 @@ int SdlVideo::GetHeight() const

void SdlVideo::PreRender()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
Video::Clear();
}

void SdlVideo::PostRender(float milliseconds)


+ 7
- 9
src/sdlvideo.h View File

@@ -11,21 +11,19 @@
#if !defined __DH_SDLVIDEO_H__
#define __DH_SDLVIDEO_H__

#include "video.h"

class SdlVideoData;

class SdlVideo : public Video
class SdlVideo
{
public:
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:
SdlVideoData *data;


+ 1
- 1
src/test-map.cpp View File

@@ -19,7 +19,7 @@

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");

/* Register the input driver */


+ 5
- 0
src/tileset.cpp View File

@@ -73,6 +73,11 @@ TileSet::~TileSet()
delete data;
}

Asset::Group TileSet::GetGroup()
{
return GROUP_BEFORE;
}

void TileSet::TickRender(float delta_time)
{
Asset::TickRender(delta_time);


+ 3
- 0
src/tileset.h View File

@@ -26,9 +26,12 @@ public:
TileSet(char const *path);
virtual ~TileSet();

protected:
/* Inherited from Asset */
virtual Group GetGroup();
virtual void TickRender(float delta_time);

public:
/* New implementations */
char const *GetName();



+ 54
- 0
src/video.cpp View File

@@ -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();
}


+ 3
- 6
src/video.h View File

@@ -6,7 +6,7 @@
//
// The Video interface
// -------------------
// Not sure yet whether this should exist.
// Helper GL functions to set up the scene.
//

#if !defined __DH_VIDEO_H__
@@ -15,11 +15,8 @@
class Video
{
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__


Loading…
Cancel
Save