-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.cpp
117 lines (88 loc) · 3.4 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
102
103
104
105
106
107
108
109
110
111
112
/****************************************************************************
Copyright (C) 2012 Adrian Blumer ([email protected])
Copyright (C) 2012 Pascal Spörri ([email protected])
Copyright (C) 2012 Sabina Schellenberg ([email protected])
All Rights Reserved.
You may use, distribute and modify this code under the terms of the
MIT license (http://opensource.org/licenses/MIT).
*****************************************************************************/
#include <iostream>
#include <stdlib.h>
#include "tclap/CmdLine.h"
#include "platform_includes.h"
#include "TerrainFluidSimulation.h"
using namespace std;
TerrainFluidSimulation* simulationPtr = 0;
int onWindowClose()
{
if (simulationPtr) simulationPtr->Stop();
return GL_TRUE;
}
int main(int argc, char** argv)
{
// Settings ////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
int windowWidth = 800;
int windowHeight = 600;
uint terrainDim = 300;
// Read Command Line Arguments /////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
try
{
TCLAP::CmdLine cmd("Terrain Eroision & Fluid Simulation.", ' ', "0.9");
TCLAP::ValueArg<uint> dimArg("d","dim","Size of the terrain. Default: 300.",false,300,"uint");
cmd.add(dimArg);
cmd.parse( argc, argv );
terrainDim = dimArg.getValue();
}
catch (TCLAP::ArgException &e)
{
std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
}
// Open GL Stuff ///////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// init GLFW
if (!glfwInit())
{
std::cerr << "[GLFW] Error initialising GLFW" << std::endl;
exit(1);
}
glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialiasing
// Use OpenGL Core v3.2
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
// Open an OpenGL window
if( !glfwOpenWindow( windowWidth,windowHeight, 8,8,8,8,8,8, GLFW_WINDOW ) )
{
std::cerr << "[GLFW] Error opening window" << std::endl;
glfwTerminate();
exit(1);
}
int major, minor, rev;
glfwGetGLVersion(&major, &minor, &rev);
fprintf(stdout, "OpenGL version recieved: %d.%d.%d\n", major, minor, rev);
// Init Glew (OpenGL Extension Loading)
#if defined(__APPLE__) || defined(__MACH__)
// Do nothing
#else
// http://stackoverflow.com/questions/8302625/segmentation-fault-at-glgenvertexarrays-1-vao
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
std::cerr << "[GLEW] Init failed: " << glewGetErrorString(err) << std::endl;
glfwTerminate();
exit(1);
}
#endif
// Start Simulation ////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
glfwSetWindowCloseCallback(onWindowClose);
simulationPtr = new TerrainFluidSimulation(terrainDim);
simulationPtr->Run();
delete simulationPtr;
cout << "The end." << endl;
return 0;
}