Skip to content

Instantly share code, notes, and snippets.

@Lekensteyn
Last active January 3, 2016 06:29
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 Lekensteyn/8423151 to your computer and use it in GitHub Desktop.
Save Lekensteyn/8423151 to your computer and use it in GitHub Desktop.
/* cc -g -Wall -Wextra -fsanitize=address robot.c -lGL -lglut -lGLU -o robot */
#include <stdio.h> /* for printf of glError */
#include <GL/glut.h>
void display(void) {
glClear(GL_COLOR_BUFFER_BIT);
// draw axis
glLineWidth(2);
glBegin(GL_LINES);
// y-axis
glVertex2i(0, -100);
glVertex2i(0, 100);
// x-axis
glVertex2i(-100, 0);
glVertex2i( 100, 0);
glEnd();
glBegin(GL_TRIANGLES);
// positive Y-axis head (left, right, top)
glVertex2i(-10, 100);
glVertex2i( 10, 100);
glVertex2i( 0, 120);
glEnd();
printf("%s\n", gluErrorString(glGetError()));
glFlush();
// exit(0);
}
void reshape(int w, int h) {
glViewport(0, 0, w, h);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, w, 0.0, h);
//glTranslatef(50, 50, 0);
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(0);
glutInitWindowPosition(100, 100);
glutInitWindowSize(300, 200);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glEnable(GL_LINE_SMOOTH);
//glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glClearColor(1.0, 1.0, 1.0, 1.0);
glColor3f(1.0, 0.0, 0.0);
reshape(300, 200);
glutMainLoop();
return 0;
}
/* vim: set sw=4 ts=4 et: */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment