infinite terrain experiments
[shady.git] / main.cpp
blob5fc0c039503135bf9a12d6d243e88675c26dadd7
2 // For initializing the random number generator.
3 #include <ctime>
4 #include <cstdlib>
5 using std::time;
6 using std::srand;
8 #include <string>
9 #include <vector>
10 using std::string;
11 using std::vector;
13 extern "C" {
14 #include <GL/freeglut.h>
17 #include <cassert>
19 #include "output.hpp"
20 #include "shady.hpp"
23 static Shady * shady;
26 static void render() {
27 shady->render();
28 glutSwapBuffers();
31 static void resized(int width, int height) {
32 shady->resized(width, height);
35 static void normalKeyPressed(unsigned char key, int x, int y) {
36 shady->normalKeyPressed(key, x, y);
39 static void specialKeyPressed(int key, int x, int y) {
40 shady->specialKeyPressed(key, x, y);
43 static void mouseDragged(int x,int y) {
44 shady->mouseDragged(x, y);
47 static void mouseClicked(int button, int state, int x, int y) {
48 shady->mouseClicked(button, state, x, y);
52 int main(int argc, char ** argv) {
54 OUT(OUT_SHELLCOMMAND(OUT_BRIGHT) "Shady - OpenGL playground" OUT_SHELLCOMMAND(OUT_RESET));
56 OUT("usage: shady <postprocess>...");
58 glutInit(&argc, argv);
60 vector<string> pps;
61 for(int i = 1; i < argc; i++) {
62 pps.push_back(argv[i]);
65 // TODO generalize keybindings
66 OUT("Movement: " OUT_COLORED(OUT_GREEN, "WASD"));
67 OUT("Height: " OUT_COLORED(OUT_GREEN, "Q/E"));
68 OUT("Rotation: " OUT_COLORED(OUT_GREEN, "mouse") " (drag) and " OUT_COLORED(OUT_GREEN, "arrow keys"));
69 OUT("Radius: " OUT_COLORED(OUT_GREEN, "+/-"));
70 OUT("Var: " OUT_COLORED(OUT_GREEN, "*") " and " OUT_COLORED(OUT_GREEN, "/"));
71 OUT("Reset view: " OUT_COLORED(OUT_GREEN, "backspace"));
72 OUT("New world: " OUT_COLORED(OUT_GREEN, "space"));
74 // Initialize the random number generator for unique worlds.
75 srand(time(NULL) / 2);
77 shady = new Shady(pps);
79 glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
80 glutInitWindowSize(1024, 860);
82 glutCreateWindow("Shady");
84 if(!shady->init()) {
85 ERROR("initializing shady");
86 delete shady;
87 return 1;
90 // TODO disable key repeating for smoother movement
92 glutDisplayFunc(render);
93 glutIdleFunc(render);
94 glutReshapeFunc(resized);
95 glutKeyboardFunc(normalKeyPressed);
96 glutSpecialFunc(specialKeyPressed);
97 glutMouseFunc(mouseClicked);
98 glutMotionFunc(mouseDragged);
100 glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
102 glutMainLoop();
104 // Cleanup.
105 delete shady;
107 OUT("clean exit");
109 return 0;