-
Notifications
You must be signed in to change notification settings - Fork 457
/
Copy pathsimple.c
87 lines (69 loc) · 2.03 KB
/
simple.c
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
#include <stdio.h>
#include <stdlib.h>
#include <glad/glad.h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
// This file is a modified version of gl3w's test.c
// https://github.com/skaslev/gl3w/blob/master/src/test.c
// Compile:
// gcc example/c/simple.c -Ibuild/include build/src/glad.c -lglut -ldl
static int width = 600, height = 600;
static void display(void)
{
glClearColor(1.0f, 0.2f, 0.7f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
glutPostRedisplay();
}
static void reshape(int w, int h)
{
width = w > 1 ? w : 1;
height = h > 1 ? h : 1;
glViewport(0, 0, width, height);
glClearDepth(1.0);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glEnable(GL_DEPTH_TEST);
}
#ifdef GLAD_DEBUG
void pre_gl_call(const char *name, void *funcptr, int len_args, ...) {
printf("Calling: %s (%d arguments)\n", name, len_args);
}
#endif
int main(int argc, char **argv)
{
if(gladLoadGL()) {
// you need an OpenGL context before loading glad
printf("I did load GL with no context!\n");
exit(-1);
}
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize(width, height);
glutCreateWindow("cookie");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
if(!gladLoadGL()) {
printf("Something went wrong!\n");
exit(-1);
}
#ifdef GLAD_DEBUG
// before every opengl call call pre_gl_call
glad_set_pre_callback(pre_gl_call);
// don't use the callback for glClear
// (glClear could be replaced with your own function)
glad_debug_glClear = glad_glClear;
#endif
// gladLoadGLLoader(&glutGetProcAddress);
printf("OpenGL %d.%d\n", GLVersion.major, GLVersion.minor);
if (GLVersion.major < 2) {
printf("Your system doesn't support OpenGL >= 2!\n");
return -1;
}
printf("OpenGL %s, GLSL %s\n", glGetString(GL_VERSION),
glGetString(GL_SHADING_LANGUAGE_VERSION));
glutMainLoop();
return 0;
}