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
|
#include <stdio.h>
#include <string.h>
#include "main.h"
int main()
{
if (!glfwPlatformSupported(GLFW_PLATFORM_WAYLAND)) {
printf("Wayland is not supported\n");
return 1;
}
glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_WAYLAND);
if (!glfwInit()) {
printf("Failed to initialize GLFW\n");
return 1;
}
glfwSetErrorCallback(error_callback);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
if (window == NULL) {
printf("Failed to create GLFW window\n");
glfwTerminate();
return 1;
}
glfwMakeContextCurrent(window);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glViewport(0, 0, 800, 600);
while(!glfwWindowShouldClose(window)) {
processInput(window);
glClearColor(0.121f, 0.157f, 0.246f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
void error_callback(int error, const char* description)
{
fprintf(stderr, "Error %d: %s\n", error, description);
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}
void processInput(GLFWwindow *window)
{
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, GLFW_TRUE);
}
/* TODO */
/* void hexToRGB(CRT_RGB* rgb, const char* hex) { */
/* if (strlen(hex) == 0) { */
/* printf("Invalid hex: %s", hex); */
/* return; */
/* } */
/* if (hex[0] != '#') { */
/* printf("Invalid hex: %s", hex); */
/* return; */
/* } */
/* const char* r; */
/* const char* g; */
/* const char* b; */
/* } */
|