Repository navigation
Expand file tree
/
Copy pathmoreteapots.cpp
More file actions
executable file
·114 lines (99 loc) · 2.71 KB
/
Copy pathmoreteapots.cpp
File metadata and controls
executable file
·114 lines (99 loc) · 2.71 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <cstdlib>
// for mac osx
#ifdef __APPLE__
#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
// only for windows
#ifdef _WIN32
#include <windows.h>
#endif
// for windows and linux
#include <GL/freeglut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#endif
#include <iostream>
using namespace std;
void display()
{
// clear window
glClear(GL_COLOR_BUFFER_BIT);
// set current matrix as GL_MODELVIEW
glMatrixMode(GL_MODELVIEW);
// draw scene
glLoadIdentity();
// add a copy of the curr. matrix to the stack
glPushMatrix();
glPushMatrix();
gluLookAt(.0, .0, 5., .0, .0, -1., .0, 1., .0);
// translate by -3 on the z
glTranslatef(.0f, .0f, -3.f);
// set drawing color to red
glColor3f(1.0f, 0.0f, 0.0f);
// middle red teapot
glutWireTeapot(1);
// translate by 2 on the y
glTranslatef(.0f, 2.f, .0f);
// set drawing color to green
glColor3f(.0f, 1.0f, .0f);
// rotate 90 deg around x
glRotatef(90.f, 1.0f, 0.0f, 0.0f);
// top green teapot
glutWireTeapot(1);
// pop the current matrix
glPopMatrix();
// translate -2 on y and -1 on z
glTranslatef(.0f, -2.f, -1.f);
// set drawing color to blue
glColor3f(.0f, .0f, 1.f);
// bottom blue teapot
glutWireTeapot(1);
// pop the current matrix
glPopMatrix();
// flush drawing routines to the window
glFlush();
}
// Function called everytime a key is pressed
void key(unsigned char key, int, int)
{
switch(key)
{
case 27:
case 'q': exit(EXIT_SUCCESS); break;
default: break;
}
glutPostRedisplay();
}
void reshape(int width, int height)
{
// define the viewport transformation
glViewport(0, 0, width, height);
}
int main(int argc, char* argv[])
{
// initialize GLUT, using any commandline parameters passed to the program
glutInit(&argc, argv);
// setup the size, position, and display mode for new windows
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutInitDisplayMode(GLUT_RGB);
// create and set up a window
glutCreateWindow("hello, teapot!");
// Set up the callback functions
// for display
glutDisplayFunc(display);
// for the keyboard
glutKeyboardFunc(key);
// for reshaping
glutReshapeFunc(reshape);
// define the projection transformation
glMatrixMode(GL_PROJECTION);
gluPerspective(60, 1, 1, 10);
// define the viewing transformation
glMatrixMode(GL_MODELVIEW);
// glLoadIdentity();
// tell GLUT to wait for events
glutMainLoop();
}