-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
101 lines (78 loc) · 2.11 KB
/
main.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
#include <cstdlib>
#include <cmath>
#include <GLUT/glut.h>
#include "main.h"
#include "camera/Camera.h"
//#include "chunk/Chunk.h"
#include "block/Block.h"
#include "light/Light.h"
#include "mouse/mouse.h"
#include "keyboard/keyboard.h"
#include "player/Player.h"
#include "window/Window.h"
#include "world/World.h"
#include "biome/BiomeType.h"
// Ugly but GLUT is a C lib not C++ so not easy to do clean OOP...
Player *playerPtr;
Window *windowPtr;
World *worldPtr;
namespace {
constexpr int WINDOW_SIZE = 512;
}
int count = 0;
Light light;
void init() {
light.ApplyLight();
}
void display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
playerPtr->takeAction();
playerPtr->camera.refresh(light);
worldPtr->update(playerPtr->camera.camera_x, playerPtr->camera.camera_z);
playerPtr->camera.idle(sin((float) count++ / 40), 0);
glutSwapBuffers();
glutPostRedisplay();
}
void reshape(int w, int h) {
glutWarpPointer(w / 2, h / 2);
windowPtr->setWidth(w);
windowPtr->setHeight(h);
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (double) w / h, 0.5, 60);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char **argv) {
Window window(WINDOW_SIZE, WINDOW_SIZE);
windowPtr = &window;
World world;
worldPtr = &world;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(WINDOW_SIZE, WINDOW_SIZE);
glutCreateWindow("Terrain");
Player player(Camera(0, 20, 0, 0, 0, 0));
playerPtr = &player;
init();
glEnable(GL_CULL_FACE);
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutPassiveMotionFunc(mouseMotion);
glutKeyboardFunc(keydown);
glutKeyboardUpFunc(keyup);
glutWarpPointer(200, 200);
glClearColor(0.439, 0.729, 0.988, 0.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glShadeModel(GL_SMOOTH);
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glutMainLoop();
return 0;
}