Switch fixed time system. Logic updates should now happen at 30Hz, physics at 60Hz...
[blender.git] / source / gameengine / Rasterizer / RAS_OpenGLRasterizer / RAS_OpenGLRasterizer.cpp
1 /**
2  * $Id$
3  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version. The Blender
9  * Foundation also sells licenses for use in proprietary software under
10  * the Blender License.  See http://www.blender.org/BL/ for information
11  * about this.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23  * All rights reserved.
24  *
25  * The Original Code is: all of this file.
26  *
27  * Contributor(s): none yet.
28  *
29  * ***** END GPL/BL DUAL LICENSE BLOCK *****
30  */
31 #include "RAS_OpenGLRasterizer.h"
32
33 #ifdef HAVE_CONFIG_H
34 #include <config.h>
35 #endif
36
37 #ifdef WIN32
38 #include <windows.h>
39 #endif // WIN32
40 #ifdef __APPLE__
41 #include <OpenGL/gl.h>
42 #else
43 #include <GL/gl.h>
44 #endif
45
46 #include "RAS_Rect.h"
47 #include "RAS_TexVert.h"
48 #include "MT_CmMatrix4x4.h"
49 #include "RAS_IRenderTools.h" // rendering text
50
51 #include "RAS_GLExtensionManager.h"
52
53
54 RAS_OpenGLRasterizer::RAS_OpenGLRasterizer(RAS_ICanvas* canvas)
55         :RAS_IRasterizer(canvas),
56         m_2DCanvas(canvas),
57         m_fogenabled(false),
58         m_time(0.0),
59         m_stereomode(RAS_STEREO_NOSTEREO),
60         m_curreye(RAS_STEREO_LEFTEYE),
61         m_noOfScanlines(32),
62         m_materialCachingInfo(0)
63 {
64         m_viewmatrix.Identity();
65 }
66
67
68
69 RAS_OpenGLRasterizer::~RAS_OpenGLRasterizer()
70 {
71 }
72
73
74
75 static void Myinit_gl_stuff(void)       
76 {
77         float mat_specular[] = { 0.5, 0.5, 0.5, 1.0 };
78         float mat_shininess[] = { 35.0 };
79 /*      float one= 1.0; */
80         int a, x, y;
81         GLubyte pat[32*32];
82         const GLubyte *patc= pat;
83                 
84         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_specular);
85         glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
86         glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
87
88
89 #if defined(__FreeBSD) || defined(__linux__)
90         glDisable(GL_DITHER);   /* op sgi/sun hardware && 12 bits */
91 #endif
92         
93         /* no local viewer, looks ugly in ortho mode */
94         /* glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, &one); */
95         
96         glDepthFunc(GL_LEQUAL);
97         /* scaling matrices */
98         glEnable(GL_NORMALIZE);
99
100         glShadeModel(GL_FLAT);
101
102         glDisable(GL_ALPHA_TEST);
103         glDisable(GL_BLEND);
104         glDisable(GL_DEPTH_TEST);
105         glDisable(GL_FOG);
106         glDisable(GL_LIGHTING);
107         glDisable(GL_LOGIC_OP);
108         glDisable(GL_STENCIL_TEST);
109         glDisable(GL_TEXTURE_1D);
110         glDisable(GL_TEXTURE_2D);
111
112         glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
113         glPixelTransferi(GL_RED_SCALE, 1);
114         glPixelTransferi(GL_RED_BIAS, 0);
115         glPixelTransferi(GL_GREEN_SCALE, 1);
116         glPixelTransferi(GL_GREEN_BIAS, 0);
117         glPixelTransferi(GL_BLUE_SCALE, 1);
118         glPixelTransferi(GL_BLUE_BIAS, 0);
119         glPixelTransferi(GL_ALPHA_SCALE, 1);
120         glPixelTransferi(GL_ALPHA_BIAS, 0);
121
122         a = 0;
123         for(x=0; x<32; x++)
124         {
125                 for(y=0; y<4; y++)
126                 {
127                         if( (x) & 1) pat[a++]= 0x88;
128                         else pat[a++]= 0x22;
129                 }
130         }
131         
132         glPolygonStipple(patc);
133 }
134
135
136
137 bool RAS_OpenGLRasterizer::Init()
138 {
139
140         Myinit_gl_stuff();
141
142         m_redback = 0.4375;
143         m_greenback = 0.4375;
144         m_blueback = 0.4375;
145         m_alphaback = 0.0;
146         
147         glClearColor(m_redback,m_greenback,m_blueback,m_alphaback);
148         glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
149         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
150
151         glShadeModel(GL_SMOOTH);
152
153         return true;
154 }
155
156
157
158 void RAS_OpenGLRasterizer::SetBackColor(float red,
159                                                                                 float green,
160                                                                                 float blue,
161                                                                                 float alpha)
162 {
163         m_redback = red;
164         m_greenback = green;
165         m_blueback = blue;
166         m_alphaback = alpha;
167 }
168
169
170
171 void RAS_OpenGLRasterizer::SetFogColor(float r,
172                                                                            float g,
173                                                                            float b)
174 {
175         m_fogr = r;
176         m_fogg = g;
177         m_fogb = b;
178         m_fogenabled = true;
179 }
180
181
182
183 void RAS_OpenGLRasterizer::SetFogStart(float start)
184 {
185         m_fogstart = start;
186         m_fogenabled = true;
187 }
188
189
190
191 void RAS_OpenGLRasterizer::SetFogEnd(float fogend)
192 {
193         m_fogdist = fogend;
194         m_fogenabled = true;
195 }
196
197
198
199 void RAS_OpenGLRasterizer::SetFog(float start,
200                                                                   float dist,
201                                                                   float r,
202                                                                   float g,
203                                                                   float b)
204 {
205         m_fogstart = start;
206         m_fogdist = dist;
207         m_fogr = r;
208         m_fogg = g;
209         m_fogb = b;
210         m_fogenabled = true;
211 }
212
213
214
215 void RAS_OpenGLRasterizer::DisableFog()
216 {
217         m_fogenabled = false;
218 }
219
220
221
222 void RAS_OpenGLRasterizer::DisplayFog()
223 {
224         if ((m_drawingmode >= KX_SOLID) && m_fogenabled)
225         {
226                 float params[5];
227                 glFogi(GL_FOG_MODE, GL_LINEAR);
228                 glFogf(GL_FOG_DENSITY, 0.1f);
229                 glFogf(GL_FOG_START, m_fogstart);
230                 glFogf(GL_FOG_END, m_fogstart + m_fogdist);
231                 params[0]= m_fogr;
232                 params[1]= m_fogg;
233                 params[2]= m_fogb;
234                 params[3]= 0.0;
235                 glFogfv(GL_FOG_COLOR, params); 
236                 glEnable(GL_FOG);
237         } 
238         else
239         {
240                 glDisable(GL_FOG);
241         }
242 }
243
244
245
246 void RAS_OpenGLRasterizer::SetMaterial(const RAS_IPolyMaterial& mat)
247 {
248         if (mat.GetCachingInfo() != m_materialCachingInfo)
249         {
250                 mat.Activate(this, m_materialCachingInfo);
251         }
252 }
253
254
255
256 void RAS_OpenGLRasterizer::Exit()
257 {
258
259         glEnable(GL_CULL_FACE);
260         glEnable(GL_DEPTH_TEST);
261         glClearDepth(1.0); 
262         glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
263         glClearColor(m_redback, m_greenback, m_blueback, m_alphaback);
264         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
265         glDepthMask (GL_TRUE);
266         glDepthFunc(GL_LEQUAL);
267         glBlendFunc(GL_ONE, GL_ZERO);
268
269         glDisable(GL_LIGHTING);
270         if (bgl::QueryExtension(bgl::_GL_EXT_separate_specular_color) || bgl::QueryVersion(1, 2))
271                 glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR);
272         
273         EndFrame();
274 }
275
276
277
278 bool RAS_OpenGLRasterizer::BeginFrame(int drawingmode, double time)
279 {
280         m_time = time;
281         m_drawingmode = drawingmode;
282         
283         m_2DCanvas->ClearColor(m_redback,m_greenback,m_blueback,m_alphaback);
284         m_2DCanvas->ClearBuffer(RAS_ICanvas::COLOR_BUFFER);
285
286         // Blender camera routine destroys the settings
287         if (m_drawingmode < KX_SOLID)
288         {
289                 glDisable (GL_CULL_FACE);
290                 glDisable (GL_DEPTH_TEST);
291         }
292         else
293         {
294                 glEnable(GL_DEPTH_TEST);
295                 glEnable (GL_CULL_FACE);
296         }
297
298         glShadeModel(GL_SMOOTH);
299
300         m_2DCanvas->BeginFrame();
301         
302         return true;
303 }
304
305
306
307 void RAS_OpenGLRasterizer::SetDrawingMode(int drawingmode)
308 {
309         m_drawingmode = drawingmode;
310
311         switch (m_drawingmode)
312         {
313         case KX_BOUNDINGBOX:
314                 {
315                 }
316         case KX_WIREFRAME:
317                 {
318                         glDisable (GL_CULL_FACE);
319                         break;
320                 }
321         case KX_TEXTURED:
322                 {
323                 }
324         case KX_SHADED:
325                 {
326                 }
327         case KX_SOLID:
328                 {
329                 }
330         default:
331                 {
332                 }
333         }
334 }
335
336
337
338 int RAS_OpenGLRasterizer::GetDrawingMode()
339 {
340         return m_drawingmode;
341 }
342
343
344
345 void RAS_OpenGLRasterizer::SetDepthMask(DepthMask depthmask)
346 {
347         glDepthMask(depthmask == KX_DEPTHMASK_DISABLED ? GL_FALSE : GL_TRUE);
348 }
349
350
351
352 void RAS_OpenGLRasterizer::ClearDepthBuffer()
353 {
354         m_2DCanvas->ClearBuffer(RAS_ICanvas::DEPTH_BUFFER);
355 }
356
357
358 void RAS_OpenGLRasterizer::ClearCachingInfo(void)
359 {
360         m_materialCachingInfo = 0;
361 }
362
363
364 void RAS_OpenGLRasterizer::EndFrame()
365 {
366         glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
367         m_2DCanvas->EndFrame();
368 }       
369
370 void RAS_OpenGLRasterizer::SetRenderArea()
371 {
372         // only above/below stereo method needs viewport adjustment
373         switch (m_stereomode)
374         {
375                 case RAS_STEREO_ABOVEBELOW:
376                         switch(m_curreye)
377                         {
378                                 case RAS_STEREO_LEFTEYE:
379                                         // upper half of window
380                                         m_2DCanvas->GetDisplayArea().SetLeft(0);
381                                         m_2DCanvas->GetDisplayArea().SetBottom(m_2DCanvas->GetHeight() -
382                                                 int(m_2DCanvas->GetHeight() - m_noOfScanlines) / 2);
383         
384                                         m_2DCanvas->GetDisplayArea().SetRight(int(m_2DCanvas->GetWidth()));
385                                         m_2DCanvas->GetDisplayArea().SetTop(int(m_2DCanvas->GetHeight()));
386                                         break;
387                                 case RAS_STEREO_RIGHTEYE:
388                                         // lower half of window
389                                         m_2DCanvas->GetDisplayArea().SetLeft(0);
390                                         m_2DCanvas->GetDisplayArea().SetBottom(0);
391                                         m_2DCanvas->GetDisplayArea().SetRight(int(m_2DCanvas->GetWidth()));
392                                         m_2DCanvas->GetDisplayArea().SetTop(int(m_2DCanvas->GetHeight() - m_noOfScanlines) / 2);
393                                         break;
394                         }
395                         break;
396                 case RAS_STEREO_SIDEBYSIDE:
397                         switch (m_curreye)
398                         {
399                                 case RAS_STEREO_LEFTEYE:
400                                         // Left half of window
401                                         m_2DCanvas->GetDisplayArea().SetLeft(0);
402                                         m_2DCanvas->GetDisplayArea().SetBottom(0);
403                                         m_2DCanvas->GetDisplayArea().SetRight(m_2DCanvas->GetWidth()/2);
404                                         m_2DCanvas->GetDisplayArea().SetTop(m_2DCanvas->GetHeight());
405                                         break;
406                                 case RAS_STEREO_RIGHTEYE:
407                                         // Right half of window
408                                         m_2DCanvas->GetDisplayArea().SetLeft(m_2DCanvas->GetWidth()/2);
409                                         m_2DCanvas->GetDisplayArea().SetBottom(0);
410                                         m_2DCanvas->GetDisplayArea().SetRight(m_2DCanvas->GetWidth());
411                                         m_2DCanvas->GetDisplayArea().SetTop(m_2DCanvas->GetHeight());
412                                         break;
413                         }
414                         break;
415                 default:
416                         // every available pixel
417                         m_2DCanvas->GetDisplayArea().SetLeft(0);
418                         m_2DCanvas->GetDisplayArea().SetBottom(0);
419                         m_2DCanvas->GetDisplayArea().SetRight(int(m_2DCanvas->GetWidth()));
420                         m_2DCanvas->GetDisplayArea().SetTop(int(m_2DCanvas->GetHeight()));
421                         break;
422         }
423 }
424
425         
426 void RAS_OpenGLRasterizer::SetStereoMode(const StereoMode stereomode)
427 {
428         m_stereomode = stereomode;
429 }
430
431
432
433 bool RAS_OpenGLRasterizer::Stereo()
434 {
435         if(m_stereomode == RAS_STEREO_NOSTEREO)
436                 return false;
437         else
438                 return true;
439 }
440
441
442 void RAS_OpenGLRasterizer::SetEye(StereoEye eye)
443 {
444         m_curreye = eye;
445         switch (m_stereomode)
446         {
447                 case RAS_STEREO_QUADBUFFERED:
448                         glDrawBuffer(m_curreye == RAS_STEREO_LEFTEYE ? GL_BACK_LEFT : GL_BACK_RIGHT);
449                         break;
450                 case RAS_STEREO_ANAGLYPH:
451                         if (m_curreye == RAS_STEREO_LEFTEYE)
452                         {
453                                 glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_FALSE);
454                                 m_2DCanvas->ClearBuffer(RAS_ICanvas::COLOR_BUFFER);
455                                 glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_FALSE);
456                         } else {
457                                 //glAccum(GL_LOAD, 1.0);
458                                 glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
459                                 ClearDepthBuffer();
460                         }
461                         break;
462                 default:
463                         break;
464         }
465 }
466
467
468 void RAS_OpenGLRasterizer::SetEyeSeparation(float eyeseparation)
469 {
470         m_eyeseparation = eyeseparation;
471 }
472
473
474 void RAS_OpenGLRasterizer::SetFocalLength(float focallength)
475 {
476         m_focallength = focallength;
477 }
478
479
480 void RAS_OpenGLRasterizer::SwapBuffers()
481 {
482         m_2DCanvas->SwapBuffers();
483 }
484
485
486
487 void RAS_OpenGLRasterizer::IndexPrimitives(const vecVertexArray & vertexarrays,
488                                                                         const vecIndexArrays & indexarrays,
489                                                                         int mode,
490                                                                         class RAS_IPolyMaterial* polymat,
491                                                                         class RAS_IRenderTools* rendertools,
492                                                                         bool useObjectColor,
493                                                                         const MT_Vector4& rgbacolor
494                                                                         )
495
496         GLenum drawmode;
497         switch (mode)
498         {
499         case 0:
500                 drawmode = GL_TRIANGLES;
501                 break;
502         case 1:
503                 drawmode = GL_LINES;
504                 break;
505         case 2:
506                 drawmode = GL_QUADS;
507                 break;
508         default:
509                 drawmode = GL_LINES;
510                 break;
511         }
512         
513         const RAS_TexVert* vertexarray ;
514         unsigned int numindices,vt;
515
516         for (vt=0;vt<vertexarrays.size();vt++)
517         {
518                 vertexarray = &((*vertexarrays[vt]) [0]);
519                 const KX_IndexArray & indexarray = (*indexarrays[vt]);
520                 numindices = indexarray.size();
521                 
522                 if (!numindices)
523                         break;
524                 
525                 int vindex=0;
526                 switch (mode)
527                 {
528                 case 1:
529                         {
530                                 glBegin(GL_LINES);
531                                 vindex=0;
532                                 for (unsigned int i=0;i<numindices;i+=2)
533                                 {
534                                         glVertex3fv(vertexarray[(indexarray[vindex++])].getLocalXYZ());
535                                         glVertex3fv(vertexarray[(indexarray[vindex++])].getLocalXYZ());
536                                 }
537                                 glEnd();
538                         }
539                         break;
540                 case 2:
541                         {
542                                 glBegin(GL_QUADS);
543                                 vindex=0;
544                                 if (useObjectColor)
545                                 {
546                                         for (unsigned int i=0;i<numindices;i+=4)
547                                         {
548
549                                                 glColor4d(rgbacolor[0], rgbacolor[1], rgbacolor[2], rgbacolor[3]);
550
551                                                 glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
552                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
553                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
554                                                 vindex++;
555                                                 
556                                                 glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
557                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
558                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
559                                                 vindex++;
560                                                 
561                                                 glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
562                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
563                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
564                                                 vindex++;
565                                                 
566                                                 glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
567                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
568                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
569                                                 vindex++;
570                                         }
571                                 }
572                                 else
573                                 {
574                                         for (unsigned int i=0;i<numindices;i+=4)
575                                         {
576                                                 // This looks curiously endian unsafe to me.
577                                                 // However it depends on the way the colors are packed into 
578                                                 // the m_rgba field of RAS_TexVert
579
580                                                 glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
581                                                 glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
582                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
583                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
584                                                 vindex++;
585                                                 
586                                                 glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
587                                                 glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
588                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
589                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
590                                                 vindex++;
591                                                 
592                                                 glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
593                                                 glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
594                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
595                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
596                                                 vindex++;
597                                                 
598                                                 glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
599                                                 glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
600                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
601                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
602                                                 vindex++;
603                                         }
604                                 }
605                                 glEnd();        
606                                 break;
607                         }
608                 case 0:
609                         {
610                                 glBegin(GL_TRIANGLES);
611                                 vindex=0;
612                                 if (useObjectColor)
613                                 {
614                                         for (unsigned int i=0;i<numindices;i+=3)
615                                         {
616
617                                                 glColor4d(rgbacolor[0], rgbacolor[1], rgbacolor[2], rgbacolor[3]);
618
619                                                 glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
620                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
621                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
622                                                 vindex++;
623                                                 
624                                                 glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
625                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
626                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
627                                                 vindex++;
628                                                 
629                                                 glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
630                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
631                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
632                                                 vindex++;
633                                         }
634                                 }
635                                 else 
636                                 {
637                                         for (unsigned int i=0;i<numindices;i+=3)
638                                         {
639
640                                                 glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
641                                                 glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
642                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
643                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
644                                                 vindex++;
645                                                 
646                                                 glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
647                                                 glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
648                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
649                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
650                                                 vindex++;
651                                                 
652                                                 glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
653                                                 glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
654                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
655                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
656                                                 vindex++;
657                                         }
658                                 }
659                                 glEnd();        
660                                 break;
661                         }
662                 default:
663                         {
664                         }
665                         
666                 } // switch
667         } // for each vertexarray
668
669 }
670
671 void RAS_OpenGLRasterizer::IndexPrimitives_Ex(const vecVertexArray & vertexarrays,
672                                                                         const vecIndexArrays & indexarrays,
673                                                                         int mode,
674                                                                         class RAS_IPolyMaterial* polymat,
675                                                                         class RAS_IRenderTools* rendertools,
676                                                                         bool useObjectColor,
677                                                                         const MT_Vector4& rgbacolor
678                                                                         )
679
680         bool    recalc;
681         GLenum drawmode;
682         switch (mode)
683         {
684         case 0:
685                 drawmode = GL_TRIANGLES;
686                 break;
687         case 1:
688                 drawmode = GL_LINES;
689                 break;
690         case 2:
691                 drawmode = GL_QUADS;
692                 break;
693         default:
694                 drawmode = GL_LINES;
695                 break;
696         }
697         
698         const RAS_TexVert* vertexarray ;
699         unsigned int numindices,vt;
700
701         for (vt=0;vt<vertexarrays.size();vt++)
702         {
703                 vertexarray = &((*vertexarrays[vt]) [0]);
704                 const KX_IndexArray & indexarray = (*indexarrays[vt]);
705                 numindices = indexarray.size();
706                 
707                 if (!numindices)
708                         continue;
709                 
710                 int vindex=0;
711                 switch (mode)
712                 {
713                 case 1:
714                         {
715                                 glBegin(GL_LINES);
716                                 vindex=0;
717                                 for (unsigned int i=0;i<numindices;i+=2)
718                                 {
719                                         glVertex3fv(vertexarray[(indexarray[vindex++])].getLocalXYZ());
720                                         glVertex3fv(vertexarray[(indexarray[vindex++])].getLocalXYZ());
721                                 }
722                                 glEnd();
723                         }
724                         break;
725                 case 2:
726                         {
727                                 glBegin(GL_QUADS);
728                                 vindex=0;
729                                 if (useObjectColor)
730                                 {
731                                         for (unsigned int i=0;i<numindices;i+=4)
732                                         {
733                                                 MT_Point3 mv1, mv2, mv3, mv4, fnor;
734                                                 /* Calc a new face normal */
735
736                                                 if (vertexarray[(indexarray[vindex])].getFlag() & TV_CALCFACENORMAL)
737                                                         recalc= true;
738                                                 else
739                                                         recalc=false;
740
741                                                 if (recalc){
742                                                         mv1 = MT_Point3(vertexarray[(indexarray[vindex])].getLocalXYZ());
743                                                         mv2 = MT_Point3(vertexarray[(indexarray[vindex+1])].getLocalXYZ());
744                                                         mv3 = MT_Point3(vertexarray[(indexarray[vindex+2])].getLocalXYZ());
745                                                         mv4 = MT_Point3(vertexarray[(indexarray[vindex+2])].getLocalXYZ());
746                                                         
747                                                         fnor = (((mv2-mv1).cross(mv3-mv2))+((mv4-mv3).cross(mv1-mv4))).safe_normalized();
748
749                                                         glNormal3f(fnor[0], fnor[1], fnor[2]);
750                                                 }
751
752                                                 glColor4d(rgbacolor[0], rgbacolor[1], rgbacolor[2], rgbacolor[3]);
753
754                                                 if (!recalc)
755                                                         glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
756                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
757                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
758                                                 vindex++;
759                                                 
760                                                 if (!recalc)
761                                                         glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
762                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
763                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
764                                                 vindex++;
765                                                 
766                                                 if (!recalc)
767                                                         glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());                                             
768                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
769                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
770                                                 vindex++;
771                                                 
772                                                 if (!recalc)
773                                                         glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
774                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
775                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
776                                                 vindex++;
777                                         }
778                                 }
779                                 else
780                                 {
781                                         for (unsigned int i=0;i<numindices;i+=4)
782                                         {
783                                                 // This looks curiously endian unsafe to me.
784                                                 // However it depends on the way the colors are packed into 
785                                                 // the m_rgba field of RAS_TexVert
786                                                 MT_Point3 mv1, mv2, mv3, mv4, fnor;
787                                                 /* Calc a new face normal */
788
789                                                 if (vertexarray[(indexarray[vindex])].getFlag() & TV_CALCFACENORMAL)
790                                                         recalc= true;
791                                                 else
792                                                         recalc=false;
793
794
795                                                 if (recalc){
796                                                         mv1 = MT_Point3(vertexarray[(indexarray[vindex])].getLocalXYZ());
797                                                         mv2 = MT_Point3(vertexarray[(indexarray[vindex+1])].getLocalXYZ());
798                                                         mv3 = MT_Point3(vertexarray[(indexarray[vindex+2])].getLocalXYZ());
799                                                         mv4 = MT_Point3(vertexarray[(indexarray[vindex+3])].getLocalXYZ());
800                                                         
801                                                         fnor = (((mv2-mv1).cross(mv3-mv2))+((mv4-mv3).cross(mv1-mv4))).safe_normalized();
802
803                                                         glNormal3f(fnor[0], fnor[1], fnor[2]);
804                                                 }
805
806                                                 glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
807                                                 if (!recalc)
808                                                         glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
809                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
810                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
811                                                 vindex++;
812                                                 
813                                                 glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
814                                                 if (!recalc)
815                                                         glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
816                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
817                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
818                                                 vindex++;
819                                                 
820                                                 glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
821                                                 if (!recalc)
822                                                         glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
823                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
824                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
825                                                 vindex++;
826                                                 
827                                                 glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
828                                                 if (!recalc)
829                                                         glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
830                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
831                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
832                                                 vindex++;
833                                         }
834                                 }
835                                 glEnd();        
836                                 break;
837                         }
838                 case 0:
839                         {
840                                 glBegin(GL_TRIANGLES);
841                                 vindex=0;
842                                 if (useObjectColor)
843                                 {
844                                         for (unsigned int i=0;i<numindices;i+=3)
845                                         {
846                                                 MT_Point3 mv1, mv2, mv3, fnor;
847                                                 /* Calc a new face normal */
848
849                                                 if (vertexarray[(indexarray[vindex])].getFlag() & TV_CALCFACENORMAL)
850                                                         recalc= true;
851                                                 else
852                                                         recalc=false;
853
854                                                 if (recalc){
855                                                         mv1 = MT_Point3(vertexarray[(indexarray[vindex])].getLocalXYZ());
856                                                         mv2 = MT_Point3(vertexarray[(indexarray[vindex+1])].getLocalXYZ());
857                                                         mv3 = MT_Point3(vertexarray[(indexarray[vindex+2])].getLocalXYZ());
858                                                         
859                                                         fnor = ((mv2-mv1).cross(mv3-mv2)).safe_normalized();
860                                                         glNormal3f(fnor[0], fnor[1], fnor[2]);
861                                                 }
862
863                                                 glColor4d(rgbacolor[0], rgbacolor[1], rgbacolor[2], rgbacolor[3]);
864
865                                                 if (!recalc)
866                                                         glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
867                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
868                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
869                                                 vindex++;
870                                                 
871                                                 if (!recalc)
872                                                         glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
873                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
874                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
875                                                 vindex++;
876                                                 
877                                                 if (!recalc)
878                                                         glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
879                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
880                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
881                                                 vindex++;
882                                         }
883                                 }
884                                 else 
885                                 {
886                                         for (unsigned int i=0;i<numindices;i+=3)
887                                         {
888                                                 MT_Point3 mv1, mv2, mv3, fnor;
889                                                 /* Calc a new face normal */
890
891                                                 if (vertexarray[(indexarray[vindex])].getFlag() & TV_CALCFACENORMAL)
892                                                         recalc= true;
893                                                 else
894                                                         recalc=false;
895
896
897                                                 if (recalc){
898                                                         mv1 = MT_Point3(vertexarray[(indexarray[vindex])].getLocalXYZ());
899                                                         mv2 = MT_Point3(vertexarray[(indexarray[vindex+1])].getLocalXYZ());
900                                                         mv3 = MT_Point3(vertexarray[(indexarray[vindex+2])].getLocalXYZ());
901                                                         
902                                                         fnor = ((mv2-mv1).cross(mv3-mv2)).safe_normalized();
903                                                         glNormal3f(fnor[0], fnor[1], fnor[2]);
904                                                 }
905
906                                                 glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
907                                                 if (!recalc)
908                                                         glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
909                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
910                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
911                                                 vindex++;
912                                                 
913                                                 glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
914                                                 if (!recalc)
915                                                         glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
916                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
917                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
918                                                 vindex++;
919                                                 
920                                                 glColor4ubv((const GLubyte *)(vertexarray[(indexarray[vindex])].getRGBA()));
921                                                 if (!recalc)
922                                                         glNormal3fv(vertexarray[(indexarray[vindex])].getNormal());
923                                                 glTexCoord2fv(vertexarray[(indexarray[vindex])].getUV1());
924                                                 glVertex3fv(vertexarray[(indexarray[vindex])].getLocalXYZ());
925                                                 vindex++;
926                                         }
927                                 }
928                                 glEnd();        
929                                 break;
930                         }
931                 default:
932                         {
933                         }
934                         
935                 } // switch
936         } // for each vertexarray
937
938 }
939
940
941
942 void RAS_OpenGLRasterizer::IndexPrimitives_3DText(const vecVertexArray & vertexarrays,
943                                                                         const vecIndexArrays & indexarrays,
944                                                                         int mode,
945                                                                         class RAS_IPolyMaterial* polymat,
946                                                                         class RAS_IRenderTools* rendertools,
947                                                                         bool useObjectColor,
948                                                                         const MT_Vector4& rgbacolor
949                                                                         )
950
951         GLenum drawmode;
952         switch (mode)
953         {
954         case 0:
955                 drawmode = GL_TRIANGLES;
956                 break;
957         case 1:
958                 drawmode = GL_LINES;
959                 break;
960         case 2:
961                 drawmode = GL_QUADS;
962                 break;
963         default:
964                 drawmode = GL_LINES;
965                 break;
966         }
967         
968         const RAS_TexVert* vertexarray ;
969         
970         unsigned int numindices, vt;
971         
972         if (useObjectColor)
973         {
974                 glDisableClientState(GL_COLOR_ARRAY);
975                 glColor4d(rgbacolor[0], rgbacolor[1], rgbacolor[2], rgbacolor[3]);
976         }
977         else
978         {
979                 glEnableClientState(GL_COLOR_ARRAY);
980         }
981         
982         for (vt=0;vt<vertexarrays.size();vt++)
983         {
984                 vertexarray = &((*vertexarrays[vt]) [0]);
985                 const KX_IndexArray & indexarray = (*indexarrays[vt]);
986                 numindices = indexarray.size();
987                 
988                 if (!numindices)
989                         break;
990                 
991                 int vindex=0;
992                 switch (mode)
993                 {
994                 case 1:
995                         {
996                                 glBegin(GL_LINES);
997                                 vindex=0;
998                                 for (unsigned int i=0;i<numindices;i+=2)
999                                 {
1000                                         glVertex3fv(vertexarray[(indexarray[vindex++])].getLocalXYZ());
1001                                         glVertex3fv(vertexarray[(indexarray[vindex++])].getLocalXYZ());
1002                                 }
1003                                 glEnd();
1004                         }
1005                         break;
1006                 case 2:
1007                         {
1008                                 vindex=0;
1009                                 for (unsigned int i=0;i<numindices;i+=4)
1010                                 {
1011                                         float v1[3],v2[3],v3[3],v4[3];
1012                                         
1013                                         v1[0] = vertexarray[(indexarray[vindex])].getLocalXYZ()[0];
1014                                         v1[1] = vertexarray[(indexarray[vindex])].getLocalXYZ()[1];
1015                                         v1[2] = vertexarray[(indexarray[vindex])].getLocalXYZ()[2];
1016                                         vindex++;
1017                                         
1018                                         v2[0] = vertexarray[(indexarray[vindex])].getLocalXYZ()[0];
1019                                         v2[1] = vertexarray[(indexarray[vindex])].getLocalXYZ()[1];
1020                                         v2[2] = vertexarray[(indexarray[vindex])].getLocalXYZ()[2];
1021                                         vindex++;
1022                                         
1023                                         v3[0] = vertexarray[(indexarray[vindex])].getLocalXYZ()[0];
1024                                         v3[1] = vertexarray[(indexarray[vindex])].getLocalXYZ()[1];
1025                                         v3[2] = vertexarray[(indexarray[vindex])].getLocalXYZ()[2];
1026                                         vindex++;
1027                                         
1028                                         v4[0] = vertexarray[(indexarray[vindex])].getLocalXYZ()[0];
1029                                         v4[1] = vertexarray[(indexarray[vindex])].getLocalXYZ()[1];
1030                                         v4[2] = vertexarray[(indexarray[vindex])].getLocalXYZ()[2];
1031                                         
1032                                         vindex++;
1033                                         
1034                                         rendertools->RenderText(polymat->GetDrawingMode(),polymat,v1,v2,v3,v4);
1035                                         ClearCachingInfo();
1036                                 }
1037                                 break;
1038                         }
1039                 case 0:
1040                         {
1041                                 glBegin(GL_TRIANGLES);
1042                                 vindex=0;
1043                                 for (unsigned int i=0;i<numindices;i+=3)
1044                                 {
1045                                         float v1[3],v2[3],v3[3];
1046                                         
1047                                         v1[0] = vertexarray[(indexarray[vindex])].getLocalXYZ()[0];
1048                                         v1[1] = vertexarray[(indexarray[vindex])].getLocalXYZ()[1];
1049                                         v1[2] = vertexarray[(indexarray[vindex])].getLocalXYZ()[2];
1050                                         vindex++;
1051                                         
1052                                         v2[0] = vertexarray[(indexarray[vindex])].getLocalXYZ()[0];
1053                                         v2[1] = vertexarray[(indexarray[vindex])].getLocalXYZ()[1];
1054                                         v2[2] = vertexarray[(indexarray[vindex])].getLocalXYZ()[2];
1055                                         vindex++;
1056                                         
1057                                         v3[0] = vertexarray[(indexarray[vindex])].getLocalXYZ()[0];
1058                                         v3[1] = vertexarray[(indexarray[vindex])].getLocalXYZ()[1];
1059                                         v3[2] = vertexarray[(indexarray[vindex])].getLocalXYZ()[2];
1060                                         vindex++;
1061                                         
1062                                         rendertools->RenderText(polymat->GetDrawingMode(),polymat,v1,v2,v3,NULL);               
1063                                         ClearCachingInfo();
1064                                 }
1065                                 glEnd();        
1066                                 break;
1067                         }
1068                 default:
1069                         {
1070                         }
1071                 }       //switch
1072         }       //for each vertexarray
1073 }
1074
1075
1076
1077 void RAS_OpenGLRasterizer::SetProjectionMatrix(MT_CmMatrix4x4 &mat)
1078 {
1079         glMatrixMode(GL_PROJECTION);
1080         double* matrix = &mat(0,0);
1081         glLoadMatrixd(matrix);
1082 }
1083
1084
1085 void RAS_OpenGLRasterizer::SetProjectionMatrix(const MT_Matrix4x4 & mat)
1086 {
1087         glMatrixMode(GL_PROJECTION);
1088         double matrix[16];
1089         /* Get into argument. Looks a bit dodgy, but it's ok. */
1090         mat.getValue(matrix);
1091         /* Internally, MT_Matrix4x4 uses doubles (MT_Scalar). */
1092         glLoadMatrixd(matrix);  
1093 }
1094
1095 MT_Matrix4x4 RAS_OpenGLRasterizer::GetFrustumMatrix(
1096         float left,
1097         float right,
1098         float bottom,
1099         float top,
1100         float frustnear,
1101         float frustfar,
1102         bool
1103 ){
1104         MT_Matrix4x4 result;
1105         double mat[16];
1106
1107         // correction for stereo
1108         if(m_stereomode != RAS_STEREO_NOSTEREO)
1109         {
1110                         float near_div_focallength;
1111                         // next 2 params should be specified on command line and in Blender publisher
1112                         m_focallength = 1.5 * right;  // derived from example
1113                         m_eyeseparation = 0.18 * right;  // just a guess...
1114
1115                         near_div_focallength = frustnear / m_focallength;
1116                         switch(m_curreye)
1117                         {
1118                                 case RAS_STEREO_LEFTEYE:
1119                                                 left += 0.5 * m_eyeseparation * near_div_focallength;
1120                                                 right += 0.5 * m_eyeseparation * near_div_focallength;
1121                                                 break;
1122                                 case RAS_STEREO_RIGHTEYE:
1123                                                 left -= 0.5 * m_eyeseparation * near_div_focallength;
1124                                                 right -= 0.5 * m_eyeseparation * near_div_focallength;
1125                                                 break;
1126                         }
1127                         // leave bottom, top, bottom and top untouched
1128         }
1129         
1130         glMatrixMode(GL_PROJECTION);
1131         glLoadIdentity();
1132         glFrustum(left, right, bottom, top, frustnear, frustfar);
1133                 
1134         glGetDoublev(GL_PROJECTION_MATRIX, mat);
1135         result.setValue(mat);
1136
1137         return result;
1138 }
1139
1140
1141 // next arguments probably contain redundant info, for later...
1142 void RAS_OpenGLRasterizer::SetViewMatrix(const MT_Matrix4x4 &mat, const MT_Vector3& campos,
1143                 const MT_Point3 &, const MT_Quaternion &camOrientQuat)
1144 {
1145         MT_Matrix4x4 viewMat = mat;
1146
1147         // correction for stereo
1148         if(m_stereomode != RAS_STEREO_NOSTEREO)
1149         {
1150                 MT_Matrix3x3 camOrientMat3x3(camOrientQuat);
1151                 MT_Vector3 unitViewDir(0.0, -1.0, 0.0);  // minus y direction, Blender convention
1152                 MT_Vector3 unitViewupVec(0.0, 0.0, 1.0);
1153                 MT_Vector3 viewDir, viewupVec;
1154                 MT_Vector3 eyeline;
1155
1156                 // actual viewDir
1157                 viewDir = camOrientMat3x3 * unitViewDir;  // this is the moto convention, vector on right hand side
1158                 // actual viewup vec
1159                 viewupVec = camOrientMat3x3 * unitViewupVec;
1160
1161                 // vector between eyes
1162                 eyeline = viewDir.cross(viewupVec);
1163
1164                 switch(m_curreye)
1165                 {
1166                         case RAS_STEREO_LEFTEYE:
1167                                 {
1168                                 // translate to left by half the eye distance
1169                                 MT_Transform transform;
1170                                 transform.setIdentity();
1171                                 transform.translate(-(eyeline * m_eyeseparation / 2.0));
1172                                 viewMat *= transform;
1173                                 }
1174                                 break;
1175                         case RAS_STEREO_RIGHTEYE:
1176                                 {
1177                                 // translate to right by half the eye distance
1178                                 MT_Transform transform;
1179                                 transform.setIdentity();
1180                                 transform.translate(eyeline * m_eyeseparation / 2.0);
1181                                 viewMat *= transform;
1182                                 }
1183                                 break;
1184                 }
1185         }
1186
1187         // convert row major matrix 'viewMat' to column major for OpenGL
1188         MT_Scalar cammat[16];
1189         viewMat.getValue(cammat);
1190         MT_CmMatrix4x4 viewCmmat = cammat;
1191
1192         glMatrixMode(GL_MODELVIEW);
1193         m_viewmatrix = viewCmmat;
1194         glLoadMatrixd(&m_viewmatrix(0,0));
1195         m_campos = campos;
1196 }
1197
1198
1199 const MT_Point3& RAS_OpenGLRasterizer::GetCameraPosition()
1200 {
1201         return m_campos;
1202 }
1203
1204
1205
1206 void RAS_OpenGLRasterizer::LoadViewMatrix()
1207 {
1208         glLoadMatrixd(&m_viewmatrix(0,0));
1209 }
1210
1211
1212
1213 void RAS_OpenGLRasterizer::EnableTextures(bool enable)
1214 {
1215 }
1216
1217
1218
1219 void RAS_OpenGLRasterizer::SetCullFace(bool enable)
1220 {
1221         if (enable)
1222                 glEnable(GL_CULL_FACE);
1223         else
1224                 glDisable(GL_CULL_FACE);
1225 }
1226
1227 void RAS_OpenGLRasterizer::SetLines(bool enable)
1228 {
1229         if (enable)
1230                 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
1231         else
1232                 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1233 }
1234
1235 void RAS_OpenGLRasterizer::SetSpecularity(float specX,
1236                                                                                   float specY,
1237                                                                                   float specZ,
1238                                                                                   float specval)
1239 {
1240         GLfloat mat_specular[] = {specX, specY, specZ, specval};
1241         glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
1242 }
1243
1244
1245
1246 void RAS_OpenGLRasterizer::SetShinyness(float shiny)
1247 {
1248         GLfloat mat_shininess[] = {     shiny };
1249         glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
1250 }
1251
1252
1253
1254 void RAS_OpenGLRasterizer::SetDiffuse(float difX,float difY,float difZ,float diffuse)
1255 {
1256         GLfloat mat_diffuse [] = {difX, difY,difZ, diffuse};
1257         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
1258 }
1259
1260 double RAS_OpenGLRasterizer::GetTime()
1261 {
1262         return m_time;
1263 }
1264
1265