forked from sergioruiz/cgcourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCG_Demo.cpp
69 lines (60 loc) · 2.31 KB
/
CG_Demo.cpp
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
/*
* Sergio Ruiz.
*
* TC3022. Computer Graphics Course.
* Basic template OpenGL project.
*/
#ifdef __APPLE__
// See: http://lnx.cx/docs/opengl-in-xcode/
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#else
#include "freeglut.h"
#endif
#include <stdio.h>
#include <math.h>
void init() // FOR GLUT LOOP
{
glEnable(GL_DEPTH_TEST); // Enable check for close and far objects.
glClearColor(0.0, 0.0, 0.0, 0.0); // Clear the color state.
glMatrixMode(GL_MODELVIEW); // Go to 3D mode.
glLoadIdentity(); // Reset 3D view matrix.
}
void display() // Called for each frame (about 60 times per second).
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear color and depth buffers.
glColor3f(1.0f, 1.0f, 0.0f); // Yellow
glutWireTeapot(1);
glutSwapBuffers(); // Swap the hidden and visible buffers.
}
void idle() // Called when drawing is finished.
{
glutPostRedisplay(); // Display again.
}
void reshape(int x, int y) // Called when the window geometry changes.
{
glMatrixMode(GL_PROJECTION); // Go to 2D mode.
glLoadIdentity(); // Reset the 2D matrix.
gluPerspective(40.0, (GLdouble)x / (GLdouble)y, 0.5, 50.0); // Configure the camera lens aperture.
glMatrixMode(GL_MODELVIEW); // Go to 3D mode.
glLoadIdentity(); // Reset the 3D matrix.
glViewport(0, 0, x, y); // Configure the camera frame dimensions.
gluLookAt(0.0, 5.0, 5.0, // Where the camera is.
0.0, 0.0, 0.0, // To where the camera points at.
0.0, 1.0, 0.0); // "UP" vector.
display();
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv); // Init GLUT with command line parameters.
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB); // Use 2 buffers (hidden and visible). Use the depth buffer. Use 3 color channels.
glutInitWindowSize(800, 800);
glutCreateWindow("CG DEMO");
init();
glutReshapeFunc(reshape); // Reshape CALLBACK function.
glutDisplayFunc(display); // Display CALLBACK function.
glutIdleFunc(idle); // Idle CALLBACK function.
glutMainLoop(); // Begin graphics program.
return 0; // ANSI C requires a return value.
}