summaryrefslogtreecommitdiff
path: root/mogltk/glbase.cpp
blob: 71fcaa000dedb7968eacd9b3004efb228e524777 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "glbase.h"
#include "engine.h"
#include "generic.h"
#include <SDL.h>
#include <SDL_opengl.h>

int mogltk::glbase::width, mogltk::glbase::height, mogltk::glbase::inited = 0;
SDL_Surface * mogltk::glbase::surface = 0;

int mogltk::glbase::setup(int w, int h, int flags) throw(GeneralException) {
    if (inited) {
        printm(M_WARNING, "mogltk::glbase::setup called twice, ignoring second call...\n");
        return -1;
    }

    width = w;
    height = h;
    
    mogltk::engine::setup();
    if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
        throw GeneralException(String("Couldn't initialise Video SubSystem: ") + SDL_GetError());
    }

    if (!(surface = SDL_SetVideoMode(width, height, 0, flags | SDL_OPENGL))) {
        throw GeneralException(String("Couldn't set GL mode: ") + SDL_GetError());
    }

    printm(M_INFO, "Video resolution: %dx%dx%d\n", surface->w, surface->h, surface->format->BitsPerPixel);
    printm(M_INFO, "\n");
    printm(M_INFO, "OpenGL infos\n");
    printm(M_INFO, "------------\n");
    printm(M_INFO, String("Vendor    : ") + (char *) glGetString(GL_VENDOR) + "\n");
    printm(M_INFO, String("Renderer  : ") + (char *) glGetString(GL_RENDERER) + "\n");
    printm(M_INFO, String("Version   : ") + (char *) glGetString(GL_VERSION) + "\n");
    printm(M_INFO, String("Extensions: ") + (char *) glGetString(GL_EXTENSIONS) + "\n");

    inited = 1;
    return 0;
}

int mogltk::glbase::GetWidth(void) {
    return width;
}

int mogltk::glbase::GetHeight(void) {
    return height;
}

int mogltk::glbase::GetInited(void) {
    return inited;
}