+// extension functions we use
+typedef GLuint (*GLCREATESHADERPROC) (GLenum type);
+typedef void (*GLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params);
+typedef void (*GLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
+typedef void (*GLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar* const *string, const GLint *length);
+typedef void (*GLCOMPILESHADERPROC) (GLuint shader);
+typedef GLuint (*GLCREATEPROGRAMPROC) (void);
+typedef void (*GLATTACHSHADERPROC) (GLuint program, GLuint shader);
+typedef void (*GLLINKPROGRAMPROC) (GLuint program);
+typedef GLint (*GLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name);
+typedef void (*GLUSEPROGRAMPROC) (GLuint program);
+
+typedef void (*GLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer);
+typedef void (*GLENABLEVERTEXATTRIBARRAYPROC) (GLuint index);
+typedef void (*GLGENBUFFERSPROC) (GLsizei n, GLuint *buffers);
+typedef void (*GLBINDBUFFERPROC) (GLenum target, GLuint buffer);
+typedef void (*GLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
+typedef void (*GLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers);
+
+#ifdef CON_GL3
+// VAOs are only supported in GL3+, and not needed in earler contexts
+typedef void (*GLBINDVERTEXARRAYPROC) (GLuint array);
+typedef void (*GLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays);
+typedef void (*GLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays);
+#endif
+
+GLGETSHADERIVPROC p_glGetShaderiv = NULL;
+GLGETSHADERINFOLOGPROC p_glGetShaderInfoLog = NULL;
+GLCREATESHADERPROC p_glCreateShader = NULL;
+GLSHADERSOURCEPROC p_glShaderSource = NULL;
+GLCOMPILESHADERPROC p_glCompileShader = NULL;
+GLCREATEPROGRAMPROC p_glCreateProgram = NULL;
+GLATTACHSHADERPROC p_glAttachShader = NULL;
+GLLINKPROGRAMPROC p_glLinkProgram = NULL;
+GLGETATTRIBLOCATIONPROC p_glGetAttribLocation = NULL;
+GLUSEPROGRAMPROC p_glUseProgram = NULL;
+
+GLVERTEXATTRIBPOINTERPROC p_glVertexAttribPointer = NULL;
+GLENABLEVERTEXATTRIBARRAYPROC p_glEnableVertexAttribArray = NULL;
+GLGENBUFFERSPROC p_glGenBuffers = NULL;
+GLBINDBUFFERPROC p_glBindBuffer = NULL;
+GLBUFFERDATAPROC p_glBufferData = NULL;
+GLDELETEBUFFERSPROC p_glDeleteBuffers = NULL;
+
+#ifdef CON_GL3
+GLBINDVERTEXARRAYPROC p_glBindVertexArray = NULL;
+GLDELETEVERTEXARRAYSPROC p_glDeleteVertexArrays = NULL;
+GLGENVERTEXARRAYSPROC p_glGenVertexArrays = NULL;
+#endif
+
+// resolve function pointers
+static T_proc resolveFunctionPointer(T_glGetProcAddress p_glGetProcAddress, const char *name)
+{
+ T_proc proc = p_glGetProcAddress(name);
+ if (proc == NULL) {
+ die("Error resolvung function %s\n", name);
+ }
+ return proc;
+}
+
+void resolveFunctionPointers(T_glGetProcAddress p_glGetProcAddress)
+{
+#ifdef CON_GL1
+ // we need to check if we have GL 2.0 or greater
+ std::string version = (char*)glGetString(GL_VERSION);
+ std::stringstream ssv(version);
+ std::string major;
+ std::getline(ssv, major, '.');
+ std::stringstream ssm(major);
+ int majorVersion;
+ ssm >> majorVersion;
+ if (majorVersion < 2) {
+ die("Need at least GL 2.0 to function properly, but detected version %d\n", majorVersion);
+ }
+#endif
+
+ // now get the function pointers
+ p_glGetShaderiv = (GLGETSHADERIVPROC)resolveFunctionPointer(p_glGetProcAddress, "glGetShaderiv");
+ p_glGetShaderInfoLog = (GLGETSHADERINFOLOGPROC)resolveFunctionPointer(p_glGetProcAddress, "glGetShaderInfoLog");
+ p_glCreateShader = (GLCREATESHADERPROC)resolveFunctionPointer(p_glGetProcAddress, "glCreateShader");
+ p_glShaderSource = (GLSHADERSOURCEPROC)resolveFunctionPointer(p_glGetProcAddress, "glShaderSource");
+ p_glCompileShader = (GLCOMPILESHADERPROC)resolveFunctionPointer(p_glGetProcAddress, "glCompileShader");
+ p_glCreateProgram = (GLCREATEPROGRAMPROC)resolveFunctionPointer(p_glGetProcAddress, "glCreateProgram");
+ p_glAttachShader = (GLATTACHSHADERPROC)resolveFunctionPointer(p_glGetProcAddress, "glAttachShader");
+ p_glLinkProgram = (GLLINKPROGRAMPROC)resolveFunctionPointer(p_glGetProcAddress, "glLinkProgram");
+ p_glGetAttribLocation = (GLGETATTRIBLOCATIONPROC)resolveFunctionPointer(p_glGetProcAddress, "glGetAttribLocation");