-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c.1.bak
82 lines (79 loc) · 2.32 KB
/
main.c.1.bak
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
#include<stdio.h>
#include<stdlib.h>
#include<GLFW/glfw3.h>
#include<GL/gl.h>
#include<GL/glu.h>
void key_callback();
GLuint left = 0;
GLuint right = 0;
int main(){
if(!glfwInit()){
//printf("Failed to initialize GLFW!\n");
system("notify-send 'Failed to initialize GLFW'");
return 1;
}
GLFWwindow* window = glfwCreateWindow(1054, 1057, "Title", NULL, NULL);
if(window == NULL){
//printf("Window creation failed!\n");
system("notify-send 'Window creation failed!'");
return 1;
}
glfwSetKeyCallback(window, key_callback);
glfwMakeContextCurrent(window);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glMatrixMode(GL_MODELVIEW);
float translatetri = 0.0f;
float translatequad = 0.0f;
float currentframe = 0.0f;
float lastframe = 0.0f;
float deltatime = 0.0f;
while(!glfwWindowShouldClose(window)){
glfwPollEvents();
glfwSwapBuffers(window);
currentframe = glfwGetTime();
deltatime = currentframe - lastframe;
lastframe = currentframe;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(translatetri, 0.0f, 0.0f);
if(left == 1){
translatetri += -1.0f * deltatime;
}
if(right == 1){
translatetri += 1.0f * deltatime;
}
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-0.5f, -0.5f, 0.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f( 0.0f, 0.5f, 0.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f( 0.5f, -0.5f, 0.0f);
glEnd();
glLoadIdentity();
glBegin(GL_QUADS);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glVertex3f(-1.0f, -0.5f, 0.0f);
glVertex3f( 1.0f, -0.5f, 0.0f);
glVertex3f( 1.0f, -1.0f, 0.0f);
glEnd();
}
return 0;
}
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods){
if(key == GLFW_KEY_A && action == GLFW_PRESS){
left = 1;
}else if(key == GLFW_KEY_A && action == GLFW_RELEASE){
left = 0;
}else if(key == GLFW_KEY_D && action == GLFW_PRESS){
right = 1;
}else if(key == GLFW_KEY_D && action == GLFW_RELEASE){
right = 0;
}
}