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