1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
//
// main.cpp
// GLSTUFF
//
// Created by Nathan Medros on 4/19/14.
// Copyright (c) 2014 Nathan Medros. All rights reserved.
//
#include <iostream>
#include <GLUT/glut.h>
using namespace std;
void init(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(400, 400);
glutCreateWindow("Introduction to OpenGL");
glEnable(GL_DEPTH_TEST);
}
void handleResize(int w, int h){
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (double)w / (double)h, 1.0, 200.0);
}
void draw(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glVertex3f(-0.75f, -0.25f, -5.0f);
glEnd();
glBegin(GL_LINES);
glVertex3f(-1.0f, 1.0f, -5.0f);
glVertex3f(1.0f, -1.0f, -5.0f);
glEnd();
glBegin(GL_TRIANGLES);
glVertex3f(1.5f, 1.0f, -5.0f);
glVertex3f(1.0f, 0.0f, -5.0f);
glVertex3f(0.5f, 1.0f, -5.0f);
glEnd();
glBegin(GL_QUADS);
glVertex3f(-0.5f, -2.0f, -5.0f);
glVertex3f(0.5f, -2.0f, -5.0f);
glVertex3f(0.5f, -1.0f, -5.0f);
glVertex3f(-0.5f, -1.0f, -5.0f);
glEnd();
glutSwapBuffers();
}
int main(int argc, const char * argv[])
{
init(argc, argv); //Initialize rendering
//Set functions for glutMainLoop to call
glutDisplayFunc(draw);
glutReshapeFunc(handleResize);
glutMainLoop(); //Start the main loop. glutMainLoop doesn't return.
return 0; //This line is never reached
}
|