1 //#**************************************************************
2 //# filename: RenderContext.cpp
3 //#
4 //# author: Gerstmayr, Vetyukov
5 //#
6 //# generated:
7 //# description:
8 //# comments:
9 //#
10 //# Copyright (c) 2003-2013 Johannes Gerstmayr, Linz Center of Mechatronics GmbH, Austrian
11 //# Center of Competence in Mechatronics GmbH, Institute of Technical Mechanics at the
12 //# Johannes Kepler Universitaet Linz, Austria. All rights reserved.
13 //#
14 //# This file is part of HotInt.
15 //# HotInt is free software: you can redistribute it and/or modify it under the terms of
16 //# the HOTINT license. See folder 'licenses' for more details.
17 //#
18 //# bug reports are welcome!!!
19 //# WWW: www.hotint.org
20 //# email: bug_reports@hotint.org or support@hotint.org
21 //#***************************************************************************************
22
23
24 #include "stdafx.h"
25
26 #include "RenderContext.h"
27
28 int vertexcnt = 0;
29 int gltrigcnt = 0;
30 int glquadcnt = 0;
31 int gllinecnt = 0;
32
ChooseColor(float r,float g,float b)33 void RenderContext_::ChooseColor(float r, float g, float b)
34 {
35 glColor3f(r,g,b);
36 }
37
ChooseLineThickness(float thickness)38 void RenderContext_::ChooseLineThickness(float thickness)
39 {
40 glLineWidth(thickness);
41 }
42
ChoosePointSize(float size)43 void RenderContext_::ChoosePointSize(float size)
44 {
45 glPointSize(size);
46 }
47
48 #ifdef _DEBUG
Begin()49 void RenderContext_::Begin()
50 {
51 if(bBegin)
52 ASSERT(AfxMessageBox("glBegin() called twice without glEnd().\nContinue?",MB_YESNO | MB_ICONSTOP) == IDYES);
53 bBegin = true;
54 }
55 #endif // _DEBUG
56
glBeginPoints()57 void RenderContext_::glBeginPoints()
58 {
59 Begin();
60 glBegin(GL_POINTS);
61 }
62
glBeginLines()63 void RenderContext_::glBeginLines()
64 {
65 gllinecnt++;
66 Begin();
67 glBegin(GL_LINES);
68 }
69
glBeginLineStrip()70 void RenderContext_::glBeginLineStrip()
71 {
72 Begin();
73 glBegin(GL_LINE_STRIP);
74 }
75
glBeginLineLoop()76 void RenderContext_::glBeginLineLoop()
77 {
78 Begin();
79 glBegin(GL_LINE_LOOP);
80 }
81
glBeginTriangles()82 void RenderContext_::glBeginTriangles()
83 {
84 gltrigcnt++;
85 Begin();
86 glBegin(GL_TRIANGLES);
87 }
88
glBeginTriangleStrip()89 void RenderContext_::glBeginTriangleStrip()
90 {
91 Begin();
92 glBegin(GL_TRIANGLE_STRIP);
93 }
94
glBeginTriangleFan()95 void RenderContext_::glBeginTriangleFan()
96 {
97 Begin();
98 glBegin(GL_TRIANGLE_FAN);
99 }
100
glBeginQuads()101 void RenderContext_::glBeginQuads()
102 {
103 glquadcnt++;
104 Begin();
105 glBegin(GL_QUADS);
106 }
107
glBeginQuadStrip()108 void RenderContext_::glBeginQuadStrip()
109 {
110 Begin();
111 glBegin(GL_QUAD_STRIP);
112 }
113
glBeginPolygon()114 void RenderContext_::glBeginPolygon()
115 {
116 Begin();
117 glBegin(GL_POLYGON);
118 }
119
glEnd()120 void RenderContext_::glEnd()
121 {
122 bBegin = false;
123 ::glEnd();
124 }
125
126 #ifdef _DEBUG
CheckCoordinates(float x,float y,float z)127 void RenderContext_::CheckCoordinates(float x,float y,float z)
128 {
129 static bool bKeepCheckingCoordinates = true;
130 if(!bKeepCheckingCoordinates)
131 return;
132
133 if(fabs(x) > MaxSceneCoord || fabs(y) > MaxSceneCoord || fabs(z) > MaxSceneCoord)
134 {
135 //would only be necessary if graphics problem
136 //ASSERT(AfxMessageBox("The scene coordinates are out of range.\nContinue?",MB_YESNO | MB_ICONSTOP) == IDYES);
137 bKeepCheckingCoordinates = false;
138 }
139 }
140 #endif
141
glVertex(float x,float y,float z)142 void RenderContext_::glVertex(float x, float y, float z)
143 {
144 #ifdef _DEBUG
145 CheckCoordinates(x,y,-z);
146 #endif
147
148 vertexcnt ++;
149 ::glVertex3f(x,y,-z);
150 }
151
glVertex(const double * v)152 void RenderContext_::glVertex(const double* v)
153 {
154 #ifdef _DEBUG
155 CheckCoordinates((float)v[0],(float)v[1],-(float)v[2]);
156 #endif
157
158 vertexcnt ++;
159 ::glVertex3f((float)v[0],(float)v[1],-(float)v[2]);
160 }
161
glRasterPos(float x,float y,float z)162 void RenderContext_::glRasterPos(float x, float y, float z)
163 {
164 vertexcnt ++;
165 //::glRasterPos3f(x,y,-z);
166 ::glVertex3f(x,y,-z);
167 }
168
glColor3f(float x,float y,float z)169 void RenderContext_::glColor3f(float x, float y, float z)
170 {
171 ::glColor3f(x,y,z);
172 }
173
glColor4f(float x,float y,float z,float transp)174 void RenderContext_::glColor4f(float x, float y, float z, float transp)
175 {
176 ::glColor4f(x,y,z,transp);
177 }
178
glEnableColorMaterial()179 void RenderContext_::glEnableColorMaterial()
180 {
181 glEnable(GL_COLOR_MATERIAL);
182 }
183
glDisableColorMaterial()184 void RenderContext_::glDisableColorMaterial()
185 {
186 glDisable (GL_COLOR_MATERIAL);
187 }
188
glVertex(const Vertex & v)189 void RenderContext_::glVertex(const Vertex & v)
190 {
191 CheckCoordinates(v.x,v.y,-v.z);
192 ::glVertex3f(v.x,v.y,-v.z);
193 }
194
glLighting(int bLightingIsOn)195 void RenderContext_::glLighting(int bLightingIsOn)
196 {
197 if(bLightingIsOn) // && pWCDI->GetIOption(206))
198 glEnable(GL_LIGHTING);
199 else
200 glDisable(GL_LIGHTING);
201 }
202
glNormal(float x,float y,float z)203 void RenderContext_::glNormal(float x, float y, float z)
204 {
205 ::glNormal3f(x,y,-z);
206 }
207
glNormal(const Vertex & v)208 void RenderContext_::glNormal(const Vertex & v)
209 {
210 ::glNormal3f(v.x,v.y,-v.z);
211 }
212
glNormal(const double * v)213 void RenderContext_::glNormal(const double* v)
214 {
215 ::glNormal3f((float)v[0],(float)v[1],-(float)v[2]);
216 }
217
218 //texture:
glInitializeTexture(unsigned int * texName,const void * texImage,int imageH,int imageW)219 void RenderContext_::glInitializeTexture(unsigned int* texName, const void* texImage, int imageH, int imageW) //initialize texture
220 {
221 //glClearColor(0.0, 0.0, 0.0, 0.0);
222 //glEnable(GL_DEPTH_TEST);
223
224 if (glstoretextures)
225 {
226
227 gltexturecnt++;
228 if (gltexturecnt >= nmaxtextures)
229 {
230 gltexturecnt = 1;
231
232 if (!gltexturecnt_warned)
233 {
234 AfxMessageBox("Warning: Maximum number of textures reached!\nTexture will be disrupted\nFurther warnings suppressed ... ", MB_OK | MB_ICONSTOP);
235 gltexturecnt_warned = 1;
236 }
237 }
238
239 *texName = texNames[gltexturecnt];
240 }
241 else
242 {
243 *texName = texNames[0]; //one texname has been allocated!
244 }
245
246 glBindTexture(GL_TEXTURE_2D, *texName);
247
248 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //GL_CLAMP
249 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
250 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //GL_NEAREST
251 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //GL_NEAREST
252
253 if (texturemode == 1 || !glstoretextures) //generate textures
254 {
255 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, imageW, imageH, 0, GL_RGBA, GL_UNSIGNED_BYTE, texImage);
256 }
257 else
258 {
259 glTexImage2D( GL_PROXY_TEXTURE_2D, 0, GL_RGBA, imageW, imageH, 0, GL_RGBA, GL_UNSIGNED_BYTE, texImage);
260 }
261 }
262
glBeginTexture(const unsigned int & texName)263 void RenderContext_::glBeginTexture(const unsigned int& texName) //call this function just before begin QUADS
264 {
265 glEnable(GL_TEXTURE_2D);
266 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); //GL_DECAL does not support lighting; GL_MODULATE modulates with surface color and supports lighting!
267 glBindTexture(GL_TEXTURE_2D, texName);
268 }
269
glEndTexture()270 void RenderContext_::glEndTexture() //call this function just after glEnd() of QUADS
271 {
272 glDisable(GL_TEXTURE_2D);
273 }
274
glTexCoord2f(float x,float y)275 void RenderContext_::glTexCoord2f(float x, float y) //local coordinates in texture image (0,0) - (1,1)
276 {
277 ::glTexCoord2f(x, y);
278 }
279
glBeginTexture1D(const unsigned int & texName)280 void RenderContext_::glBeginTexture1D(const unsigned int& texName) //call this function just before begin QUADS
281 {
282 glEnable(GL_TEXTURE_1D);
283 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); //GL_DECAL does not support lighting; GL_MODULATE modulates with surface color and supports lighting!
284 glBindTexture(GL_TEXTURE_1D, FEcolortexNames[texName]);
285 }
286
glEndTexture1D()287 void RenderContext_::glEndTexture1D() //call this function just after glEnd() of QUADS
288 {
289 glDisable(GL_TEXTURE_1D);
290 }
291
glTexCoord1f(float x)292 void RenderContext_::glTexCoord1f(float x)
293 {
294 ::glTexCoord1f(x);
295 }
296
297
glPushMatrices()298 void RenderContext_::glPushMatrices()
299 {
300 glMatrixMode(GL_MODELVIEW);
301 glPushMatrix();
302 glLoadIdentity();
303 glMatrixMode(GL_PROJECTION);
304 glPushMatrix();
305 glLoadIdentity();
306 }
307
glPopMatrices()308 void RenderContext_::glPopMatrices()
309 {
310 glPopMatrix();
311 glMatrixMode(GL_MODELVIEW);
312 glPopMatrix();
313 }
314
DrawNode(float x,float y,float z)315 void RenderContext_::DrawNode(float x, float y, float z)
316 {
317 // TODO
318 }
319
DrawFixedDof(float x,float y,float z,int dof_num)320 void RenderContext_::DrawFixedDof(float x, float y, float z, int dof_num)
321 {
322 // TODO
323 }
324
DrawForce(float x,float y,float z,float dirx,float diry,float dirz)325 void RenderContext_::DrawForce(float x, float y, float z, float dirx, float diry, float dirz)
326 {
327 // TODO
328 }
329
330
331
332
333 /*
334 void RenderContext_::glInitializeTexture(unsigned int* texName, const void* texImage, int imageH, int imageW) //initialize texture
335 {
336 //glClearColor(0.0, 0.0, 0.0, 0.0);
337 //glEnable(GL_DEPTH_TEST);
338
339
340 glGenTextures(1, texName);
341 glBindTexture(GL_TEXTURE_2D, *texName);
342
343 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //GL_CLAMP
344 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
345 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
346 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
347
348 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, imageW, imageH, 0,
349 GL_RGBA, GL_UNSIGNED_BYTE, texImage);
350 }
351
352 void RenderContext_::glBeginTexture(const unsigned int& texName) //call this function just before begin QUADS
353 {
354 glEnable(GL_TEXTURE_2D);
355 //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
356 glBindTexture(GL_TEXTURE_2D, texName);
357 }
358
359 void RenderContext_::glEndTexture(const unsigned int& texName) //call this function just after glEnd() of QUADS
360 {
361 glDisable(GL_TEXTURE_2D);
362 glDeleteTextures(1, &texName);
363 }
364
365 */
366
AddDrawComponent(const DrawComponent & elem)367 int ControlWindowContext_::AddDrawComponent(const DrawComponent& elem)
368 {
369 return the_elements.Add(elem);
370 }
371
Reset()372 void ControlWindowContext_::Reset()
373 {
374 the_elements.Flush();
375 }
376
DrawScene()377 int ControlWindowContext_::DrawScene()
378 {
379 return 1;
380 }
381
382