-
Notifications
You must be signed in to change notification settings - Fork 2
/
glext.h
114 lines (85 loc) · 2.95 KB
/
glext.h
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
// heligun: 3D flight sim shooter
// Copyright (c) 2016 Joseph Kuziel
//
// This software is MIT licensed.
//
#ifdef __EMSCRIPTEN__
#include <SDL2/SDL_opengles2.h>
#else
#include <SDL2/SDL_opengl.h>
#endif
/// @brief Print text description of OpenGL error from glGetError().
/// @return GL error enum. 0 if no error, !0 if error occurred
GLenum glextCheckError();
/// @brief Print the shader info log to standard output.
/// @param shader GL shader name
void glextPrintShaderInfoLog(
GLuint shader
);
/// @brief Print the shader program info log to standard output.
/// @param program GL shader program name
void glextPrintProgramInfoLog(
GLuint program
);
/// @brief Creates and loads a shader (vertex or fragment) from a text file.
/// @param shader_filename Filename of shader to load
/// @param shader_type Can either be GL_VERTEX_SHADER or GL_FRAGMENT_SHADER
/// @return GL shader name
GLuint glextLoadShader(
const char* shader_filename
, GLenum shader_type
);
/// @brief Compiles shader and prints any compiler errors to standard output.
/// @param shader GL name of shader to compile
/// @return 0 if compilation succeeded or 1 if failed
int glextCompileShader(
GLuint shader
);
/// @brief Links shader program and prints compiler errors to standard output.
/// @param program GL name of shader program to link
/// @return 0 on success or 1 on failure
int glextLinkProgram(
GLuint program
);
/// @brief Loads vertex and fragment shaders, compiles, and links shader program
/// @param vertex_shader_filename Filename of vertex shader in plain text
/// @param fragment_shader_filename Filename of fragment shader in plain text
/// @return GL shader program name or 0 on failure
GLuint glextCreateShaderProgram(
const char* vertex_shader_filename
, const char* fragment_shader_filename
);
/// @brief Creates and loads texture from image file
/// @param filename Filename of image to load
/// @param repeat 0 = clamp texture, otherwise repeat
/// @param linearFilter 0 = nearest filtering, otherwise linear filtering
/// @return GL name of texture
GLuint glextLoadTexture(
const char* filename
, GLuint repeat
, GLuint linearFilter
);
/// @brief Binds texture to shader uniform parameter
/// @param program GL shader program name
/// @param texture GL texture name
/// @param unit Texture unit to bind texture to
/// @param uniform Uniform name to bind texture to
/// @return 0 on success, 1 on failure
int glextBindTextureToUniform(
GLuint program
, GLuint texture
, GLuint unit
, const char* uniform
);
/// @brief Create a Vertex Buffer Object from an array of data
/// @param vertices Pointer to flat vertex array
/// @param count Number of vertices described by the vertex array
/// @param size Number of floats per vertex
/// @param usage Type of VBO: GL_STREAM_DRAW, GL_STATIC_DRAW, or GL_DYNAMIC_DRAW
GLuint glextCreateVBO(
GLfloat* vertices
, GLuint count
, GLint size
, GLenum usage
);