Changeset 105


Ignore:
Timestamp:
Aug 14, 2010, 11:15:38 PM (10 years ago)
Author:
sam
Message:

Create a helper class for easy scene setup. Highly reduces the number
of includes in a few source files.

Location:
trunk/src
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.am

    r103 r105  
    77    game.cpp game.h tiler.cpp tiler.h tileset.cpp tileset.h \
    88    scene.cpp scene.h font.cpp font.h layer.cpp layer.h map.cpp map.h \
    9     joystick.cpp joystick.h asset.cpp asset.h ticker.cpp ticker.h
     9    joystick.cpp joystick.h asset.cpp asset.h ticker.cpp ticker.h \
     10    video.cpp video.h
    1011libcommon_a_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image`
    1112
  • trunk/src/gtk/editor.cpp

    r100 r105  
    1111#include <cmath>
    1212
    13 #include <SDL.h>
    14 
    1513#include <gtk/gtk.h>
    1614#include <gtkgl/gtkglarea.h>
    17 #include <GL/gl.h>
    1815
    1916#include "gtkvideo.h"
  • trunk/src/gtk/gtkvideo.cpp

    r100 r105  
    1313#include <gtkgl/gtkglarea.h>
    1414
    15 #ifdef WIN32
    16 #   define WIN32_LEAN_AND_MEAN
    17 #   include <windows.h>
    18 #endif
    19 #if defined __APPLE__ && defined __MACH__
    20 #   include <OpenGL/gl.h>
    21 #else
    22 #   define GL_GLEXT_PROTOTYPES
    23 #   include <GL/gl.h>
    24 #endif
    25 
    2615#include "gtkvideo.h"
     16#include "video.h"
    2717
    2818/*
     
    3525
    3626private:
    37     void SetupView()
    38     {
    39         glViewport(0, 0, widget->allocation.width,
    40                          widget->allocation.height);
    41 
    42         glMatrixMode(GL_PROJECTION);
    43         glLoadIdentity();
    44         glOrtho(0, widget->allocation.width,
    45                    widget->allocation.height, 0, -1, 10);
    46         glMatrixMode(GL_MODELVIEW);
    47         glLoadIdentity();
    48 
    49         glEnable(GL_TEXTURE_2D);
    50         glShadeModel(GL_SMOOTH);
    51         glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    52         glClearDepth(1.0);
    53         glEnable(GL_DEPTH_TEST);
    54         glDepthFunc(GL_LEQUAL);
    55         glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    56 
    57         glEnable(GL_BLEND);
    58         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    59     }
    60 
    6127    static gint init(GtkWidget *widget)
    6228    {
     
    6733        if (gtk_gl_area_make_current(GTK_GL_AREA(widget)))
    6834        {
    69             data->SetupView();
     35            Video::Setup(widget->allocation.width,
     36                         widget->allocation.height);
    7037        }
    7138        return TRUE;
     
    9663        if (gtk_gl_area_make_current(GTK_GL_AREA(widget)))
    9764        {
    98             data->SetupView();
     65            Video::Setup(widget->allocation.width,
     66                         widget->allocation.height);
    9967        }
    10068        return TRUE;
     
    168136    gtk_gl_area_make_current(GTK_GL_AREA(data->widget));
    169137
    170     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    171     glLoadIdentity();
     138    Video::Clear();
    172139
    173140    data->drawing = 1;
     
    190157}
    191158
    192 void GtkVideo::FullScreen()
    193 {
    194     // FIXME
    195 }
    196 
    197 GtkVideo::~GtkVideo()
    198 {
    199     // FIXME
    200 }
    201 
  • trunk/src/gtk/gtkvideo.h

    r100 r105  
    1212#define __DH_GTKVIDEO_H__
    1313
    14 #include "video.h"
    15 
    1614class GtkVideoData;
    1715
    18 class GtkVideo : public Video
     16class GtkVideo
    1917{
    2018public:
    2119    GtkVideo(char const *title, int width, int height);
    22     virtual ~GtkVideo();
    2320
    2421    // Inherited
    25     virtual int GetWidth() const;
    26     virtual int GetHeight() const;
    27     virtual void PreRender();
    28     virtual void PostRender(float milliseconds);
    29     virtual void FullScreen();
     22    int GetWidth() const;
     23    int GetHeight() const;
     24    void PreRender();
     25    void PostRender(float milliseconds);
    3026
    3127    // New
  • trunk/src/sdlvideo.cpp

    r100 r105  
    88#endif
    99
    10 #ifdef WIN32
    11 #   define WIN32_LEAN_AND_MEAN
    12 #   include <windows.h>
    13 #endif
    14 #if defined __APPLE__ && defined __MACH__
    15 #   include <OpenGL/gl.h>
    16 #else
    17 #   define GL_GLEXT_PROTOTYPES
    18 #   include <GL/gl.h>
    19 #endif
    20 
    2110#include <SDL.h>
    2211
    2312#include "sdlvideo.h"
     13#include "video.h"
    2414
    2515/*
     
    6454    SDL_WM_GrabInput(SDL_GRAB_ON);
    6555
    66     /* Initialise OpenGL */
    67     glViewport(0, 0, data->video->w, data->video->h);
    68     glMatrixMode(GL_PROJECTION);
    69     glLoadIdentity();
    70     glOrtho(0, data->video->w, data->video->h, 0, -1, 10);
    71     glMatrixMode(GL_MODELVIEW);
    72     glLoadIdentity();
    73 
    74     glEnable(GL_TEXTURE_2D);
    75     glShadeModel(GL_SMOOTH);
    76     glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    77     glClearDepth(1.0);
    78     glEnable(GL_DEPTH_TEST);
    79     glDepthFunc(GL_LEQUAL);
    80     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    81 
    82     glEnable(GL_BLEND);
    83     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     56    Video::Setup(data->video->w, data->video->h);
    8457
    8558    /* Initialise timer */
     
    10073void SdlVideo::PreRender()
    10174{
    102     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    103     glLoadIdentity();
     75    Video::Clear();
    10476}
    10577
  • trunk/src/sdlvideo.h

    r100 r105  
    1212#define __DH_SDLVIDEO_H__
    1313
    14 #include "video.h"
    15 
    1614class SdlVideoData;
    1715
    18 class SdlVideo : public Video
     16class SdlVideo
    1917{
    2018public:
    2119    SdlVideo(char const *title, int width, int height);
    22     virtual ~SdlVideo();
     20    ~SdlVideo();
    2321
    24     virtual int GetWidth() const;
    25     virtual int GetHeight() const;
    26     virtual void PreRender();
    27     virtual void PostRender(float milliseconds);
    28     virtual void FullScreen();
     22    int GetWidth() const;
     23    int GetHeight() const;
     24    void PreRender();
     25    void PostRender(float milliseconds);
     26    void FullScreen();
    2927
    3028private:
  • trunk/src/test-map.cpp

    r103 r105  
    2020int main(int argc, char **argv)
    2121{
    22     Video *video = new SdlVideo("Deus Hax", 640, 480);
     22    SdlVideo *video = new SdlVideo("Deus Hax", 640, 480);
    2323    Game *game = new Game("maps/testmap.tmx");
    2424
  • trunk/src/tileset.cpp

    r100 r105  
    7474}
    7575
     76Asset::Group TileSet::GetGroup()
     77{
     78    return GROUP_BEFORE;
     79}
     80
    7681void TileSet::TickRender(float delta_time)
    7782{
  • trunk/src/tileset.h

    r104 r105  
    2727    virtual ~TileSet();
    2828
     29protected:
    2930    /* Inherited from Asset */
     31    virtual Group GetGroup();
    3032    virtual void TickRender(float delta_time);
    3133
     34public:
    3235    /* New implementations */
    3336    char const *GetName();
  • trunk/src/video.h

    r100 r105  
    77// The Video interface
    88// -------------------
    9 // Not sure yet whether this should exist.
     9// Helper GL functions to set up the scene.
    1010//
    1111
     
    1616{
    1717public:
    18     virtual int GetWidth() const = 0;
    19     virtual int GetHeight() const = 0;
    20     virtual void PreRender() = 0;
    21     virtual void PostRender(float milliseconds) = 0;
    22     virtual void FullScreen() = 0;
     18    static void Setup(int width, int height);
     19    static void Clear();
    2320};
    2421
Note: See TracChangeset for help on using the changeset viewer.