-
Notifications
You must be signed in to change notification settings - Fork 0
/
Delta.cpp
134 lines (109 loc) · 2.66 KB
/
Delta.cpp
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
127
128
129
130
131
132
133
134
/**
* This file is in the public domain.
* Programmer: Toben "Littlefoot" Archer
*/
#include <math.h>
#include <iostream>
#include "Camera.cpp"
#include "ResourceManager.cpp"
#include "Scene.cpp"
#include "Interface.cpp"
using namespace std;
Scene *foo;
glm::mat4 projection,view;
GLint uniform_mvp;
GLint local;
float angle = 0.0;
float angleV = 0.0;
float angleH = 0.0;
float rotx = 0.0;
float roty = 0.0;
float rotz = 0.0;
float zoom = 0.0;
int lx = -1, ly = -1;
bool lclick = false;
bool rclick = false;
float shuffle = 0.0;
float downShuf = 0.0;
int frameCount = 0;
//initalize all the resources for Delta.
int init_resources()
{
TRACE(1);
globalRM = new ResourceManager();
globalIn = new Interface();
//seed the random number generator.
srand(time(NULL));
const char* filename = "Scene.xml";
xml_document doc;
xml_parse_result result; TRACE(3);
result = doc.load_file(filename); TRACE(3);
foo = new Scene(doc.first_child()); TRACE(3);
foo->bindToProgram(0); TRACE(3);
globalRM->ResolveRequests(); TRACE(3);
printf("Resources loaded!\n");
return 1;//resources initalized.
}
void onIdle()
{
frameCount++;
globalIn->update();
glutPostRedisplay();//request a redraw.
}
void onDisplay()
{//redraw!
glClearColor(0.0, 0.0, 0.0, 1.0);//set the color to clear too. not the color that is clear.
//thats what the alpha channel is for.
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);//clear these buffers.
TRACE(1);
foo->render();
TRACE(1);
//redrawn, swap the buffers and put this new one to the front.
glutSwapBuffers();
}
void free_resources()
{//done, free up the resources so there aren't any loose ends.
delete foo;
}
void shutdown()
{
free_resources();
printf("frames: %i\n",frameCount);
exit(0);
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_ALPHA|GLUT_DOUBLE|GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutCreateWindow("Delta Alpha 13");
glutKeyboardFunc(keyFunc);
glutKeyboardUpFunc(keyUpFunc);
glutSpecialFunc(specialFunc);
glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF);
if (argc > 1)
DEBUG = ((int)argv[1][0])-(int)'0';
else
DEBUG = 0;
GLenum glew_status = glewInit();
if (glew_status != GLEW_OK) {
fprintf(stderr, "Error: %s\n", glewGetErrorString(glew_status));
return 1;
}
if (!GLEW_VERSION_2_0) {
fprintf(stderr, "Error: your graphic card does not support OpenGL 2.0\n");
return 1;
}
if (init_resources()) {
glutDisplayFunc(onDisplay);
glutIdleFunc(onIdle);
glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glEnable(GL_POINT_SMOOTH);
glEnable(GL_PROGRAM_POINT_SIZE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glutMainLoop();
}
return 0;
}
/*.S.D.G.*/