Created
December 1, 2015 03:02
-
-
Save Einlander/56e186098138aaaad63f to your computer and use it in GitHub Desktop.
learning opengl using Glad https://github.com/Dav1dde/glad/blob/master/example/c/simple.c
This file contains hidden or 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
| import "ecere" | |
| #include <glad/glad.h> | |
| #define property _property | |
| #include <GL/glut.h> | |
| #undef property | |
| // GLAD_DEBUG is only defined if the c-debug generator was used | |
| #ifdef GLAD_DEBUG | |
| // logs every gl call to the console | |
| void pre_gl_call(const char *name, void *funcptr, int len_args, ...) | |
| { | |
| printf("Calling: %s (%d arguments)\n", name, len_args); | |
| } | |
| #endif | |
| class HelloApp : Application | |
| { | |
| int width; | |
| width = 600; | |
| int height; | |
| height = 600; | |
| void (*display)(void); | |
| void (*reshape)(int , int); | |
| void display(void) | |
| { | |
| glClearColor(1.0f, 0.2f, 0.7f, 1.0f); | |
| glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
| glutSwapBuffers(); | |
| glutPostRedisplay(); | |
| } | |
| void ::reshape(int w, int h) | |
| { | |
| width = w > 1 ? w : 1; | |
| height = h > 1 ? h : 1; | |
| glViewport(0, 0, width, height); | |
| glClearDepth(1.0); | |
| glClearColor(0.0f, 0.0f, 0.0f, 0.0f); | |
| glEnable(GL_DEPTH_TEST); | |
| } | |
| void Main() | |
| { | |
| char *myargv [1]; | |
| int myargc=1; | |
| PrintLn("Hello, World!!"); | |
| if(gladLoadGL()) | |
| { | |
| // you need an OpenGL context before loading glad | |
| printf("I did load GL with no context!\n"); | |
| //exit(-1); | |
| } | |
| PrintLn("initializing"); | |
| myargv [0]=strdup ("Myappname"); | |
| glutInit(&myargc, myargv); | |
| PrintLn("SUCCESS!"); | |
| glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); | |
| glutInitWindowSize(600, 600); | |
| glutCreateWindow("cookie"); | |
| PrintLn("reshape callback"); | |
| glutReshapeFunc( this.reshape); | |
| PrintLn("display callback"); | |
| glutDisplayFunc( this.display); | |
| PrintLn("did we load?"); | |
| if(!gladLoadGL()) | |
| { | |
| printf("Something went wrong!\n"); | |
| //exit(-1); | |
| } | |
| #ifdef GLAD_DEBUG | |
| // before every opengl call call pre_gl_call | |
| glad_set_pre_callback(pre_gl_call); | |
| // don't use the callback for glClear | |
| // (glClear could be replaced with your own function) | |
| glad_debug_glClear = glad_glClear; | |
| #endif | |
| // gladLoadGLLoader(&glutGetProcAddress); | |
| printf("OpenGL %d.%d\n", GLVersion.major, GLVersion.minor); | |
| if (GLVersion.major < 2) | |
| { | |
| printf("Your system doesn't support OpenGL >= 2!\n"); | |
| //return -1; | |
| } | |
| printf("OpenGL %s, GLSL %s\n", glGetString(GL_VERSION), | |
| glGetString(GL_SHADING_LANGUAGE_VERSION)); | |
| glutMainLoop(); | |
| //return 0; | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment