Skip to content

Instantly share code, notes, and snippets.

@candh
Last active February 18, 2019 14:16
Show Gist options
  • Save candh/9e9d5f634b55f1c9a1428ba85e7a587f to your computer and use it in GitHub Desktop.
Save candh/9e9d5f634b55f1c9a1428ba85e7a587f to your computer and use it in GitHub Desktop.
opengl.c template for mac, linux and windows.
#ifdef __APPLE__
#define GL_SILENCE_DEPRECATION
#include <GLUT/glut.h>
#else
#ifdef _WIN32
#include <window.h>
#endif
// linux and win
#include <GL/glut.h>
#endif
#include <stdio.h>
void init() {
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
}
void display() {
// axis 100 wide
/* gluOrtho2D(-100, 100, -100, 100); */
// set the bg to black
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
// Draw a Red 1x1 Square centered at origin
/* glBegin(GL_QUADS); // Each set of 4 vertices form a quad */
/* glColor3f(1.0, 0.0, 0.0); // Red */
/* glVertex2f(-0.5, -0.5); // x, y */
/* glVertex2f( 0.5, -0.5); */
/* glVertex2f( 0.5, 0.5); */
/* glVertex2f(-0.5, 0.5); */
/* glEnd(); */
glFlush(); // Render now
}
int main(int argc, char *argv[]) {
glutInit(&argc, argv);
// init function
init();
// make window
glutCreateWindow("My First OpenGL Test");
// call the display function
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment