source: trunk/src/test-map.cpp @ 206

Last change on this file since 206 was 206, checked in by sam, 10 years ago

Activate depth buffer when the GL context is created.

  • Property svn:keywords set to Id
File size: 1.7 KB
Line 
1//
2// Deus Hax (working title)
3// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
4//
5
6#if defined HAVE_CONFIG_H
7#   include "config.h"
8#endif
9
10#include <cstdio>
11#include <cmath>
12
13#include <SDL.h>
14
15#include "core.h"
16#include "sdlinput.h"
17#include "debugfps.h"
18#include "debugsprite.h"
19#include "debugrecord.h"
20#include "debugstats.h"
21
22static float const FPS = 30.0f;
23
24int main(int argc, char **argv)
25{
26    /* Initialise SDL */
27    if (SDL_Init(SDL_INIT_VIDEO) < 0)
28    {
29        fprintf(stderr, "Cannot initialise SDL: %s\n", SDL_GetError());
30        return EXIT_FAILURE;
31    }
32
33    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
34    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
35    SDL_Surface *video = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
36    if (!video)
37    {
38        fprintf(stderr, "Cannot create OpenGL screen: %s\n", SDL_GetError());
39        SDL_Quit();
40        return EXIT_FAILURE;
41    }
42
43    SDL_WM_SetCaption("Map Test (SDL)", NULL);
44    SDL_ShowCursor(0);
45    //SDL_WM_GrabInput(SDL_GRAB_ON);
46
47    /* Initialise OpenGL */
48    Video::Setup(video->w, video->h);
49
50    /* Create a game */
51    Game *game = new Game("maps/testmap2.tmx");
52
53    /* Register an input driver and some debug stuff */
54    new SdlInput();
55    new DebugFps();
56    new DebugSprite(game);
57    //new DebugRecord("lolengine.ogg");
58    new DebugStats("stats.txt");
59
60    while (!Ticker::Finished())
61    {
62        /* Tick the game */
63        Ticker::TickGame();
64
65        /* Clear the screen, tick the renderer, show the frame and
66         * clamp to desired framerate. */
67        Video::Clear();
68        Ticker::TickDraw();
69        SDL_GL_SwapBuffers();
70        Ticker::ClampFps(1000.0f / FPS);
71    }
72
73    SDL_Quit();
74
75    return EXIT_SUCCESS;
76}
77
Note: See TracBrowser for help on using the repository browser.