Repository navigation
Expand file tree
/
Copy pathgame.cpp
More file actions
107 lines (82 loc) · 2.13 KB
/
Copy pathgame.cpp
File metadata and controls
107 lines (82 loc) · 2.13 KB
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
#include "game.h"
#pragma comment(lib, "opengl32.lib")
std::shared_ptr<Game> current=nullptr;
extern void drag_init(GLFWwindow* window);
extern void drag_update(GLFWwindow* window);
extern void _key_callback(GLFWwindow*, int key, int scancode, int action, int mods);
//std::shared_ptr<Game> Game::GetCurrent()
//{
// //return current;
// //return nullptr;
//}
int Game::Init()
{
/*if (current != nullptr) {
fprintf(stderr, "ERROR: Game instance exists\n");
return 1;
}
current = std::shared_ptr<Game>(this);*/
// start GL context and O/S window using the GLFW helper library
if (!glfwInit()) {
fprintf(stderr, "ERROR: could not start GLFW3\n");
return 1;
}
window = glfwCreateWindow(800, 600, "Blocks", NULL, NULL);
if (!window) {
fprintf(stderr, "ERROR: could not open window with GLFW3\n");
glfwTerminate();
return 1;
}
glfwMakeContextCurrent(window);
glfwSetKeyCallback(window, _key_callback);
// start GLEW extension handler
glewExperimental = GL_TRUE;
glewInit();
// get version info
const GLubyte* renderer = glGetString(GL_RENDERER); // get renderer string
const GLubyte* version = glGetString(GL_VERSION); // version as a string
printf("Renderer: %s\n", renderer);
printf("OpenGL version supported %s\n", version);
// tell GL to only draw onto a pixel if the shape is closer to the viewer
glEnable(GL_DEPTH_TEST); // enable depth-testing
glDepthFunc(GL_LESS); // depth-testing interprets a smaller value as "closer"
drag_init(window);
return 0;
}
int Game::Uninit()
{
glfwTerminate();
return 0;
}
int Game::Run(std::shared_ptr<Game> game)
{
if (current != nullptr) {
return -1;
}
current = game;
if (game->Init()) {
current = nullptr;
return 1;
}
while (true)
{
drag_update(game->window);
for (auto c = game->controllers.begin(); c != game->controllers.end(); c++) {
(*c)->FrameUpdate();
}
if (!game->GameLoop()) {
break;
}
}
game->Uninit();
current = nullptr;
return 0;
}
bool Game::GameLoop()
{
return !glfwWindowShouldClose(window);
}
//Game::~Game()
//{
//
//}