a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

am_gl.h (6931B)


      1 #if !defined(AM_GL_H)
      2 #define AM_GL_H
      3 
      4 // Thanks to Fabien Giesen [1] and Apoorva Joshi [2] for their succinct
      5 // examples of how to load OpenGL functions.
      6 // [1]: https://gist.github.com/rygorous/16796a0c876cf8a5f542caddb55bce8a
      7 // [2]: http://apoorvaj.io/loading-opengl-without-glew.html
      8 
      9 #if !defined(__gl_h_)
     10 #define __gl_h_
     11 #else
     12 #error <GL/gl.h> was already included. This conflicts with that.
     13 #endif
     14 
     15 // GL_VERSION_1_0
     16 typedef void GLvoid;
     17 typedef unsigned int GLenum;
     18 typedef float GLfloat;
     19 typedef int GLint;
     20 typedef int GLsizei;
     21 typedef unsigned int GLbitfield;
     22 typedef unsigned int GLuint;
     23 typedef unsigned char GLboolean;
     24 #define GL_BLEND                          0x0BE2
     25 #define GL_COLOR_BUFFER_BIT               0x00004000
     26 #define GL_FALSE                          0
     27 #define GL_FILL                           0x1B02
     28 #define GL_FLOAT                          0x1406
     29 #define GL_FRONT_AND_BACK                 0x0408
     30 #define GL_LINEAR                         0x2601
     31 #define GL_LINEAR_MIPMAP_LINEAR           0x2703
     32 #define GL_LINES                          0x0001
     33 #define GL_ONE_MINUS_SRC_ALPHA            0x0303
     34 #define GL_RGBA                           0x1908
     35 #define GL_SCISSOR_TEST                   0x0C11
     36 #define GL_SRC_ALPHA                      0x0302
     37 #define GL_TEXTURE_MAG_FILTER             0x2800
     38 #define GL_TEXTURE_MIN_FILTER             0x2801
     39 #define GL_TEXTURE_WRAP_S                 0x2802
     40 #define GL_TEXTURE_WRAP_T                 0x2803
     41 #define GL_TRIANGLES                      0x0004
     42 #define GL_TRUE                           1
     43 #define GL_UNSIGNED_BYTE                  0x1401
     44 #define GL_UNSIGNED_INT                   0x1405
     45 // GL_VERSION_1_1
     46 #define GL_RGBA8                          0x8058
     47 // GL_VERSION_1_2
     48 #define GL_CLAMP_TO_EDGE                  0x812F
     49 // GL_VERSION_1_3
     50 #define GL_TEXTURE0                       0x84C0
     51 // GL_VERSION_1_4
     52 // GL_VERSION_1_5
     53 typedef size_t GLsizeiptr;
     54 #define GL_ARRAY_BUFFER                   0x8892
     55 #define GL_ELEMENT_ARRAY_BUFFER           0x8893
     56 #define GL_STATIC_DRAW                    0x88E4
     57 // GL_VERSION_2_0
     58 typedef char GLchar;
     59 #define GL_COMPILE_STATUS                 0x8B81
     60 #define GL_FRAGMENT_SHADER                0x8B30
     61 #define GL_LINK_STATUS                    0x8B82
     62 #define GL_VERTEX_SHADER                  0x8B31
     63 // GL_VERSION_2_1
     64 // GL_VERSION_3_0
     65 #define GL_TEXTURE_2D_ARRAY               0x8C1A
     66 // GL_VERSION_3_1
     67 // GL_VERSION_3_2
     68 // GL_VERSION_3_3
     69 
     70 // https://www.khronos.org/registry/OpenGL/api/GL/glcorearb.h
     71 #define GL_LOAD_FUNCTION_LIST \
     72     /* GL_VERSION_1_0 */ \
     73     AM_GLE(void,   glBlendFunc,               GLenum sfactor, GLenum dfactor) \
     74     AM_GLE(void,   glClear,                   GLbitfield mask) \
     75     AM_GLE(void,   glClearColor,              GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) \
     76     AM_GLE(void,   glDisable,                 GLenum cap) \
     77     AM_GLE(void,   glEnable,                  GLenum cap) \
     78     AM_GLE(void,   glPolygonMode,             GLenum face, GLenum mode) \
     79     AM_GLE(void,   glScissor,                 GLint x, GLint y, GLsizei width, GLsizei height) \
     80     AM_GLE(void,   glTexParameteri,           GLenum target, GLenum pname, GLint param) \
     81     AM_GLE(void,   glViewport,                GLint x, GLint y, GLsizei width, GLsizei height) \
     82     /* GL_VERSION_1_1 */ \
     83     AM_GLE(void,   glBindTexture,             GLenum target, GLuint texture) \
     84     AM_GLE(void,   glDrawElements,            GLenum mode, GLsizei count, GLenum type, const void *indices) \
     85     AM_GLE(void,   glGenTextures,             GLsizei n, GLuint *textures) \
     86     /* GL_VERSION_1_2 */ \
     87     AM_GLE(void,   glTexImage3D,              GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels) \
     88     AM_GLE(void,   glTexSubImage3D,           GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels) \
     89     /* GL_VERSION_1_3 */ \
     90     AM_GLE(void,   glActiveTexture,           GLenum texture) \
     91     /* GL_VERSION_1_4 */ \
     92     /* GL_VERSION_1_5 */ \
     93     AM_GLE(void,   glBindBuffer,              GLenum target, GLuint buffer) \
     94     AM_GLE(void,   glBufferData,              GLenum target, GLsizeiptr size, const void *data, GLenum usage) \
     95     AM_GLE(void,   glDeleteBuffers,           GLsizei n, const GLuint *buffers) \
     96     AM_GLE(void,   glGenBuffers,              GLsizei n, GLuint *buffers) \
     97     /* GL_VERSION_2_0 */ \
     98     AM_GLE(void,   glAttachShader,            GLuint program, GLuint shader) \
     99     AM_GLE(void,   glCompileShader,           GLuint shader) \
    100     AM_GLE(GLuint, glCreateProgram,           void) \
    101     AM_GLE(GLuint, glCreateShader,            GLenum type) \
    102     AM_GLE(void,   glDeleteShader,            GLuint shader) \
    103     AM_GLE(void,   glEnableVertexAttribArray, GLuint index) \
    104     AM_GLE(void,   glGetProgramiv,            GLuint program, GLenum pname, GLint *params) \
    105     AM_GLE(void,   glGetShaderInfoLog,        GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog) \
    106     AM_GLE(void,   glGetShaderiv,             GLuint shader, GLenum pname, GLint *params) \
    107     AM_GLE(GLint,  glGetUniformLocation,      GLuint program, const GLchar *name) \
    108     AM_GLE(void,   glLinkProgram,             GLuint program) \
    109     AM_GLE(void,   glShaderSource,            GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length) \
    110     AM_GLE(void,   glUniform1f,               GLint location, GLfloat v0) \
    111     AM_GLE(void,   glUniform1i,               GLint location, GLint v0) \
    112     AM_GLE(void,   glUniform3f,               GLint location, GLfloat v0, GLfloat v1, GLfloat v2) \
    113     AM_GLE(void,   glUniformMatrix4fv,        GLint location, GLsizei count, GLboolean transpose, const GLfloat *value) \
    114     AM_GLE(void,   glUseProgram,              GLuint program) \
    115     AM_GLE(void,   glVertexAttribPointer,     GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer) \
    116     /* GL_VERSION_2_1 */ \
    117     /* GL_VERSION_3_0 */ \
    118     AM_GLE(void,   glBindVertexArray,         GLuint array) \
    119     AM_GLE(void,   glDeleteVertexArrays,      GLsizei n, const GLuint *arrays) \
    120     AM_GLE(void,   glGenerateMipmap,          GLenum target) \
    121     AM_GLE(void,   glGenVertexArrays,         GLsizei n, GLuint *arrays) \
    122     /* GL_VERSION_3_1 */ \
    123     /* GL_VERSION_3_2 */ \
    124     /* GL_VERSION_3_3 */
    125 
    126 #if defined(PLATFORM_LINUX)
    127 #define GLDECL
    128 #elif defined(PLATFORM_WINDOWS)
    129 #define NOMINMAX
    130 #define WIN32_LEAN_AND_MEAN
    131 #include <windows.h>
    132 #undef near
    133 #undef far
    134 #define GLDECL WINAPI
    135 #else
    136 #error
    137 #endif // defined(PLATFORM_LINUX)
    138 
    139 #define AM_GLE(ret, name, ...) \
    140     typedef ret GLDECL name##Proc(__VA_ARGS__); \
    141     static name##Proc * name;
    142     GL_LOAD_FUNCTION_LIST
    143 #undef AM_GLE
    144 
    145 int am_gl_init();
    146 
    147 #endif // AM_GL_H