-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
77 lines (64 loc) · 1.54 KB
/
main.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
#include "win_platform.h"
#include "opengl_loading.h"
#include "render_mgr.h"
#include <stdio.h>
#include <assert.h>
#define WIDTH 1280
#define HEIGHT 720
static const char *vstr =
"#version 430 core\n"
"void main()\n"
"{\n"
" const vec4 vertices[] = vec4[](vec4(0.25, -0.25, 0.5, 1.0), vec4(-0.25, -0.25, 0.5, 1.0), vec4(0.25, 0.25, 0.5, 1.0));\n"
" gl_Position = vertices[gl_VertexID];\n"
"}\n";
static const char *fstr =
"#version 430 core\n"
"layout (location = 0) out vec4 o_color;\n"
"void main()\n"
"{\n"
" o_color = vec4(1.0, 0.0, 0.0, 1.0);\n"
"}\n";
struct UserData {
GLuint vao;
GLuint program;
};
static void
_init(void *pud)
{
int major, minor;
glGetIntegerv(GL_MAJOR_VERSION, &major);
glGetIntegerv(GL_MINOR_VERSION, &minor);
printf("OpenGL info major:%d minor:%d\n", major, minor);
struct UserData *ud = pud;
glGenVertexArrays(1, &ud->vao);
glBindVertexArray(ud->vao);
ud->program = render_mgr_link(vstr, fstr);
assert(ud->program);
}
static void
_render(void *pud)
{
static const GLfloat green[] = { 0.0f, 0.25f, 0.0f, 1.0f };
glClearBufferfv(GL_COLOR, 0, green);
struct UserData *ud = pud;
glUseProgram(ud->program);
glDrawArrays(GL_TRIANGLES, 0, 3);
}
static void
_shutdown(void *pud)
{
struct UserData *ud = pud;
glDeleteVertexArrays(1, &ud->vao);
}
int main()
{
struct UserData data;
PlatformContext pc;
pc.ud = &data;
pc.init_cb = _init;
pc.render_cb = _render;
pc.shutdown_cb = _shutdown;
winplat_run(WIDTH, HEIGHT, &pc);
return 0;
}