summaryrefslogtreecommitdiff
path: root/video.cpp
blob: ab9b9d3e6b820f0a876c3eb00461f0ec2da7d2b2 (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
#include "video.h"

#include "gl.h"

SDL_Surface *video::surface = NULL;
int video::width = 800;
int video::height = 600;

void video::init() {
	SDL_Init(SDL_INIT_VIDEO);

	surface = SDL_SetVideoMode(width, height, 32, SDL_OPENGL);

	glClearColor(0, 0, 0, 0);
	glClearDepth(1);
	glDepthFunc(GL_LESS);
	glEnable(GL_DEPTH_TEST);

	glShadeModel(GL_SMOOTH);
	glEnable(GL_POINT_SMOOTH);

	//glEnable(GL_LIGHTING);
	//glEnable(GL_LIGHT0);
	//glEnable(GL_COLOR_MATERIAL);

	const float light_ambient[4] = {.2, .2, .2, 1};
	const float light_diffuse[4] = {1, 1, 1, 1};
	const float light_specular[4] = {1, 1, 1, 1};
	glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
	glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);

	//glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
	//glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0);
	//glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

	persp();
}

void video::free() {
	SDL_Quit();
}

void video::persp() {
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	gluPerspective(45, (float)width/(float)height, .1, 1000);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}

void video::ortho() {
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	glOrtho(0, width, 0, height, 0, 1);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}