-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
95 lines (78 loc) · 2.59 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
#define GLEW_STATIC
#include <iostream>
#include "GameControl.hpp"
#include "Util.hpp"
#include "SceneRenderer.hpp"
#include "Input.hpp"
#include "Constants.hpp"
#include "Textures.hpp"
#include "Constellations.hpp"
#include "Map.hpp"
#include "Chunk.hpp"
#include "Player.hpp"
const GLint WIDTH = 800, HEIGHT = 600;
int main ()
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); //needed for mac
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); //prevent from resizing
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "Learn Open GL", nullptr, nullptr);
int screenWidth, screenHeight;
glfwGetFramebufferSize(window, &screenWidth, &screenHeight);
//if window is not successfully created, terminate
if (window == nullptr)
{
std::cout << "failed to create GLFW window" << std::endl;
glfwTerminate();
return EXIT_FAILURE;
}
glfwMakeContextCurrent(window);
glewExperimental = GL_TRUE;
if (GLEW_OK != glewInit())
{
std::cout << "Failed to initialize GLEW" << std::endl;
return EXIT_FAILURE;
}
glfwSwapInterval(1);
glViewport(0, 0, screenWidth, screenHeight);
std::cout << glGetString(GL_VERSION) << std::endl;
//init input and crosshair stuff
Input::Init(window);
//init input and crosshair finished
//load textures
Textures::LoadTextures();
//load textures finished
//Generate map
Map::SetCurrSeed(100);
//Generate map finished
//set up Chunk
Chunk::SetUp();
//set up Chunk finished
GameControl::sharedInstance().Start();
Player::Init();
Player* player = new Player("Jacky", glm::vec3(0, 180, 0));
player -> Start();
SceneRenderer* renderer = new SceneRenderer(128);
renderer -> SetCamera(player -> m_FirstPersonCamera);
player -> SetSceneRenderer (renderer);
renderer -> SetConstellations (new Constellations(20));
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
double timeFromStart = glfwGetTime();
while (!glfwWindowShouldClose(window))
{
double timeCurr = glfwGetTime(); //in seconds
Constants::deltaTime = timeCurr - timeFromStart;
timeFromStart = timeCurr;
// GameControl::sharedInstance().Update();
renderer -> Render();
player -> Update();
glfwSwapBuffers(window);
glfwPollEvents();
}
delete player;
delete renderer;
}