-
Notifications
You must be signed in to change notification settings - Fork 0
/
gltexture.c
45 lines (36 loc) · 1.24 KB
/
gltexture.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
#include <stdio.h>
#include <epoxy/gl.h>
#include <GLFW/glfw3.h>
#include "stb_image.h"
#define LOG(...) do { \
fprintf(stderr, "%s:%s():%d: ", __FILE__, __func__, __LINE__); \
fprintf(stderr, __VA_ARGS__); \
fputc('\n', stderr); \
} while(0)
#define FAIL(...) do { LOG("Error: " __VA_ARGS__); exit(1); } while(0)
#define ASSERT(cond, ...) if (!(cond)) FAIL(__VA_ARGS__)
#define GL() do { \
GLenum err = glGetError(); \
ASSERT(err == GL_NO_ERROR, "OpenGL error: %d", err); \
} while(0)
int main(int argc, char** argv) {
if (argc < 2) {
fprintf(stderr, "Usage: %s [image]", argv[0]);
return 1;
}
int img_w, img_h, img_ch;
uint8_t* img = stbi_load(argv[1], &img_w, &img_h, &img_ch, 4);
ASSERT(glfwInit() == GLFW_TRUE, "Failed to initialize GLFW");
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
#endif
GLFWwindow* win = glfwCreateWindow(img_w, img_h, "GL Texture", NULL, NULL);
ASSERT(win, "Failed to create GLFW window");
glfwMakeContextCurrent(win);
stbi_image_free(img);
return 0;
}