soc-2008-mxcurioni: merged changes to revision 15705
[blender.git] / source / gameengine / GamePlayer / common / GPC_RenderTools.h
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 #ifndef __GPC_RENDERTOOLS_H
31 #define __GPC_RENDERTOOLS_H
32
33 #ifdef WIN32
34         #include <windows.h>
35 #endif // WIN32
36
37 #include "GL/glew.h"
38
39 #include "RAS_IRenderTools.h"
40
41 #include "BMF_Api.h"
42
43 struct KX_ClientObjectInfo;
44
45
46 class GPC_RenderTools : public RAS_IRenderTools
47 {
48 public:
49         GPC_RenderTools();
50         virtual ~GPC_RenderTools();
51
52         virtual void EndFrame(RAS_IRasterizer* rasty);
53         virtual void BeginFrame(RAS_IRasterizer* rasty);
54
55         void DisableOpenGLLights()
56         {
57                 glDisable(GL_LIGHTING);
58                 glDisable(GL_COLOR_MATERIAL);
59         }
60
61         void EnableOpenGLLights();
62
63         int ProcessLighting(int layer);
64
65         void Perspective(int a, int width, int height, float mat[4][4], float viewmat[4][4])
66         {
67                 if(a== 0)
68                 {
69                         glMatrixMode(GL_PROJECTION);
70                         glMatrixMode(GL_MODELVIEW);
71                         glLoadIdentity();
72                 }
73                 else
74                 {
75                         if(a== 1)
76                         {
77                                 glMatrixMode(GL_PROJECTION);
78                                 glMatrixMode(GL_MODELVIEW);
79                         }
80                 }
81         }
82
83         /**
84          * @attention mode is ignored here
85          */
86         virtual void RenderText2D(
87                                         RAS_TEXT_RENDER_MODE mode,
88                                         const char* text,
89                                         int xco,
90                                         int yco,
91                                         int width,
92                                         int height);
93
94         /**
95          * Renders text into a (series of) polygon(s), using a texture font,
96          * Each character consists of one polygon (one quad or two triangles)
97          */
98         virtual void RenderText(
99                                         int mode,
100                                         RAS_IPolyMaterial* polymat,
101                                         float v1[3],
102                                         float v2[3],
103                                         float v3[3],
104                                         float v4[3]);
105
106         void Render(RAS_IRasterizer* rasty,double* oglmatrix,int objectdrawmode)
107         {
108                 glPopMatrix();
109                 glPushMatrix();
110                 glMultMatrixd(oglmatrix);
111         }
112
113         void applyTransform(RAS_IRasterizer* rasty, double* oglmatrix, int objectdrawmode);
114
115         virtual void PushMatrix()
116         {
117                 glPushMatrix();
118         }
119
120         virtual void PopMatrix()
121         {
122                 glPopMatrix();
123         }
124
125         virtual class RAS_IPolyMaterial* CreateBlenderPolyMaterial(
126                         const STR_String &texname,
127                         bool ba,
128                         const STR_String& matname,
129                         int tile,
130                         int tilexrep,int tileyrep,
131                         int mode,
132                         bool transparant,
133                         bool zsort,
134                         int lightlayer,
135                         bool bIsTriangle,
136                         void* clientobject,
137                         void* tface);
138
139         int applyLights(int objectlayer);
140
141         bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data);
142
143         virtual void MotionBlur(RAS_IRasterizer* rasterizer);
144
145         virtual void Update2DFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text);
146
147         virtual void Render2DFilters(RAS_ICanvas* canvas);
148
149         virtual void SetClientObject(void* obj);
150
151 protected:
152         /** 
153          * Copied from KX_BlenderGL.cpp in KX_blenderhook
154          */
155         void BL_RenderText(
156                 int mode,
157                 const char* textstr,
158                 int textlen,
159                 struct MTFace* tface,
160                 unsigned int* col,
161                 float v1[3],float v2[3],float v3[3],float v4[3]);
162         void BL_spack(unsigned int ucol)
163         {
164                 char *cp = (char *)&ucol;               
165                 glColor3ub(cp[3], cp[2], cp[1]);
166         }
167
168
169         BMF_Font* m_font;
170         static unsigned int m_numgllights;
171 };
172
173 #endif  // __GPC_RENDERTOOLS_H
174
175
176