Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: a76b4b9a682c8b3c36af1d0aaf1191b48118b257 (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
/*
   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.h"
#include "gl/osiriongl.h"

#include <SDL/SDL.h>

namespace client {

Video::Video()
{	
	width = 0;
	height = 0;
	initialized = false;
	ratio = 1;
}

Video::~Video()
{
}

void Video::reset()
{
	ratio = (float) width / (float) height;

	// Our shading model--Gouraud (smooth). 
	gl::shademodel(GL_SMOOTH);

	// Culling
	gl::cullface( GL_BACK );
	gl::frontface(GL_CCW );
	gl::enable( GL_CULL_FACE );

	// Depth buffer writing
	gl::depthmask(GL_TRUE);
	gl::enable(GL_DEPTH_TEST);

	// Alpha blending
	gl::blendfunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);	

	// Set the clear color
	gl::clearcolor( 0, 0, 0, 0 );

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

	view.reset();
}

void Video::init() 
{
	if (initialized) {
		return;
	}

	int bpp = 0;
	int flags = 0;

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

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

	width = 800;
	height = 600;
	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 )) {
		conwarn << "SDL_SetVideoMode() failed: " << SDL_GetError() << std::endl;
		return;
	}

	gl::init();

	initialized = true;
	view.init();

	reset();
	return;
}

void Video::draw(float elapsed)
{
	view.draw(elapsed);
}

void Video::shutdown()
{
	view.shutdown();
	gl::shutdown();

	initialized = false;
	width = 0;
	height = 0;
}

} // namespace client