Created
February 16, 2017 07:31
-
-
Save AmruthPillai/5ef71a8d03cf6c1d55bd5e8d18f4da09 to your computer and use it in GitHub Desktop.
My first house, on OpenGL. One small step for man.
This file contains 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
#include <GL/GLUT.h> | |
void init(float r, float g, float b) { | |
glClearColor(r, g, b, 0.0); | |
glMatrixMode(GL_PROJECTION); | |
gluOrtho2D(0.0, 0.0, 0.0, 0.0); | |
} | |
void display() { | |
glClear(GL_COLOR_BUFFER_BIT); | |
// House | |
// mountains | |
glColor3f(0.0, 1.0, 0.0); | |
glBegin(GL_TRIANGLES); | |
glVertex2f(-1,.5); | |
glVertex2f(-.5,.5); | |
glVertex2f(-.75,.9); | |
glVertex2f(-.5,.5); | |
glVertex2f(0,.5); | |
glVertex2f(-.25,.9); | |
glVertex2f(0,.5); | |
glVertex2f(.5,.5); | |
glVertex2f(.25,.9); | |
glVertex2f(.5,.5); | |
glVertex2f(1,.5); | |
glVertex2f(.75,.9); | |
glEnd(); | |
// chimney | |
glColor3f(1.0, 0.0, 0.0); | |
glBegin(GL_QUADS); | |
glVertex2f(-.05, .30); | |
glVertex2f(-.15, .30); | |
glVertex2f(-.15, 0); | |
glVertex2f(-.05, 0); | |
glEnd(); | |
// house walls | |
glBegin(GL_QUADS); | |
glVertex2f(-.25, 0); | |
glVertex2f(.25, 0); | |
glVertex2f(.25, -.75); | |
glVertex2f(-.25, -.75); | |
glEnd(); | |
// roof | |
glColor3f(1.0, 1.0, 0.0); | |
glBegin(GL_TRIANGLES); | |
glVertex2f(-.25, 0); | |
glVertex2f(.25, 0); | |
glVertex2f(0, .25); | |
glEnd(); | |
// door | |
glColor3f(0.0, 0.0, 0.0); | |
glBegin(GL_QUADS); | |
glVertex2f(-.10, -.75); | |
glVertex2f(.10, -.75); | |
glVertex2f(.10, -.40); | |
glVertex2f(-.10, -.40); | |
glEnd(); | |
// open door | |
glColor3f(1.0, 1.0, 0.5); | |
glBegin(GL_QUADS); | |
glVertex2f(-.10, -.75); | |
glVertex2f(.10-.05, -.75-.05); | |
glVertex2f(.10-.05, -.40-.05); | |
glVertex2f(-.10, -.40); | |
glEnd(); | |
// roof window | |
glColor3f(0.0, 0.0, 0.0); | |
glBegin(GL_QUADS); | |
glVertex2f(-.05, .12); | |
glVertex2f(.05, .12); | |
glVertex2f(.05, .02); | |
glVertex2f(-.05, .02); | |
glEnd(); | |
// roof window panes/lines | |
glColor3f(1.0, 1.0, 1.0); | |
glBegin(GL_LINES); | |
glVertex2f(0, .12); | |
glVertex2f(0, .02); | |
glVertex2f(-.05, .065); | |
glVertex2f(.05, .065); | |
glEnd(); | |
glFlush(); | |
} | |
void main(int argc, char *argv[]) { | |
glutInit(&argc, argv); | |
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); | |
glutInitWindowSize(500, 500); | |
glutInitWindowPosition(0, 0); | |
glutCreateWindow("This is an OpenGL Window!"); | |
init(0.0, 0.5, 1.0); | |
glutDisplayFunc(display); | |
glutMainLoop(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment