svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r22099:22130
[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         if(glIsEnabled(GL_BLEND)) glDisable(GL_BLEND);
107         if(glIsEnabled(GL_ALPHA_TEST)) glDisable(GL_ALPHA_TEST);
108
109         if(glIsEnabled(GL_LIGHTING)) {
110                 glDisable(GL_LIGHTING);
111                 glDisable(GL_COLOR_MATERIAL);
112         }
113
114         if(GLEW_ARB_multitexture) {
115                 for(int i=0; i<MAXTEX; i++) {
116                         glActiveTextureARB(GL_TEXTURE0_ARB+i);
117
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                 glActiveTextureARB(GL_TEXTURE0_ARB);
127         }
128         else {
129                 if(GLEW_ARB_texture_cube_map)
130                         if(glIsEnabled(GL_TEXTURE_CUBE_MAP_ARB))
131                                 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
132
133                 if(glIsEnabled(GL_TEXTURE_2D))
134                         glDisable(GL_TEXTURE_2D);
135         }
136 }
137
138 void BL_print_gamedebug_line(char* text, int xco, int yco, int width, int height)
139 {       
140         /* gl prepping */
141         DisableForText();
142         //glDisable(GL_TEXTURE_2D);
143
144         glMatrixMode(GL_PROJECTION);
145         glPushMatrix();
146         glLoadIdentity();
147         
148         glOrtho(0, width,
149                         0, height, 0, 1);
150         
151         glMatrixMode(GL_MODELVIEW);
152         glPushMatrix();
153         glLoadIdentity();
154         glMatrixMode(GL_TEXTURE);
155         glPushMatrix();
156         glLoadIdentity();
157
158         /* the actual drawing */
159         glColor3ub(255, 255, 255);
160         BLF_draw_default(xco, height-yco, 0.0f, text);
161
162         glMatrixMode(GL_TEXTURE);
163         glPopMatrix();
164         glMatrixMode(GL_PROJECTION);
165         glPopMatrix();
166         glMatrixMode(GL_MODELVIEW);
167         glPopMatrix();
168         glEnable(GL_DEPTH_TEST);
169 }
170
171 void BL_print_gamedebug_line_padded(char* text, int xco, int yco, int width, int height)
172 {
173         /* This is a rather important line :( The gl-mode hasn't been left
174          * behind quite as neatly as we'd have wanted to. I don't know
175          * what cause it, though :/ .*/
176         DisableForText();
177         //glDisable(GL_TEXTURE_2D);
178
179         glMatrixMode(GL_PROJECTION);
180         glPushMatrix();
181         glLoadIdentity();
182         
183         glOrtho(0, width,
184                         0, height, 0, 1);
185         
186         glMatrixMode(GL_MODELVIEW);
187         glPushMatrix();
188         glLoadIdentity();
189         glMatrixMode(GL_TEXTURE);
190         glPushMatrix();
191         glLoadIdentity();
192
193         /* draw in black first*/
194         glColor3ub(0, 0, 0);
195         BLF_draw_default(xco+1, height-yco-1, 0.0f, text);
196         glColor3ub(255, 255, 255);
197         BLF_draw_default(xco, height-yco, 0.0f, text);
198
199         glMatrixMode(GL_TEXTURE);
200         glPopMatrix();
201         glMatrixMode(GL_PROJECTION);
202         glPopMatrix();
203         glMatrixMode(GL_MODELVIEW);
204         glPopMatrix();
205         glEnable(GL_DEPTH_TEST);
206 }
207
208 void BL_HideMouse()
209 {
210         //XXX set_cursor(CURSOR_NONE);
211 }
212
213
214 void BL_WaitMouse()
215 {
216         //XXX set_cursor(CURSOR_WAIT);
217 }
218
219
220 void BL_NormalMouse()
221 {
222         //XXX set_cursor(CURSOR_STD);
223 }
224 #define MAX_FILE_LENGTH 512
225
226
227 void BL_MakeScreenShot(struct ARegion *ar, const char* filename)
228 {
229         char copyfilename[MAX_FILE_LENGTH];
230         strcpy(copyfilename,filename);
231
232         // filename read - only
233         
234           /* XXX will need to change at some point */
235         //XXX BIF_screendump(0);
236
237         // write+read filename
238         //XXX write_screendump((char*) copyfilename);
239 }
240