-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
77 lines (65 loc) · 1.96 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
#include<stdio.h>
#include<stdlib.h>
#ifdef EMSCRIPTEN
#include<emscripten/emscripten.h>
#define GLFW_INCLUDE_ES3
#endif
#include<GLFW/glfw3.h>
#include <iostream>
int windowWidth;
int windowHeight;
void window_size_callback(GLFWwindow* window, int width, int height)
{
printf("window_size_callback received width: %i, height: %i\n", width, height);
}
void key_callback(GLFWwindow* window, int key, int scancode, int action, int modifier)
{
if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE)
glfwSetWindowShouldClose(window, 1);
if (key == GLFW_KEY_ENTER)
std::cout << "Enter was hit\n" << std::endl;
}
static void wmbutcb(GLFWwindow *window, int button, int action, int mods) {
//assert(window != NULL); (void)button; (void)action; (void)mods;
printf("Mouse buttion! \n");
}
GLFWwindow *window;
void do_frame(){
static int a = 0;
//printf("Fc: %d \n", ++a);
//glClearColor(rand() / (float)RAND_MAX, rand() / (float)RAND_MAX, rand() / (float)RAND_MAX, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
int main(int argc, char **argv) {
if (glfwInit()!=GL_TRUE) {
printf("glfwInit() failed\n");
glfwTerminate();
} else {
printf("glfwInit() success\n");
window = glfwCreateWindow(1280, 512, "GLFW test", NULL, NULL);
if (!window){
printf("glfwCreateWindow() failed\n");
glfwTerminate();
} else {
printf("glfwCreateWindow() success\n");
glfwMakeContextCurrent(window);
glfwGetFramebufferSize(window, &windowWidth, &windowHeight);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetMouseButtonCallback(window, wmbutcb);
glfwSetKeyCallback(window, key_callback);
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
#ifdef EMSCRIPTEN
emscripten_set_main_loop(do_frame, 0, 1);
#else
while (!glfwWindowShouldClose(window))
{
do_frame();
}
#endif
}
}
glfwTerminate();
return EXIT_SUCCESS;
}