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