source: trunk/src/sdlvideo.cpp @ 107

Last change on this file since 107 was 107, checked in by sam, 11 years ago

Remove dead code from the soon to be deprecated Video classes.

  • 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 <SDL.h>
11
12#include "sdlvideo.h"
13#include "video.h"
14
15/*
16 * SDL Video implementation class
17 */
18
19class SdlVideoData
20{
21    friend class SdlVideo;
22
23private:
24    SDL_Surface *video;
25    Uint32 start, ticks;
26    int frames;
27};
28
29/*
30 * Public SdlVideo class
31 */
32
33SdlVideo::SdlVideo(char const *title, int width, int height)
34{
35    data = new SdlVideoData();
36
37    /* Initialise SDL */
38    if (SDL_Init(SDL_INIT_VIDEO) < 0)
39    {
40        fprintf(stderr, "Cannot initialise SDL: %s\n", SDL_GetError());
41        exit(EXIT_FAILURE);
42    }
43
44    data->video = SDL_SetVideoMode(width, height, 0, SDL_OPENGL);
45    if (!data->video)
46    {
47        fprintf(stderr, "Cannot create OpenGL screen: %s\n", SDL_GetError());
48        SDL_Quit();
49        exit(EXIT_FAILURE);
50    }
51
52    SDL_WM_SetCaption(title, NULL);
53    SDL_ShowCursor(0);
54    SDL_WM_GrabInput(SDL_GRAB_ON);
55
56    Video::Setup(data->video->w, data->video->h);
57
58    /* Initialise timer */
59    data->start = data->ticks = SDL_GetTicks();
60    data->frames = 0;
61}
62
63void SdlVideo::PreRender()
64{
65    Video::Clear();
66}
67
68void SdlVideo::PostRender(float milliseconds)
69{
70    if (milliseconds > 0.0f)
71        while (SDL_GetTicks() < data->ticks + (milliseconds - 0.5f))
72            SDL_Delay(1);
73    data->ticks = SDL_GetTicks();
74    data->frames++;
75
76    SDL_GL_SwapBuffers();
77}
78
79void SdlVideo::FullScreen()
80{
81    SDL_WM_ToggleFullScreen(data->video);
82}
83
84SdlVideo::~SdlVideo()
85{
86    Uint32 total = SDL_GetTicks() - data->start;
87    printf("%f fps\n", 1000.0f * data->frames / total);
88    SDL_Quit();
89    delete data;
90}
91
Note: See TracBrowser for help on using the repository browser.