Skip to content

Instantly share code, notes, and snippets.

@chromedays
Created December 17, 2017 12:48
Show Gist options
  • Save chromedays/8075449ff2041f02be25ca8c152b8b7e to your computer and use it in GitHub Desktop.
Save chromedays/8075449ff2041f02be25ca8c152b8b7e to your computer and use it in GitHub Desktop.
#ifdef _WIN32
#include <windows.h>
#include <GL/gl.h>
#define GL_CALL APIENTRY
#else
#include "GL/gl.h"
#define GL_CALL
#endif//_WIN32
// This loader code is inspired by Bink GL extension loader
// Acquired from https://www.khronos.org/registry/OpenGL/api/GL/glext.h
#define GL_ARRAY_BUFFER 0x8892
#define GL_ELEMENT_ARRAY_BUFFER 0x8893
#define GL_VERTEX_SHADER 0x8B31
#define GL_FRAGMENT_SHADER 0x8B30
#define GL_COMPILE_STATUS 0x8B81
#define GL_LINK_STATUS 0x8B82
#define GL_CURRENT_PROGRAM 0x8B8D
#define GL_STATIC_DRAW 0x88E4
#define GL_STREAM_DRAW 0x88E0
#define GL_FUNC_ADD 0x8006
#define GL_ACTIVE_TEXTURE 0x84E0
#define GL_TEXTURE0 0x84C0
#define GL_TEXTURE1 0x84C1
#define GL_TEXTURE2 0x84C2
#define GL_TEXTURE3 0x84C3
#define GL_TEXTURE4 0x84C4
#define GL_TEXTURE5 0x84C5
#define GL_TEXTURE6 0x84C6
#define GL_TEXTURE7 0x84C7
#define GL_TEXTURE8 0x84C8
#define GL_TEXTURE9 0x84C9
#define GL_TEXTURE10 0x84CA
#define GL_TEXTURE11 0x84CB
#define GL_TEXTURE12 0x84CC
#define GL_TEXTURE13 0x84CD
#define GL_TEXTURE14 0x84CE
#define GL_TEXTURE15 0x84CF
#define GL_TEXTURE16 0x84D0
#define GL_ARRAY_BUFFER_BINDING 0x8894
#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895
#define GL_VERTEX_ARRAY_BINDING 0x85B5
#define GL_BLEND_SRC_RGB 0x80C9
#define GL_BLEND_DST_RGB 0x80C8
#define GL_BLEND_DST_ALPHA 0x80CA
#define GL_BLEND_SRC_ALPHA 0x80CB
#define GL_BLEND_EQUATION_RGB 0x8009
#define GL_BLEND_EQUATION_ALPHA 0x883D
typedef char GLchar;
typedef ptrdiff_t GLsizeiptr;
typedef ptrdiff_t GLintptr;
typedef void (GL_CALL *GLDEBUGPROCARB)(GLenum source, GLenum type, GLuint id,
GLenum severity, GLsizei length,
const GLchar *message, const void *userParam);
#define GL_LIST \
GLE(void, BlendEquation, GLenum mode) \
GLE(void, BlendEquationSeparate, GLenum modeRGB, GLenum modeAlpha) \
GLE(void, BlendFuncSeparate, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) \
GLE(GLuint, CreateShader, GLenum type) \
GLE(void, ShaderSource, GLuint shader, GLsizei count, const GLchar* const*string, const GLint* length) \
GLE(void, CompileShader, GLuint shader) \
GLE(void, GetShaderiv, GLuint shader, GLenum pname, GLint* params) \
GLE(void, GetShaderInfoLog, GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog) \
GLE(GLuint, CreateProgram, void) \
GLE(void, AttachShader, GLuint program, GLuint shader) \
GLE(void, LinkProgram, GLuint program) \
GLE(void, GetProgramiv, GLuint program, GLenum pname, GLint *params) \
GLE(void, GetProgramInfoLog, GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog) \
GLE(void, DeleteProgram, GLuint program) \
GLE(void, DeleteShader, GLuint shader) \
GLE(void, GenVertexArrays, GLsizei n, GLuint *arrays) \
GLE(void, GenBuffers, GLsizei n, GLuint *buffers) \
GLE(void, DeleteVertexArrays, GLsizei n, const GLuint *arrays) \
GLE(void, DeleteBuffers, GLsizei n, const GLuint *buffers) \
GLE(void, BindVertexArray, GLuint array) \
GLE(void, BindBuffer, GLenum target, GLuint buffer) \
GLE(void, BufferData, GLenum target, GLsizeiptr size, const void *data, GLenum usage) \
GLE(void, VertexAttribPointer, GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer) \
GLE(void, EnableVertexAttribArray, GLuint index) \
GLE(void, DisableVertexAttribArray, GLuint index) \
GLE(void, UseProgram, GLuint program) \
GLE(void, GenerateMipmap, GLenum target) \
GLE(GLint, GetUniformLocation, GLuint program, const GLchar *name) \
GLE(GLint, GetAttribLocation, GLuint program, const GLchar *name) \
GLE(void, ActiveTexture, GLenum texture) \
GLE(void, Uniform1i, GLint location, GLint v0) \
GLE(void, Uniform3f, GLint location, GLfloat v0, GLfloat v1, GLfloat v2) \
GLE(void, Uniform4fv, GLint location, GLsizei count, const GLfloat *value) \
GLE(void, UniformMatrix4fv, GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) \
GLE(void, DebugMessageCallbackARB, GLDEBUGPROCARB callback, const void* userParam)
#define GLE(ret, name, ...) typedef ret name##Func(__VA_ARGS__); \
extern name##Func* gl##name;
GL_LIST
#undef GLE
b32 gl_load_extensions();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment