1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Benjamin Grauer |
---|
13 | co-programmer: ... |
---|
14 | */ |
---|
15 | |
---|
16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS |
---|
17 | |
---|
18 | #include "graphics_engine.h" |
---|
19 | |
---|
20 | #include "debug.h" |
---|
21 | |
---|
22 | using namespace std; |
---|
23 | |
---|
24 | |
---|
25 | /** |
---|
26 | \brief standard constructor |
---|
27 | \todo this constructor is not jet implemented - do it |
---|
28 | */ |
---|
29 | GraphicsEngine::GraphicsEngine () |
---|
30 | { |
---|
31 | this->setClassName ("GraphicsEngine"); |
---|
32 | |
---|
33 | this->initVideo(); |
---|
34 | |
---|
35 | } |
---|
36 | |
---|
37 | GraphicsEngine* GraphicsEngine::singletonRef = NULL; |
---|
38 | |
---|
39 | GraphicsEngine* GraphicsEngine::getInstance() |
---|
40 | { |
---|
41 | if (!GraphicsEngine::singletonRef) |
---|
42 | GraphicsEngine::singletonRef = new GraphicsEngine(); |
---|
43 | return GraphicsEngine::singletonRef; |
---|
44 | } |
---|
45 | |
---|
46 | |
---|
47 | /** |
---|
48 | \brief destructs the graphicsEngine. |
---|
49 | */ |
---|
50 | GraphicsEngine::~GraphicsEngine () |
---|
51 | { |
---|
52 | // delete what has to be deleted here |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | \brief initializes the Video for openGL. |
---|
57 | |
---|
58 | This has to be done only once when starting orxonox. |
---|
59 | */ |
---|
60 | int GraphicsEngine::initVideo() |
---|
61 | { |
---|
62 | |
---|
63 | if (SDL_Init(SDL_INIT_VIDEO) == -1) |
---|
64 | { |
---|
65 | printf ("could not initialize SDL Video\n"); |
---|
66 | // return -1; |
---|
67 | } |
---|
68 | // Set video mode |
---|
69 | // TO DO: parse arguments for settings |
---|
70 | //SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); |
---|
71 | //SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); |
---|
72 | //SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); |
---|
73 | //SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); |
---|
74 | |
---|
75 | |
---|
76 | SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
---|
77 | SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16); |
---|
78 | SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0); |
---|
79 | SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 0); |
---|
80 | SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 0); |
---|
81 | SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 0); |
---|
82 | SDL_GL_SetAttribute( SDL_GL_ACCUM_ALPHA_SIZE, 0); |
---|
83 | |
---|
84 | |
---|
85 | //Uint32 flags = SDL_HWSURFACE | SDL_OPENGL | SDL_GL_DOUBLEBUFFER; /* \todo: SDL_OPENGL doen't permit to load images*/ |
---|
86 | //Uint32 flags = SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER; |
---|
87 | |
---|
88 | this->videoFlags = SDL_OPENGL | SDL_HWPALETTE | SDL_RESIZABLE; |
---|
89 | |
---|
90 | /* query SDL for information about our video hardware */ |
---|
91 | const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo (); |
---|
92 | |
---|
93 | if( videoInfo == NULL) |
---|
94 | { |
---|
95 | PRINTF(1)("Orxonox::initVideo() - Failed getting Video Info :%s\n", SDL_GetError()); |
---|
96 | SDL_Quit (); |
---|
97 | } |
---|
98 | if( videoInfo->hw_available) |
---|
99 | this->videoFlags |= SDL_HWSURFACE; |
---|
100 | else |
---|
101 | this->videoFlags |= SDL_SWSURFACE; |
---|
102 | /* |
---|
103 | if(VideoInfo -> blit_hw) |
---|
104 | VideoFlags |= SDL_HWACCEL; |
---|
105 | */ |
---|
106 | |
---|
107 | this->setResoulution(800, 600, 16); |
---|
108 | |
---|
109 | // Set window labeling |
---|
110 | SDL_WM_SetCaption ("Orxonox " PACKAGE_VERSION, "Orxonox " PACKAGE_VERSION); |
---|
111 | |
---|
112 | // TO DO: Create a cool icon and use it here |
---|
113 | // SDL_WM_SetIcon(SDL_Surface *icon, Uint8 *mask); |
---|
114 | |
---|
115 | } |
---|
116 | |
---|
117 | int GraphicsEngine::setResoulution(int width, int height, int bpp) |
---|
118 | { |
---|
119 | this->resolutionX = width; |
---|
120 | this->resolutionY = height; |
---|
121 | this->bitsPerPixel = bpp; |
---|
122 | |
---|
123 | if((this->screen = SDL_SetVideoMode (this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags)) == NULL) |
---|
124 | { |
---|
125 | PRINTF(1)("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags, SDL_GetError()); |
---|
126 | SDL_Quit(); |
---|
127 | // return -1; |
---|
128 | } |
---|
129 | |
---|
130 | } |
---|