text display (debug info) in the game engine working again & other minor changes.
[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 __cplusplus
32 extern "C" {
33 #endif
34 #include "BLF_api.h"
35 #ifdef __cplusplus
36 }
37 #endif
38
39 #ifdef HAVE_CONFIG_H
40 #include <config.h>
41 #endif
42
43 /* 
44  * This little block needed for linking to Blender... 
45  */
46 #ifdef WIN32
47 #include "BLI_winstuff.h"
48 #endif
49
50 #include <stdlib.h>
51 #include <string.h>
52
53 #include "GL/glew.h"
54
55 #include "BL_Material.h" // MAXTEX
56
57 /* Data types encoding the game world: */
58 #include "DNA_object_types.h"
59 #include "DNA_scene_types.h"
60 #include "DNA_screen_types.h"
61 #include "DNA_camera_types.h"
62 #include "DNA_world_types.h"
63 #include "DNA_mesh_types.h"
64 #include "DNA_meshdata_types.h"
65 #include "DNA_image_types.h"
66 #include "DNA_view3d_types.h"
67 #include "DNA_material_types.h"
68 #include "DNA_windowmanager_types.h"
69
70 #include "BKE_global.h"
71 #include "BKE_bmfont.h"
72 #include "BKE_image.h"
73
74 extern "C" {
75 //XXX #include "BDR_drawmesh.h"
76 //XXX #include "BIF_mywindow.h"
77 //XXX #include "BIF_toolbox.h"
78 //XXX #include "BIF_graphics.h" /* For CURSOR_NONE CURSOR_WAIT CURSOR_STD */
79 void wm_window_swap_buffers(wmWindow *win); // wm_window.h
80 }
81
82 /* end of blender block */
83
84 /* was in drawmesh.c */
85 void spack(unsigned int ucol)
86 {
87         char *cp= (char *)&ucol;
88         
89         glColor3ub(cp[3], cp[2], cp[1]);
90 }
91
92 void BL_warp_pointer(int x,int y)
93 {
94         //XXX warp_pointer(x,y);
95 }
96
97 void BL_SwapBuffers(wmWindow *win)
98 {
99         //wmWindow *window= CTX_wm_window(C);
100         wm_window_swap_buffers(win);
101         //XXX myswapbuffers();
102 }
103
104 void DisableForText()
105 {
106         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); /* needed for texture fonts otherwise they render as wireframe */
107
108         if(glIsEnabled(GL_BLEND)) glDisable(GL_BLEND);
109         if(glIsEnabled(GL_ALPHA_TEST)) glDisable(GL_ALPHA_TEST);
110
111         if(glIsEnabled(GL_LIGHTING)) {
112                 glDisable(GL_LIGHTING);
113                 glDisable(GL_COLOR_MATERIAL);
114         }
115
116         if(GLEW_ARB_multitexture) {
117                 for(int i=0; i<MAXTEX; i++) {
118                         glActiveTextureARB(GL_TEXTURE0_ARB+i);
119
120                         if(GLEW_ARB_texture_cube_map)
121                                 if(glIsEnabled(GL_TEXTURE_CUBE_MAP_ARB))
122                                         glDisable(GL_TEXTURE_CUBE_MAP_ARB);
123
124                         if(glIsEnabled(GL_TEXTURE_2D))
125                                 glDisable(GL_TEXTURE_2D);
126                 }
127
128                 glActiveTextureARB(GL_TEXTURE0_ARB);
129         }
130         else {
131                 if(GLEW_ARB_texture_cube_map)
132                         if(glIsEnabled(GL_TEXTURE_CUBE_MAP_ARB))
133                                 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
134
135                 if(glIsEnabled(GL_TEXTURE_2D))
136                         glDisable(GL_TEXTURE_2D);
137         }
138 }
139
140 void BL_print_gamedebug_line(const char* text, int xco, int yco, int width, int height)
141 {       
142         /* gl prepping */
143         DisableForText();
144
145         glMatrixMode(GL_PROJECTION);
146         glPushMatrix();
147         glLoadIdentity();
148
149         glOrtho(0, width, 0, height, -100, 100);
150
151         glMatrixMode(GL_MODELVIEW);
152         glPushMatrix();
153         glLoadIdentity();
154
155         /* the actual drawing */
156         glColor3ub(255, 255, 255);
157         BLF_draw_default(xco, height-yco, 0.0f, (char *)text);
158
159         glMatrixMode(GL_PROJECTION);
160         glPopMatrix();
161         glMatrixMode(GL_MODELVIEW);
162         glPopMatrix();
163         glEnable(GL_DEPTH_TEST);
164 }
165
166 void BL_print_gamedebug_line_padded(const char* text, int xco, int yco, int width, int height)
167 {
168         /* This is a rather important line :( The gl-mode hasn't been left
169          * behind quite as neatly as we'd have wanted to. I don't know
170          * what cause it, though :/ .*/
171         DisableForText();
172
173         glMatrixMode(GL_PROJECTION);
174         glPushMatrix();
175         glLoadIdentity();
176         
177         glOrtho(0, width, 0, height, -100, 100);
178         
179         glMatrixMode(GL_MODELVIEW);
180         glPushMatrix();
181         glLoadIdentity();
182
183         /* draw in black first*/
184         glColor3ub(0, 0, 0);
185         BLF_draw_default(xco+2, height-yco-2, 0.0f, (char *)text);
186         glColor3ub(255, 255, 255);
187         BLF_draw_default(xco, height-yco, 0.0f, (char *)text);
188
189         glMatrixMode(GL_PROJECTION);
190         glPopMatrix();
191         glMatrixMode(GL_MODELVIEW);
192         glPopMatrix();
193         glEnable(GL_DEPTH_TEST);
194 }
195
196 void BL_HideMouse()
197 {
198         //XXX set_cursor(CURSOR_NONE);
199 }
200
201
202 void BL_WaitMouse()
203 {
204         //XXX set_cursor(CURSOR_WAIT);
205 }
206
207
208 void BL_NormalMouse()
209 {
210         //XXX set_cursor(CURSOR_STD);
211 }
212 #define MAX_FILE_LENGTH 512
213
214
215 void BL_MakeScreenShot(struct ARegion *ar, const char* filename)
216 {
217         char copyfilename[MAX_FILE_LENGTH];
218         strcpy(copyfilename,filename);
219
220         // filename read - only
221         
222           /* XXX will need to change at some point */
223         //XXX BIF_screendump(0);
224
225         // write+read filename
226         //XXX write_screendump((char*) copyfilename);
227 }
228