Repository navigation
Expand file tree
/
Copy pathhelloteapot.cpp
More file actions
executable file
·92 lines (81 loc) · 1.97 KB
/
Copy pathhelloteapot.cpp
File metadata and controls
executable file
·92 lines (81 loc) · 1.97 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
#include <algorithm>
#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
bool wire_indicator = false;
// function called everytime the windows is refreshed
void display()
{
// clear window
glClear(GL_COLOR_BUFFER_BIT);
// draw scene
if (wire_indicator)
{
glutWireSphere(0.5,50,20);
}else{
glutSolidSphere(0.5,50,20);
}
// flush drawing routines to the window
glFlush();
}
// Function called everytime a key is pressed
void key(unsigned char key, int, int)
{
switch(key)
{
// the 'esc' key
case 27:
// the 'q' key
case 'q': exit(EXIT_SUCCESS); break;
case 'w': wire_indicator = !wire_indicator; break;
default: break;
}
glutPostRedisplay();
}
// Function called every time the main window is resized
void reshape(int width, int height)
{
// define the viewport transformation;
//def box pour garder l'aspect ratio
int length_box = width;
if (width > height)
{
length_box = height;
}
glViewport(width/2 - length_box/2, height/2 - length_box/2, length_box, length_box);
}
// Main routine
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);
// tell GLUT to wait for events
glutMainLoop();
}