This repository has been archived by the owner on Dec 21, 2018. It is now read-only.
/
lamp.cpp
98 lines (78 loc) · 1.9 KB
/
lamp.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
/*
* lamp.cpp
* cottages
*
* Created by Bartlomiej Kozal on 08/06/2010.
* Copyright 2010 Bartlomiej Kozal. All rights reserved.
*
*/
#include "lamp.h"
Lamp::Lamp() {}
void Lamp::draw() {
float mat_ambient[] = {0.02, 0.02, 0.02, 1};
float mat_diffuse[] = {0.01, 0.01, 0.01, 1};
float mat_specular[] = {0.4, 0.4, 0.4, 1};
float high_shininess[] = {0.10};
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
glPushMatrix();
glColor3f(0, 0, 0);
glScalef(0.4, 0.4, 0.4);
glutSolidCube(0.3);
glTranslated(0, 1.3, 0);
glPushMatrix();
glTranslated(0, 2, 0);
glDisable(GL_LIGHTING);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1, 0.8, 0, 0.5);
glutSolidSphere(0.1, 10, 10);
glEnable(GL_LIGHTING);
glPopMatrix();
glPushMatrix();
glScalef(0.1, 3, 0.1);
glutSolidCube(1);
glPopMatrix();
glTranslated(0, 2, 0);
glScalef(1, 2, 1);
glColor3f(1, 1, 1);
glutWireCube(0.5);
// glass
glDisable(GL_LIGHTING);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(0, 0.5, 0.5, 0.5);
glScalef(0.25, 0.25, 0.25);
glTranslated(0, -1, 0);
glBegin(GL_QUADS);
glVertex3f(-1, 0, 1);
glVertex3f(1, 0, 1);
glVertex3f(1, 0, -1);
glVertex3f(-1, 0, -1);
glVertex3f(-1, 2, 1);
glVertex3f(1, 2, 1);
glVertex3f(1, 2, -1);
glVertex3f(-1, 2, -1);
glVertex3f(-1, 0, 1);
glVertex3f(1, 0, 1);
glVertex3f(1, 2, 1);
glVertex3f(-1, 2, 1);
glVertex3f(-1, 0, -1);
glVertex3f(1, 0, -1);
glVertex3f(1, 2, -1);
glVertex3f(-1, 2, -1);
glVertex3f(-1, 0, 1);
glVertex3f(-1, 0, -1);
glVertex3f(-1, 2, -1);
glVertex3f(-1, 2, 1);
glVertex3f(1, 0, 1);
glVertex3f(1, 0, -1);
glVertex3f(1, 2, -1);
glVertex3f(1, 2, 1);
glEnd();
glEnable(GL_LIGHTING);
glPopMatrix();
glFlush();
}