Big, big commit!!
[blender.git] / source / gameengine / BlenderRoutines / KX_BlenderGL.cpp
1 /**
2  * $Id$
3  * ***** BEGIN GPL 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.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  *
19  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20  * All rights reserved.
21  *
22  * The Original Code is: all of this file.
23  *
24  * Contributor(s): none yet.
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include "KX_BlenderGL.h"
30
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
34
35 /* 
36  * This little block needed for linking to Blender... 
37  */
38 #ifdef WIN32
39 #include "BLI_winstuff.h"
40 #endif
41
42 #include <stdlib.h>
43 #include <string.h>
44
45 #include "GL/glew.h"
46
47 #include "BL_Material.h" // MAXTEX
48
49 /* Data types encoding the game world: */
50 #include "DNA_object_types.h"
51 #include "DNA_scene_types.h"
52 #include "DNA_screen_types.h"
53 #include "DNA_camera_types.h"
54 #include "DNA_world_types.h"
55 #include "DNA_mesh_types.h"
56 #include "DNA_meshdata_types.h"
57 #include "DNA_image_types.h"
58 #include "DNA_view3d_types.h"
59 #include "DNA_material_types.h"
60
61 #include "BKE_global.h"
62 #include "BKE_bmfont.h"
63 #include "BKE_image.h"
64
65 extern "C" {
66 //XXX #include "BDR_drawmesh.h"
67 //XXX #include "BIF_mywindow.h"
68 //XXX #include "BIF_toolbox.h"
69 //XXX #include "BIF_graphics.h" /* For CURSOR_NONE CURSOR_WAIT CURSOR_STD */
70
71 }
72
73 /* end of blender block */
74
75 /* was in drawmesh.c */
76 void spack(unsigned int ucol)
77 {
78         char *cp= (char *)&ucol;
79         
80         glColor3ub(cp[3], cp[2], cp[1]);
81 }
82
83 void BL_warp_pointer(int x,int y)
84 {
85         //XXX warp_pointer(x,y);
86 }
87
88 void BL_SwapBuffers()
89 {
90         //XXX myswapbuffers();
91 }
92
93 void DisableForText()
94 {
95         if(glIsEnabled(GL_BLEND)) glDisable(GL_BLEND);
96         if(glIsEnabled(GL_ALPHA_TEST)) glDisable(GL_ALPHA_TEST);
97
98         if(glIsEnabled(GL_LIGHTING)) {
99                 glDisable(GL_LIGHTING);
100                 glDisable(GL_COLOR_MATERIAL);
101         }
102
103         if(GLEW_ARB_multitexture) {
104                 for(int i=0; i<MAXTEX; i++) {
105                         glActiveTextureARB(GL_TEXTURE0_ARB+i);
106
107                         if(GLEW_ARB_texture_cube_map)
108                                 if(glIsEnabled(GL_TEXTURE_CUBE_MAP_ARB))
109                                         glDisable(GL_TEXTURE_CUBE_MAP_ARB);
110
111                         if(glIsEnabled(GL_TEXTURE_2D))
112                                 glDisable(GL_TEXTURE_2D);
113                 }
114
115                 glActiveTextureARB(GL_TEXTURE0_ARB);
116         }
117         else {
118                 if(GLEW_ARB_texture_cube_map)
119                         if(glIsEnabled(GL_TEXTURE_CUBE_MAP_ARB))
120                                 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
121
122                 if(glIsEnabled(GL_TEXTURE_2D))
123                         glDisable(GL_TEXTURE_2D);
124         }
125 }
126
127 void BL_print_gamedebug_line(char* text, int xco, int yco, int width, int height)
128 {       
129         /* gl prepping */
130         DisableForText();
131         //glDisable(GL_TEXTURE_2D);
132
133         glMatrixMode(GL_PROJECTION);
134         glPushMatrix();
135         glLoadIdentity();
136         
137         glOrtho(0, width,
138                         0, height, 0, 1);
139         
140         glMatrixMode(GL_MODELVIEW);
141         glPushMatrix();
142         glLoadIdentity();
143         glMatrixMode(GL_TEXTURE);
144         glPushMatrix();
145         glLoadIdentity();
146
147         /* the actual drawing */
148         glColor3ub(255, 255, 255);
149         BLF_draw_default(xco, height-yco, 0.0f, text);
150
151         glMatrixMode(GL_TEXTURE);
152         glPopMatrix();
153         glMatrixMode(GL_PROJECTION);
154         glPopMatrix();
155         glMatrixMode(GL_MODELVIEW);
156         glPopMatrix();
157         glEnable(GL_DEPTH_TEST);
158 }
159
160 void BL_print_gamedebug_line_padded(char* text, int xco, int yco, int width, int height)
161 {
162         /* This is a rather important line :( The gl-mode hasn't been left
163          * behind quite as neatly as we'd have wanted to. I don't know
164          * what cause it, though :/ .*/
165         DisableForText();
166         //glDisable(GL_TEXTURE_2D);
167
168         glMatrixMode(GL_PROJECTION);
169         glPushMatrix();
170         glLoadIdentity();
171         
172         glOrtho(0, width,
173                         0, height, 0, 1);
174         
175         glMatrixMode(GL_MODELVIEW);
176         glPushMatrix();
177         glLoadIdentity();
178         glMatrixMode(GL_TEXTURE);
179         glPushMatrix();
180         glLoadIdentity();
181
182         /* draw in black first*/
183         glColor3ub(0, 0, 0);
184         BLF_draw_default(xco+1, height-yco-1, 0.0f, text);
185         glColor3ub(255, 255, 255);
186         BLF_draw_default(xco, height-yco, 0.0f, text);
187
188         glMatrixMode(GL_TEXTURE);
189         glPopMatrix();
190         glMatrixMode(GL_PROJECTION);
191         glPopMatrix();
192         glMatrixMode(GL_MODELVIEW);
193         glPopMatrix();
194         glEnable(GL_DEPTH_TEST);
195 }
196
197 void BL_HideMouse()
198 {
199         //XXX set_cursor(CURSOR_NONE);
200 }
201
202
203 void BL_WaitMouse()
204 {
205         //XXX set_cursor(CURSOR_WAIT);
206 }
207
208
209 void BL_NormalMouse()
210 {
211         //XXX set_cursor(CURSOR_STD);
212 }
213 #define MAX_FILE_LENGTH 512
214
215
216 void BL_MakeScreenShot(struct ScrArea *area, const char* filename)
217 {
218         char copyfilename[MAX_FILE_LENGTH];
219         strcpy(copyfilename,filename);
220
221         // filename read - only
222         
223           /* XXX will need to change at some point */
224         //XXX BIF_screendump(0);
225
226         // write+read filename
227         //XXX write_screendump((char*) copyfilename);
228 }
229