Skip to content

Instantly share code, notes, and snippets.

@cseas
Created February 10, 2019 06:05
Show Gist options
  • Save cseas/2c6ac3e7802ea883cfe9c2b0b294b5d5 to your computer and use it in GitHub Desktop.
Save cseas/2c6ac3e7802ea883cfe9c2b0b294b5d5 to your computer and use it in GitHub Desktop.
Simple C++ OpenGL program to draw points on a 2D canvas
#include<GL/glut.h>
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_POINTS);
glVertex2f(10.0, 10.0);
glVertex2f(150.0, 80.0);
glVertex2f(100.0, 20.0);
glVertex2f(200.0, 100.0);
glEnd();
glFlush();
}
void myinit() {
glClearColor(1.0, 1.0, 1.0, 1.0);
glColor3f(1.0, 0.0, 0.0);
glPointSize(5.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 499.0, 0.0, 499.0);
}
void main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutCreateWindow("Points");
glutDisplayFunc(display);
myinit();
glutMainLoop();
}
Copy link

ghost commented Dec 18, 2020

Please help me, it fails to include GLUT in my program for some reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment