xref: /haiku/src/apps/glteapot/GLObject.cpp (revision e18a08119d6f8e0a1cdab67c967b416272b8bc15)
1c8c44fa0SJérôme Duval /*
2552bd60cSAlexandre Deckner  * Copyright 2008 Haiku Inc. All rights reserved.
3552bd60cSAlexandre Deckner  * Distributed under the terms of the MIT License.
4552bd60cSAlexandre Deckner  *
5552bd60cSAlexandre Deckner  * Authors:
6552bd60cSAlexandre Deckner  *		Alexandre Deckner
7552bd60cSAlexandre Deckner  *
8552bd60cSAlexandre Deckner  */
9552bd60cSAlexandre Deckner 
10552bd60cSAlexandre Deckner /*
11552bd60cSAlexandre Deckner  * Original Be Sample source modified to use a quaternion for the object's orientation
12552bd60cSAlexandre Deckner  */
13552bd60cSAlexandre Deckner 
14552bd60cSAlexandre Deckner /*
15c8c44fa0SJérôme Duval 	Copyright 1999, Be Incorporated.   All Rights Reserved.
16c8c44fa0SJérôme Duval 	This file may be used under the terms of the Be Sample Code License.
17c8c44fa0SJérôme Duval */
18c8c44fa0SJérôme Duval 
191bc51c23SAleksas Pantechovskis 
20c8c44fa0SJérôme Duval #include "GLObject.h"
211bc51c23SAleksas Pantechovskis 
221bc51c23SAleksas Pantechovskis #include <Application.h>
23be98a602SStefano Ceccherini #include <GL/gl.h>
24be98a602SStefano Ceccherini #include <InterfaceKit.h>
251bc51c23SAleksas Pantechovskis #include <Resources.h>
261bc51c23SAleksas Pantechovskis 
27c8c44fa0SJérôme Duval #include "glob.h"
28c8c44fa0SJérôme Duval 
291bc51c23SAleksas Pantechovskis 
30c8c44fa0SJérôme Duval struct material {
31c8c44fa0SJérôme Duval 	float ambient[3], diffuse[3], specular[3];
32c8c44fa0SJérôme Duval };
33c8c44fa0SJérôme Duval 
34be98a602SStefano Ceccherini float *colors[] = {NULL, white, yellow, blue, red, green};
35c8c44fa0SJérôme Duval 
36c8c44fa0SJérôme Duval material materials[] = {
37c8c44fa0SJérôme Duval 	// Null
38c8c44fa0SJérôme Duval 	{
39c8c44fa0SJérôme Duval 		{0.1745, 0.03175, 0.03175},
40c8c44fa0SJérôme Duval 		{0.61424, 0.10136, 0.10136},
41c8c44fa0SJérôme Duval 		{0.727811, 0.626959, 0.626959}
42c8c44fa0SJérôme Duval 	},
43c8c44fa0SJérôme Duval 	// White
44c8c44fa0SJérôme Duval 	{
45c8c44fa0SJérôme Duval 		{0.1745, 0.1745, 0.1745},
46c8c44fa0SJérôme Duval 		{0.61424, 0.61424, 0.61424},
47c8c44fa0SJérôme Duval 		{0.727811, 0.727811, 0.727811}
48c8c44fa0SJérôme Duval 	},
49c8c44fa0SJérôme Duval 	// Yellow
50c8c44fa0SJérôme Duval 	{
51c8c44fa0SJérôme Duval 		{0.1745, 0.1745, 0.03175},
52c8c44fa0SJérôme Duval 		{0.61424, 0.61424, 0.10136},
53c8c44fa0SJérôme Duval 		{0.727811, 0.727811, 0.626959}
54c8c44fa0SJérôme Duval 	},
55c8c44fa0SJérôme Duval 	// Blue
56c8c44fa0SJérôme Duval 	{
57c8c44fa0SJérôme Duval 		{0.03175, 0.03175, 0.1745},
58c8c44fa0SJérôme Duval 		{0.10136, 0.10136, 0.61424},
59c8c44fa0SJérôme Duval 		{0.626959, 0.626959, 0.727811}
60c8c44fa0SJérôme Duval 	},
61c8c44fa0SJérôme Duval 	// Red
62c8c44fa0SJérôme Duval 	{
63c8c44fa0SJérôme Duval 		{0.1745, 0.03175, 0.03175},
64c8c44fa0SJérôme Duval 		{0.61424, 0.10136, 0.10136},
65c8c44fa0SJérôme Duval 		{0.727811, 0.626959, 0.626959}
66c8c44fa0SJérôme Duval 	},
67c8c44fa0SJérôme Duval 	// Green
68c8c44fa0SJérôme Duval 	{
69c8c44fa0SJérôme Duval 		{0.03175, 0.1745, 0.03175},
70c8c44fa0SJérôme Duval 		{0.10136, 0.61424, 0.10136},
71c8c44fa0SJérôme Duval 		{0.626959, 0.727811, 0.626959}
72c8c44fa0SJérôme Duval 	},
73c8c44fa0SJérôme Duval };
74c8c44fa0SJérôme Duval 
75c8c44fa0SJérôme Duval #define USE_QUAD_STRIPS 1
76c8c44fa0SJérôme Duval 
77c8c44fa0SJérôme Duval extern long setEvent(sem_id event);
78c8c44fa0SJérôme Duval 
79be98a602SStefano Ceccherini 
GLObject(ObjectView * ov)80c8c44fa0SJérôme Duval GLObject::GLObject(ObjectView* ov)
8163355585SIngo Weinhold 	:
82be98a602SStefano Ceccherini 	x(0),
83be98a602SStefano Ceccherini 	y(0),
84be98a602SStefano Ceccherini 	z(-2.0),
85552bd60cSAlexandre Deckner 	fRotation(0.0f, 0.0f, 0.0f, 1.0f),
86552bd60cSAlexandre Deckner 	spinX(2),
87552bd60cSAlexandre Deckner 	spinY(2),
88be98a602SStefano Ceccherini 	solidity(0),
89450bb3e5SStephan Aßmus 	color(4),
90be98a602SStefano Ceccherini 	changed(false),
91450bb3e5SStephan Aßmus 	fObjView(ov)
92c8c44fa0SJérôme Duval {
93450bb3e5SStephan Aßmus }
94c8c44fa0SJérôme Duval 
95be98a602SStefano Ceccherini 
~GLObject()96c8c44fa0SJérôme Duval GLObject::~GLObject()
97c8c44fa0SJérôme Duval {
98450bb3e5SStephan Aßmus }
99c8c44fa0SJérôme Duval 
100be98a602SStefano Ceccherini 
101be98a602SStefano Ceccherini void
MenuInvoked(BPoint point)102be98a602SStefano Ceccherini GLObject::MenuInvoked(BPoint point)
103c8c44fa0SJérôme Duval {
104c8c44fa0SJérôme Duval 	BPopUpMenu* m = new BPopUpMenu("Object",false,false);
105c8c44fa0SJérôme Duval 	BMenuItem* i;
106c8c44fa0SJérôme Duval 
107c8c44fa0SJérôme Duval 	int c = 1;
108c8c44fa0SJérôme Duval 	m->AddItem(i = new BMenuItem("White",NULL));
109c8c44fa0SJérôme Duval 	if (color == c++)
110c8c44fa0SJérôme Duval 		i->SetMarked(true);
111c8c44fa0SJérôme Duval 	m->AddItem(i = new BMenuItem("Yellow",NULL));
112c8c44fa0SJérôme Duval 	if (color == c++)
113c8c44fa0SJérôme Duval 		i->SetMarked(true);
114c8c44fa0SJérôme Duval 	m->AddItem(i = new BMenuItem("Blue",NULL));
115c8c44fa0SJérôme Duval 	if (color == c++)
116c8c44fa0SJérôme Duval 		i->SetMarked(true);
117c8c44fa0SJérôme Duval 	m->AddItem(i = new BMenuItem("Red",NULL));
118c8c44fa0SJérôme Duval 	if (color == c++)
119c8c44fa0SJérôme Duval 		i->SetMarked(true);
120c8c44fa0SJérôme Duval 	m->AddItem(i = new BMenuItem("Green",NULL));
121c8c44fa0SJérôme Duval 	if (color == c++)
122c8c44fa0SJérôme Duval 		i->SetMarked(true);
123c8c44fa0SJérôme Duval 	m->AddSeparatorItem();
124c8c44fa0SJérôme Duval 
125c8c44fa0SJérôme Duval 	c = 0;
126c8c44fa0SJérôme Duval 	m->AddItem(i = new BMenuItem("Solid",NULL));
127c8c44fa0SJérôme Duval 	if (solidity == c++)
128c8c44fa0SJérôme Duval 		i->SetMarked(true);
129c8c44fa0SJérôme Duval 	m->AddItem(i = new BMenuItem("Translucent",NULL));
130c8c44fa0SJérôme Duval 	if (solidity == c++)
131c8c44fa0SJérôme Duval 		i->SetMarked(true);
132c8c44fa0SJérôme Duval 	m->AddItem(i = new BMenuItem("Transparent",NULL));
133c8c44fa0SJérôme Duval 	if (solidity == c++)
134c8c44fa0SJérôme Duval 		i->SetMarked(true);
135c8c44fa0SJérôme Duval 
136c8c44fa0SJérôme Duval 	i = m->Go(point);
137c8c44fa0SJérôme Duval 	int32 index = m->IndexOf(i);
138c8c44fa0SJérôme Duval 	delete m;
139c8c44fa0SJérôme Duval 
140c8c44fa0SJérôme Duval 	if (index < 5) {
141c8c44fa0SJérôme Duval 		color = index+1;
142c8c44fa0SJérôme Duval 	} else if (index > 5) {
143c8c44fa0SJérôme Duval 		solidity = index-6;
144450bb3e5SStephan Aßmus 	}
145c8c44fa0SJérôme Duval 	changed = true;
146450bb3e5SStephan Aßmus 	setEvent(fObjView->drawEvent);
147450bb3e5SStephan Aßmus }
148c8c44fa0SJérôme Duval 
1491bc51c23SAleksas Pantechovskis 
150552bd60cSAlexandre Deckner int
Solidity() const151552bd60cSAlexandre Deckner GLObject::Solidity() const
152552bd60cSAlexandre Deckner {
153552bd60cSAlexandre Deckner 	return solidity;
154552bd60cSAlexandre Deckner }
155552bd60cSAlexandre Deckner 
156be98a602SStefano Ceccherini 
1571bc51c23SAleksas Pantechovskis 
158be98a602SStefano Ceccherini bool
SpinIt()159be98a602SStefano Ceccherini GLObject::SpinIt()
160c8c44fa0SJérôme Duval {
161c8c44fa0SJérôme Duval 	bool c = changed;
162552bd60cSAlexandre Deckner 	c = c || ((spinX != 0.0f) || (spinY != 0.0f));
163552bd60cSAlexandre Deckner 
164552bd60cSAlexandre Deckner 	if (c)
165552bd60cSAlexandre Deckner 		RotateWorldSpace(spinY, spinX);
166c8c44fa0SJérôme Duval 
167c8c44fa0SJérôme Duval 	return c;
168450bb3e5SStephan Aßmus }
169c8c44fa0SJérôme Duval 
170be98a602SStefano Ceccherini 
171be98a602SStefano Ceccherini void
Spin(float rx,float ry)172552bd60cSAlexandre Deckner GLObject::Spin(float rx, float ry)
173552bd60cSAlexandre Deckner {
174552bd60cSAlexandre Deckner 	spinX = rx;
175552bd60cSAlexandre Deckner 	spinY = ry;
176552bd60cSAlexandre Deckner }
177552bd60cSAlexandre Deckner 
178552bd60cSAlexandre Deckner 
179552bd60cSAlexandre Deckner void
RotateWorldSpace(float rx,float ry)180552bd60cSAlexandre Deckner GLObject::RotateWorldSpace(float rx, float ry)
181552bd60cSAlexandre Deckner {
182552bd60cSAlexandre Deckner 	fRotation = Quaternion(Vector3(0.0f, 1.0f, 0.0f), 0.01f * rx) * fRotation;
183552bd60cSAlexandre Deckner 	fRotation = Quaternion(Vector3(1.0f, 0.0f, 0.0f), 0.01f * ry) * fRotation;
184*e18a0811SX512 	fRotation.normalize();
185552bd60cSAlexandre Deckner 	changed = true;
186552bd60cSAlexandre Deckner }
187552bd60cSAlexandre Deckner 
188552bd60cSAlexandre Deckner 
189552bd60cSAlexandre Deckner void
Draw(bool forID,float IDcolor[])190be98a602SStefano Ceccherini GLObject::Draw(bool forID, float IDcolor[])
191c8c44fa0SJérôme Duval {
192c8c44fa0SJérôme Duval 	glPushMatrix();
193c8c44fa0SJérôme Duval 		glTranslatef(x, y, z);
194552bd60cSAlexandre Deckner 
195552bd60cSAlexandre Deckner 		float mat[4][4];
196552bd60cSAlexandre Deckner 		fRotation.toOpenGLMatrix(mat);
197552bd60cSAlexandre Deckner 		glMultMatrixf((GLfloat*)mat);
198c8c44fa0SJérôme Duval 
199c8c44fa0SJérôme Duval 		if (forID) {
200c8c44fa0SJérôme Duval 			glColor3fv(IDcolor);
201450bb3e5SStephan Aßmus 		}
202c8c44fa0SJérôme Duval 
203c8c44fa0SJérôme Duval 		DoDrawing(forID);
204c8c44fa0SJérôme Duval 
205c8c44fa0SJérôme Duval 	glPopMatrix();
206c8c44fa0SJérôme Duval 
207c8c44fa0SJérôme Duval 	changed = false;
208450bb3e5SStephan Aßmus }
209c8c44fa0SJérôme Duval 
210be98a602SStefano Ceccherini 
TriangleObject(ObjectView * ov)2111bc51c23SAleksas Pantechovskis TriangleObject::TriangleObject(ObjectView* ov)
2121bc51c23SAleksas Pantechovskis 		:
2131bc51c23SAleksas Pantechovskis 		GLObject(ov),
2141bc51c23SAleksas Pantechovskis 		fStatus(B_NO_INIT),
215450bb3e5SStephan Aßmus 		fPoints(100, 100),
216450bb3e5SStephan Aßmus 		fTriangles(100, 100),
217450bb3e5SStephan Aßmus 		fQs(50, 50)
218c8c44fa0SJérôme Duval {
2191bc51c23SAleksas Pantechovskis 	BResources *res = BApplication::AppResources();
2201bc51c23SAleksas Pantechovskis 	if (res == NULL)
2211bc51c23SAleksas Pantechovskis 		return;
222c8c44fa0SJérôme Duval 
2231bc51c23SAleksas Pantechovskis 	size_t size = 0;
2241bc51c23SAleksas Pantechovskis 	int32 *arrayOfPoints
2251bc51c23SAleksas Pantechovskis 					= (int32*)res->LoadResource(B_RAW_TYPE, "points", &size);
2261bc51c23SAleksas Pantechovskis 	if (arrayOfPoints == NULL)
2271bc51c23SAleksas Pantechovskis 		return;
2281bc51c23SAleksas Pantechovskis 
2291bc51c23SAleksas Pantechovskis 	float maxp = 0;
2301bc51c23SAleksas Pantechovskis 	size_t numPt = size / sizeof(int32);
2311bc51c23SAleksas Pantechovskis 	for (size_t i = 0; i < numPt; i += 6) {
232c8c44fa0SJérôme Duval 		point p;
2331bc51c23SAleksas Pantechovskis 		p.x = 1e-6 * arrayOfPoints[i];
2341bc51c23SAleksas Pantechovskis 		p.y = 1e-6 * arrayOfPoints[i + 1];
2351bc51c23SAleksas Pantechovskis 		p.z = 1e-6 * arrayOfPoints[i + 2];
2361bc51c23SAleksas Pantechovskis 		p.nx = 1e-6 * arrayOfPoints[i + 3];
2371bc51c23SAleksas Pantechovskis 		p.ny = 1e-6 * arrayOfPoints[i + 4];
2381bc51c23SAleksas Pantechovskis 		p.nz = 1e-6 * arrayOfPoints[i + 5];
2391bc51c23SAleksas Pantechovskis 
240c8c44fa0SJérôme Duval 		if (fabs(p.x) > maxp)
241c8c44fa0SJérôme Duval 			maxp = fabs(p.x);
242c8c44fa0SJérôme Duval 		if (fabs(p.y) > maxp)
243c8c44fa0SJérôme Duval 			maxp = fabs(p.y);
244c8c44fa0SJérôme Duval 		if (fabs(p.z) > maxp)
245c8c44fa0SJérôme Duval 			maxp = fabs(p.z);
2461bc51c23SAleksas Pantechovskis 
247450bb3e5SStephan Aßmus 		fPoints.add(p);
248450bb3e5SStephan Aßmus 	}
249450bb3e5SStephan Aßmus 
250450bb3e5SStephan Aßmus 	for (int i = 0; i < fPoints.num_items; i++) {
251450bb3e5SStephan Aßmus 		fPoints[i].x /= maxp;
252450bb3e5SStephan Aßmus 		fPoints[i].y /= maxp;
253450bb3e5SStephan Aßmus 		fPoints[i].z /= maxp;
254450bb3e5SStephan Aßmus 	}
255c8c44fa0SJérôme Duval 
2561bc51c23SAleksas Pantechovskis 	int32 *arrayOfTriangles
2571bc51c23SAleksas Pantechovskis 					= (int32*)res->LoadResource(B_RAW_TYPE, "triangles", &size);
2581bc51c23SAleksas Pantechovskis 	if (arrayOfTriangles == NULL)
2591bc51c23SAleksas Pantechovskis 		return;
2601bc51c23SAleksas Pantechovskis 
2611bc51c23SAleksas Pantechovskis 	size_t numTriPoints = size / sizeof(int32);
2621bc51c23SAleksas Pantechovskis 	for (size_t i = 0; i < numTriPoints; i += 3) {
263c8c44fa0SJérôme Duval 		tri t;
2641bc51c23SAleksas Pantechovskis 		t.p1 = arrayOfTriangles[i];
2651bc51c23SAleksas Pantechovskis 		t.p2 = arrayOfTriangles[i + 1];
2661bc51c23SAleksas Pantechovskis 		t.p3 = arrayOfTriangles[i + 2];
267450bb3e5SStephan Aßmus 		fTriangles.add(t);
268450bb3e5SStephan Aßmus 	}
269c8c44fa0SJérôme Duval 
2701bc51c23SAleksas Pantechovskis 	size_t numTri = numTriPoints / 3;
2711bc51c23SAleksas Pantechovskis 
272c8c44fa0SJérôme Duval 	int qpts = 4;
273c8c44fa0SJérôme Duval 	int qp[1024];
274c8c44fa0SJérôme Duval 	quadStrip q;
275c8c44fa0SJérôme Duval 	q.pts = qp;
276c8c44fa0SJérôme Duval 	q.numpts = 4;
277450bb3e5SStephan Aßmus 	q.pts[2] = fTriangles[0].p1;
278450bb3e5SStephan Aßmus 	q.pts[0] = fTriangles[0].p2;
279450bb3e5SStephan Aßmus 	q.pts[1] = fTriangles[0].p3;
280450bb3e5SStephan Aßmus 	q.pts[3] = fTriangles[1].p3;
281c8c44fa0SJérôme Duval 
2821bc51c23SAleksas Pantechovskis 	for (size_t i = 2; i < numTri; i += 2) {
283450bb3e5SStephan Aßmus 		if ((fTriangles[i - 1].p1 == fTriangles[i].p2) &&
284450bb3e5SStephan Aßmus 			(fTriangles[i - 1].p3 == fTriangles[i].p3)) {
285450bb3e5SStephan Aßmus 			q.pts[q.numpts++] = fTriangles[i + 1].p1;
286450bb3e5SStephan Aßmus 			q.pts[q.numpts++] = fTriangles[i + 1].p3;
287c8c44fa0SJérôme Duval 			qpts+=2;
288c8c44fa0SJérôme Duval 		} else {
289c8c44fa0SJérôme Duval 			int *np = (int*)malloc(sizeof(int)*q.numpts);
290c8c44fa0SJérôme Duval 			memcpy(np, qp, q.numpts * sizeof(int));
291c8c44fa0SJérôme Duval 			quadStrip nqs;
292c8c44fa0SJérôme Duval 			nqs.numpts = q.numpts;
293c8c44fa0SJérôme Duval 			nqs.pts = np;
294450bb3e5SStephan Aßmus 			fQs.add(nqs);
295c8c44fa0SJérôme Duval 
296c8c44fa0SJérôme Duval 			qpts += 4;
297c8c44fa0SJérôme Duval 			q.numpts = 4;
298450bb3e5SStephan Aßmus 			q.pts[2] = fTriangles[i].p1;
299450bb3e5SStephan Aßmus 			q.pts[0] = fTriangles[i].p2;
300450bb3e5SStephan Aßmus 			q.pts[1] = fTriangles[i].p3;
301450bb3e5SStephan Aßmus 			q.pts[3] = fTriangles[i + 1].p3;
302450bb3e5SStephan Aßmus 		}
303450bb3e5SStephan Aßmus 	}
304c8c44fa0SJérôme Duval 
305c8c44fa0SJérôme Duval 	int* np = (int*)malloc(sizeof(int)*q.numpts);
306c8c44fa0SJérôme Duval 	memcpy(np, qp, q.numpts * sizeof(int));
307c8c44fa0SJérôme Duval 	quadStrip nqs;
308c8c44fa0SJérôme Duval 	nqs.numpts = q.numpts;
309c8c44fa0SJérôme Duval 	nqs.pts = np;
310450bb3e5SStephan Aßmus 	fQs.add(nqs);
311c8c44fa0SJérôme Duval 
3121bc51c23SAleksas Pantechovskis 	fStatus = B_OK;
313450bb3e5SStephan Aßmus }
314c8c44fa0SJérôme Duval 
315be98a602SStefano Ceccherini 
~TriangleObject()316c8c44fa0SJérôme Duval TriangleObject::~TriangleObject()
317c8c44fa0SJérôme Duval {
318450bb3e5SStephan Aßmus 	for (int i = 0; i < fQs.num_items; i++) {
319450bb3e5SStephan Aßmus 		free(fQs[i].pts);
320450bb3e5SStephan Aßmus 	}
321450bb3e5SStephan Aßmus }
322c8c44fa0SJérôme Duval 
323be98a602SStefano Ceccherini 
3241bc51c23SAleksas Pantechovskis status_t
InitCheck() const3251bc51c23SAleksas Pantechovskis TriangleObject::InitCheck() const
3261bc51c23SAleksas Pantechovskis {
3271bc51c23SAleksas Pantechovskis 	return fStatus;
3281bc51c23SAleksas Pantechovskis }
3291bc51c23SAleksas Pantechovskis 
3301bc51c23SAleksas Pantechovskis 
331be98a602SStefano Ceccherini void
DoDrawing(bool forID)332be98a602SStefano Ceccherini TriangleObject::DoDrawing(bool forID)
333c8c44fa0SJérôme Duval {
334c8c44fa0SJérôme Duval 	if (!forID) {
335c8c44fa0SJérôme Duval 		float c[3][4];
336c8c44fa0SJérôme Duval 		c[0][0] = materials[color].ambient[0];
337c8c44fa0SJérôme Duval 		c[0][1] = materials[color].ambient[1];
338c8c44fa0SJérôme Duval 		c[0][2] = materials[color].ambient[2];
339c8c44fa0SJérôme Duval 		c[1][0] = materials[color].diffuse[0];
340c8c44fa0SJérôme Duval 		c[1][1] = materials[color].diffuse[1];
341c8c44fa0SJérôme Duval 		c[1][2] = materials[color].diffuse[2];
342c8c44fa0SJérôme Duval 		c[2][0] = materials[color].specular[0];
343c8c44fa0SJérôme Duval 		c[2][1] = materials[color].specular[1];
344c8c44fa0SJérôme Duval 		c[2][2] = materials[color].specular[2];
345c8c44fa0SJérôme Duval 
346c8c44fa0SJérôme Duval 		float alpha = 1;
347c8c44fa0SJérôme Duval 		if (solidity == 0)
348c8c44fa0SJérôme Duval 			alpha = 1.0;
349c8c44fa0SJérôme Duval 		else if (solidity == 1)
350c8c44fa0SJérôme Duval 			alpha = 0.95;
351c8c44fa0SJérôme Duval 		else if (solidity == 2)
352c8c44fa0SJérôme Duval 			alpha = 0.6;
353c8c44fa0SJérôme Duval 		c[0][3] = c[1][3] = c[2][3] = alpha;
354c8c44fa0SJérôme Duval 		if (solidity != 0) {
355c8c44fa0SJérôme Duval 			glBlendFunc(GL_SRC_ALPHA,GL_ONE);
356c8c44fa0SJérôme Duval 			glEnable(GL_BLEND);
357c8c44fa0SJérôme Duval 			glDepthMask(GL_FALSE);
358c8c44fa0SJérôme Duval 			glDisable(GL_CULL_FACE);
359c8c44fa0SJérôme Duval 		} else {
360c8c44fa0SJérôme Duval 			glDisable(GL_BLEND);
361c8c44fa0SJérôme Duval 			glDepthMask(GL_TRUE);
362450bb3e5SStephan Aßmus 		}
363c8c44fa0SJérôme Duval 		glMaterialfv(GL_FRONT, GL_AMBIENT, c[0]);
364c8c44fa0SJérôme Duval 		glMaterialfv(GL_FRONT, GL_DIFFUSE, c[1]);
365c8c44fa0SJérôme Duval 		glMaterialfv(GL_FRONT, GL_SPECULAR, c[2]);
366c8c44fa0SJérôme Duval 	} else {
367c8c44fa0SJérôme Duval 		glDisable(GL_BLEND);
368c8c44fa0SJérôme Duval 		glDepthMask(GL_TRUE);
369450bb3e5SStephan Aßmus 	}
370c8c44fa0SJérôme Duval 
371c8c44fa0SJérôme Duval #if USE_QUAD_STRIPS
372450bb3e5SStephan Aßmus 		for (int i = 0; i < fQs.num_items; i++) {
373c8c44fa0SJérôme Duval  			glBegin(GL_QUAD_STRIP);
374450bb3e5SStephan Aßmus 			for (int j = 0; j < fQs[i].numpts; j++) {
375c8c44fa0SJérôme Duval  				glNormal3f(
376450bb3e5SStephan Aßmus 					fPoints[fQs[i].pts[j]].nx,
377450bb3e5SStephan Aßmus 					fPoints[fQs[i].pts[j]].ny,
378450bb3e5SStephan Aßmus 					fPoints[fQs[i].pts[j]].nz
379c8c44fa0SJérôme Duval 				);
380c8c44fa0SJérôme Duval  				glVertex3f(
381450bb3e5SStephan Aßmus 					fPoints[fQs[i].pts[j]].x,
382450bb3e5SStephan Aßmus 					fPoints[fQs[i].pts[j]].y,
383450bb3e5SStephan Aßmus 					fPoints[fQs[i].pts[j]].z
384c8c44fa0SJérôme Duval 				);
385450bb3e5SStephan Aßmus 			}
386c8c44fa0SJérôme Duval 			glEnd();
387450bb3e5SStephan Aßmus 		}
388c8c44fa0SJérôme Duval #else
389c8c44fa0SJérôme Duval  		glBegin(GL_TRIANGLES);
390450bb3e5SStephan Aßmus 		for (int i = 0; i < fTriangles.num_items; i++) {
391450bb3e5SStephan Aßmus 			int v3 = fTriangles[i].p1;
392450bb3e5SStephan Aßmus 			int v1 = fTriangles[i].p2;
393450bb3e5SStephan Aßmus 			int v2 = fTriangles[i].p3;
394c8c44fa0SJérôme Duval  	  		glNormal3f(
395450bb3e5SStephan Aßmus 				fPoints[v1].nx,
396450bb3e5SStephan Aßmus 				fPoints[v1].ny,
397450bb3e5SStephan Aßmus 				fPoints[v1].nz
398c8c44fa0SJérôme Duval 			);
399c8c44fa0SJérôme Duval  			glVertex3f(
400450bb3e5SStephan Aßmus 				fPoints[v1].x,
401450bb3e5SStephan Aßmus 				fPoints[v1].y,
402450bb3e5SStephan Aßmus 				fPoints[v1].z
403c8c44fa0SJérôme Duval 			);
404c8c44fa0SJérôme Duval  			glNormal3f(
405450bb3e5SStephan Aßmus 				fPoints[v2].nx,
406450bb3e5SStephan Aßmus 				fPoints[v2].ny,
407450bb3e5SStephan Aßmus 				fPoints[v2].nz
408c8c44fa0SJérôme Duval 			);
409c8c44fa0SJérôme Duval  			glVertex3f(
410450bb3e5SStephan Aßmus 				fPoints[v2].x,
411450bb3e5SStephan Aßmus 				fPoints[v2].y,
412450bb3e5SStephan Aßmus 				fPoints[v2].z
413c8c44fa0SJérôme Duval 			);
414c8c44fa0SJérôme Duval  			glNormal3f(
415450bb3e5SStephan Aßmus 				fPoints[v3].nx,
416450bb3e5SStephan Aßmus 				fPoints[v3].ny,
417450bb3e5SStephan Aßmus 				fPoints[v3].nz
418c8c44fa0SJérôme Duval 			);
419c8c44fa0SJérôme Duval 			glVertex3f(
420450bb3e5SStephan Aßmus 				fPoints[v3].x,
421450bb3e5SStephan Aßmus 				fPoints[v3].y,
422450bb3e5SStephan Aßmus 				fPoints[v3].z
423c8c44fa0SJérôme Duval 			);
424450bb3e5SStephan Aßmus 		}
425c8c44fa0SJérôme Duval 		glEnd();
426c8c44fa0SJérôme Duval  #endif
427450bb3e5SStephan Aßmus }
428c8c44fa0SJérôme Duval 
429