Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: df11b90ddee2190e326519de64a569c35e4413c6 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
   client/video.cc
   This file is part of the Osirion project and is distributed under 
   the terms and conditions of the GNU General Public License version 2 
*/

#include "client/video.h"
#include "client/view.h"
#include "render/render.h"
#include "core/core.h"
#include "sys/sys.h"

#include <SDL/SDL.h>

using namespace render;

namespace client {

namespace video {

const int defaultwidth = 1024;
const int defaultheight = 768;

int width =  0;
int height = 0;
float aspect = 1;

//--- cvars -------------------------------------------------------

core::Cvar r_width;
core::Cvar r_height;
core::Cvar r_fullscreen;

void reset()
{
	// recalculate the video aspect
	aspect = (float) width / (float) height;

	// settup our viewport.
	gl::viewport(0, 0, width, height );

	// reset the view
	view::reset();
}

bool init() 
{
	con_print << "Initializing video..." << std::endl;

	// initialize cvars
	r_width = core::cvar::get("r_width", defaultwidth);
	r_height = core::cvar::get("r_height", defaultheight);
	r_fullscreen = core::cvar::get("r_fullscreen", 1);

	int bpp = 0;
	int flags = 0;

	if( SDL_InitSubSystem(SDL_INIT_VIDEO) < 0 ) {
		std::cerr << "SDL_Init() failed: " << SDL_GetError() << std::endl;
		return false;
	}

	const SDL_VideoInfo* sdl_videoinfo = SDL_GetVideoInfo();
	if( !sdl_videoinfo) {
		std::cerr << "SDL_GetVideoInfo() failed: " << SDL_GetError() << std::endl;
		return false;
	}

	width = 1024;
	height = 768;
	bpp = sdl_videoinfo->vfmt->BitsPerPixel;

	SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
	SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
	SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
	SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
	SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 2);
	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

	flags = SDL_OPENGL | SDL_FULLSCREEN;

	if(!SDL_SetVideoMode(width, height, bpp, flags )) {
		std::cerr << "SDL_SetVideoMode() failed: " << SDL_GetError() << std::endl;
		return false;
	}

	con_print << "  video mode " << width << "x" << height << "x" << bpp << "bpp" << std::endl;
	
	aspect = (float) width / (float) height;
	

	render::init();

	view::init();

	video::reset();

	return true;
}

void frame(float seconds)
{
	// render a client frame
	view::frame(seconds);
	
	SDL_GL_SwapBuffers();
}

void shutdown()
{
	con_print << "Shutting down video..." << std::endl;
	
	view::shutdown();

	render::shutdown();

	width = 0;
	height = 0;

	SDL_QuitSubSystem(SDL_INIT_VIDEO);
}

} // namespace video

} // namespace client