Skip to content

Instantly share code, notes, and snippets.

@Suvink
Created May 28, 2020 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Suvink/5fd314b7599ff72165af9b5d4bb11466 to your computer and use it in GitHub Desktop.
Save Suvink/5fd314b7599ff72165af9b5d4bb11466 to your computer and use it in GitHub Desktop.
This is the way of implementing the following tutorial in C. (https://services.suvink.me/opengl-c)
#include<stdio.h>
#include <OpenGL/gl.h>
#include <GLUT/glut.h>
void myInit (void){
glClearColor(1.0, 1.0, 0.0, 1.0);
glColor3f(0.2, 0.5, 0.4);
glPointSize(10.0);
gluOrtho2D(0, 500, 0, 500);
}
void display(void){
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
glVertex2f(100, 100);
glVertex2f(300, 200);
glEnd();
glBegin( GL_QUADS );
glVertex2f( 100.0, 100.0 );
glVertex2f( 300.0, 100.0 );
glVertex2f( 300.0, 200.0 );
glVertex2f( 100.0, 200.0 );
glEnd();
glBegin( GL_TRIANGLE_STRIP );
glVertex2f( 100.0, 210.0 );
glVertex2f( 300.0, 210.0 );
glVertex2f( 300.0, 310.0 );
glEnd();
glFlush();
}
int main (int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("Python Code 1");
myInit();
glutDisplayFunc(display);
glutMainLoop();
}
/*
Run this with following format
gcc filename.c -o filename -framework OpenGL -framework GLUT
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment