* fix snprintf error with mingw
[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 <vector>
48 #include "BLI_winstuff.h"
49 #endif
50
51 #include <stdlib.h>
52 #include <string.h>
53
54 #include "GL/glew.h"
55
56 #include "BL_Material.h" // MAXTEX
57
58 /* Data types encoding the game world: */
59 #include "DNA_object_types.h"
60 #include "DNA_scene_types.h"
61 #include "DNA_screen_types.h"
62 #include "DNA_camera_types.h"
63 #include "DNA_world_types.h"
64 #include "DNA_mesh_types.h"
65 #include "DNA_meshdata_types.h"
66 #include "DNA_image_types.h"
67 #include "DNA_view3d_types.h"
68 #include "DNA_material_types.h"
69 #include "DNA_windowmanager_types.h"
70
71 #include "BKE_global.h"
72 #include "BKE_bmfont.h"
73 #include "BKE_image.h"
74
75 extern "C" {
76 //XXX #include "BDR_drawmesh.h"
77 //XXX #include "BIF_mywindow.h"
78 //XXX #include "BIF_toolbox.h"
79 //XXX #include "BIF_graphics.h" /* For CURSOR_NONE CURSOR_WAIT CURSOR_STD */
80 void wm_window_swap_buffers(wmWindow *win); // wm_window.h
81 }
82
83 /* end of blender block */
84
85 /* was in drawmesh.c */
86 void spack(unsigned int ucol)
87 {
88         char *cp= (char *)&ucol;
89         
90         glColor3ub(cp[3], cp[2], cp[1]);
91 }
92
93 void BL_warp_pointer(int x,int y)
94 {
95         //XXX warp_pointer(x,y);
96 }
97
98 void BL_SwapBuffers(wmWindow *win)
99 {
100         //wmWindow *window= CTX_wm_window(C);
101         wm_window_swap_buffers(win);
102         //XXX myswapbuffers();
103 }
104
105 void DisableForText()
106 {
107         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); /* needed for texture fonts otherwise they render as wireframe */
108
109         if(glIsEnabled(GL_BLEND)) glDisable(GL_BLEND);
110         if(glIsEnabled(GL_ALPHA_TEST)) glDisable(GL_ALPHA_TEST);
111
112         if(glIsEnabled(GL_LIGHTING)) {
113                 glDisable(GL_LIGHTING);
114                 glDisable(GL_COLOR_MATERIAL);
115         }
116
117         if(GLEW_ARB_multitexture) {
118                 for(int i=0; i<MAXTEX; i++) {
119                         glActiveTextureARB(GL_TEXTURE0_ARB+i);
120
121                         if(GLEW_ARB_texture_cube_map)
122                                 if(glIsEnabled(GL_TEXTURE_CUBE_MAP_ARB))
123                                         glDisable(GL_TEXTURE_CUBE_MAP_ARB);
124
125                         if(glIsEnabled(GL_TEXTURE_2D))
126                                 glDisable(GL_TEXTURE_2D);
127                 }
128
129                 glActiveTextureARB(GL_TEXTURE0_ARB);
130         }
131         else {
132                 if(GLEW_ARB_texture_cube_map)
133                         if(glIsEnabled(GL_TEXTURE_CUBE_MAP_ARB))
134                                 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
135
136                 if(glIsEnabled(GL_TEXTURE_2D))
137                         glDisable(GL_TEXTURE_2D);
138         }
139 }
140
141 void BL_print_gamedebug_line(const char* text, int xco, int yco, int width, int height)
142 {       
143         /* gl prepping */
144         DisableForText();
145
146         glMatrixMode(GL_PROJECTION);
147         glPushMatrix();
148         glLoadIdentity();
149
150         glOrtho(0, width, 0, height, -100, 100);
151
152         glMatrixMode(GL_MODELVIEW);
153         glPushMatrix();
154         glLoadIdentity();
155
156         /* the actual drawing */
157         glColor3ub(255, 255, 255);
158         BLF_draw_default(xco, height-yco, 0.0f, (char *)text);
159
160         glMatrixMode(GL_PROJECTION);
161         glPopMatrix();
162         glMatrixMode(GL_MODELVIEW);
163         glPopMatrix();
164         glEnable(GL_DEPTH_TEST);
165 }
166
167 void BL_print_gamedebug_line_padded(const char* text, int xco, int yco, int width, int height)
168 {
169         /* This is a rather important line :( The gl-mode hasn't been left
170          * behind quite as neatly as we'd have wanted to. I don't know
171          * what cause it, though :/ .*/
172         DisableForText();
173
174         glMatrixMode(GL_PROJECTION);
175         glPushMatrix();
176         glLoadIdentity();
177         
178         glOrtho(0, width, 0, height, -100, 100);
179         
180         glMatrixMode(GL_MODELVIEW);
181         glPushMatrix();
182         glLoadIdentity();
183
184         /* draw in black first*/
185         glColor3ub(0, 0, 0);
186         BLF_draw_default(xco+2, height-yco-2, 0.0f, (char *)text);
187         glColor3ub(255, 255, 255);
188         BLF_draw_default(xco, height-yco, 0.0f, (char *)text);
189
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 ARegion *ar, 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