-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
66 lines (65 loc) · 3 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
#include <GLFW/glfw3.h>
#include <windows.h>
float cxs = 0.3; // CubeOtherSize = cys // }
float cys = 0.5; // CubeOtherSize = cys // } Sizes
float czs = 0.3; // CubeOtherSize = cys // }
bool toRotate = true;
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
if (key == GLFW_KEY_E && action == GLFW_REPEAT && czs < 0.80) {czs += 0.005;}
else if (key == GLFW_KEY_Q && action == GLFW_REPEAT && czs > 0.03) {czs -= 0.005;}
if (key == GLFW_KEY_SPACE && action == GLFW_PRESS) {if (toRotate) {toRotate = false;} else {toRotate = true;}} // stop/start cube rotating
}
int main() {
FreeConsole();
if (!glfwInit()) { // init glfw for normaly functions work
return 0;}
glfwWindowHint(GLFW_SAMPLES, 4); // set 4X antialiasing
GLFWwindow* window = glfwCreateWindow(1280, 720, "OpenGl cube", NULL, NULL);
glfwMakeContextCurrent(window); // opening window on system
glfwSwapInterval(1); // setting fps 60 (1/60)
glEnable(GL_DEPTH_TEST); // enable deep check
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glMatrixMode(GL_MODELVIEW);
glFrustum(-0.1, 1, -1, 1, -1, 1);
glLoadIdentity();
float CUBE_TEXTRURE[] = {
1, 0.56, 0.73, 1, 0.56, 0.73, 1, 0.56, 0.73,
1, 0.56, 0.73, 1, 0.56, 0.73, 1, 0.56, 0.73, // face
0.97, 0.97, 0.87, 0.97, 0.97, 0.87, 0.97, 0.97, 0.87,
0.97, 0.97, 0.87, 0.97, 0.97, 0.87, 0.97, 0.97, 0.87, // backspace
0.8, 1, 0.8, 0.8, 1, 0.8, 0.8, 1, 0.8,
0.8, 1, 0.8, 0.8, 1, 0.8, 0.8, 1, 0.8, // right
0.54, 0.8, 0.84, 0.54, 0.8, 0.84, 0.54, 0.8, 0.84,
0.54, 0.8, 0.84, 0.54, 0.8, 0.84, 0.54, 0.8, 0.84, // left
0.8, 0.7, 1, 0.8, 0.7, 1, 0.8, 0.7, 1,
0.8, 0.7, 1, 0.8, 0.7, 1, 0.8, 0.7, 1, // head
};
glRotatef(-15, 1, 0, 0);
bool toSmall = true;
glfwSetKeyCallback(window, key_callback);
while (!glfwWindowShouldClose(window))
{
glfwPollEvents();
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // setting black backround
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, 1280, 720);
if (toRotate) {glRotatef(-0.5, 0, 1, 0);}
glColorPointer(3, GL_FLOAT, 0, CUBE_TEXTRURE); // set cube textrure
float CUBE[] = { // setting cube mesh as object
-cxs, cys, czs, cxs, cys, czs, cxs, -cys, czs, //
-cxs, -cys, czs, -cxs, cys, czs, cxs, -cys, czs, // face
-cxs, cys, -czs, cxs, cys, -czs, cxs, -cys, -czs, //
-cxs, -cys, -czs, -cxs, cys, -czs, cxs, -cys, -czs, // backspace
cxs, cys, czs, cxs, -cys, -czs, cxs, -cys, czs, //
cxs, cys, -czs, cxs, cys, czs, cxs, -cys, -czs, // right
-cxs, cys, czs, -cxs, -cys, -czs, -cxs, -cys, czs, //
-cxs, cys, -czs, -cxs, cys, czs, -cxs, -cys, -czs, // left
-cxs, cys, czs, cxs, cys, czs, -cxs, cys, -czs, //
-cxs, cys, -czs, cxs, cys, czs, cxs, cys, -czs, // head
};
glVertexPointer(3, GL_FLOAT, 0, CUBE); // creating cube mesh as vertex object
glDrawArrays(GL_TRIANGLES, 0, 30); // draw cube mesh with textrure
glfwSwapBuffers(window); // changing frames
}
}