Last active
February 17, 2017 09:34
-
-
Save pervognsen/0c79a35d27eb856d63fd to your computer and use it in GitHub Desktop.
gl3w-style loader generator for SDL2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: python glgen.py SDL_opengl.h (or SDL_opengl_glext.h if you're on the 2.0.4 development branch) | |
import sys | |
import re | |
ext_file = file(sys.argv[1]) | |
functions = [] | |
for match in re.finditer(r" APIENTRY (gl.*?) \(", ext_file.read()): | |
functions.append((match.group(1), "PFN%sPROC" % (match.group(1).upper(),))) | |
loader_file = file('SDL_opengl_load.h', 'w') | |
def out(str): | |
loader_file.write(str) | |
out('#ifdef __cplusplus\nextern "C"\n{\n#endif\n\n#ifndef _SDL_opengl_load_h\n#define _SDL_opengl_load_h\n\nvoid SDL_GL_LoadExtensions(void);\n\n') | |
for name, typedef in functions: | |
out('extern %s SDL_%s;\n#define %s SDL_%s\n\n' % (typedef, name, name, name)) | |
out('#endif\n\n#ifdef SDL_OPENGL_LOAD_IMPLEMENT\n\n') | |
for name, typedef in functions: | |
out('%s SDL_%s;\n' % (typedef, name)) | |
out('\nvoid SDL_GL_LoadExtensions(void)\n{\n') | |
for name, typedef in functions: | |
out(' SDL_%s = (%s) SDL_GL_GetProcAddress("%s");\n' % (name, typedef, name)) | |
out('}\n\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment