/
menu.cpp
102 lines (90 loc) · 1.82 KB
/
menu.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
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
#include "menu.h"
#include "util.h"
#include <iostream>
void createMenu(void){
int lights_id = glutCreateMenu(menu);
glutAddMenuEntry( "Light one", LIGHT_ONE );
glutAddMenuEntry( "Light two", LIGHT_TWO );
int shading_id = glutCreateMenu(menu);
glutAddMenuEntry( "Flat shading", FLAT_SHADING );
glutAddMenuEntry( "Smooth shading", SMOOTH_SHADING );
int exponent_id = glutCreateMenu(menu);
glutAddMenuEntry( "2", PHONG_2 );
glutAddMenuEntry( "8", PHONG_8 );
glutAddMenuEntry( "16", PHONG_16);
glutAddMenuEntry( "64", PHONG_64);
int menu_id = glutCreateMenu(menu);
glutAddSubMenu("Lights", lights_id);
glutAddSubMenu("Shading", shading_id);
glutAddSubMenu("Phong exponent", exponent_id);
// Let the menu respond on the right mouse button
glutAttachMenu( GLUT_LEFT_BUTTON );
}
void menu(int value)
{
switch( value )
{
case LIGHT_ONE:
lightOne();
break;
case LIGHT_TWO:
lightTwo();
break;
case FLAT_SHADING:
glShadeModel( GL_FLAT );
break;
case SMOOTH_SHADING:
glShadeModel( GL_SMOOTH );
break;
case PHONG_2:
exponent = 2;
glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, exponent);
break;
case PHONG_8:
exponent = 8;
glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, exponent);
break;
case PHONG_16:
exponent = 16;
glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, exponent);
break;
case PHONG_64:
exponent = 64;
glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, exponent);
break;
default:
break;
}
// you would want to redraw now
glutPostRedisplay();
}
void lightOne()
{
if(l1)
{
glDisable( GL_LIGHT0 );
l1 = false;
}
else
{
glEnable( GL_LIGHT0 );
l1 = true;
}
}
void lightTwo()
{
if(l2)
{
glDisable( GL_LIGHT1 );
l2 = false;
}
else
{
glEnable( GL_LIGHT1 );
l2 = true;
}
}
void lightsOff()
{
glDisable( GL_LIGHTING );
}