3 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20 * All rights reserved.
22 * The Original Code is: all of this file.
24 * Contributor(s): none yet.
26 * ***** END GPL LICENSE BLOCK *****
29 /** \file gameengine/BlenderRoutines/KX_BlenderGL.cpp
34 #include "KX_BlenderGL.h"
37 * This little block needed for linking to Blender...
41 #include "BLI_winstuff.h"
49 #include "MEM_guardedalloc.h"
51 #include "BL_Material.h" // MAXTEX
53 /* Data types encoding the game world: */
54 #include "DNA_object_types.h"
55 #include "DNA_scene_types.h"
56 #include "DNA_screen_types.h"
57 #include "DNA_camera_types.h"
58 #include "DNA_world_types.h"
59 #include "DNA_mesh_types.h"
60 #include "DNA_meshdata_types.h"
61 #include "DNA_image_types.h"
62 #include "DNA_view3d_types.h"
63 #include "DNA_material_types.h"
64 #include "DNA_windowmanager_types.h"
66 #include "BKE_global.h"
68 #include "BKE_bmfont.h"
69 #include "BKE_image.h"
71 #include "BLI_path_util.h"
74 #include "IMB_imbuf_types.h"
75 #include "IMB_imbuf.h"
78 #include "wm_event_system.h"
79 #include "wm_cursors.h"
80 #include "wm_window.h"
84 /* end of blender block */
85 void BL_warp_pointer(wmWindow *win, int x,int y)
87 WM_cursor_warp(win, x, y);
90 void BL_SwapBuffers(wmWindow *win)
92 wm_window_swap_buffers(win);
97 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); /* needed for texture fonts otherwise they render as wireframe */
99 if(glIsEnabled(GL_BLEND)) glDisable(GL_BLEND);
100 if(glIsEnabled(GL_ALPHA_TEST)) glDisable(GL_ALPHA_TEST);
102 if(glIsEnabled(GL_LIGHTING)) {
103 glDisable(GL_LIGHTING);
104 glDisable(GL_COLOR_MATERIAL);
107 if(GLEW_ARB_multitexture) {
108 for(int i=0; i<MAXTEX; i++) {
109 glActiveTextureARB(GL_TEXTURE0_ARB+i);
111 if(GLEW_ARB_texture_cube_map)
112 if(glIsEnabled(GL_TEXTURE_CUBE_MAP_ARB))
113 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
115 if(glIsEnabled(GL_TEXTURE_2D))
116 glDisable(GL_TEXTURE_2D);
119 glActiveTextureARB(GL_TEXTURE0_ARB);
122 if(GLEW_ARB_texture_cube_map)
123 if(glIsEnabled(GL_TEXTURE_CUBE_MAP_ARB))
124 glDisable(GL_TEXTURE_CUBE_MAP_ARB);
126 if(glIsEnabled(GL_TEXTURE_2D))
127 glDisable(GL_TEXTURE_2D);
132 void BL_print_game_line(int fontid, const char* text, int size, int dpi, float* color, double* mat, float aspect)
137 /* the actual drawing */
140 /* multiply the text matrix by the object matrix */
141 BLF_enable(fontid, BLF_MATRIX|BLF_ASPECT);
142 BLF_matrix(fontid, mat);
144 /* aspect is the inverse scale that allows you to increase */
145 /* your resolution without sizing the final text size */
146 /* the bigger the size, the smaller the aspect */
147 BLF_aspect(fontid, aspect, aspect, aspect);
149 BLF_size(fontid, size, dpi);
150 BLF_position(fontid, 0, 0, 0);
151 BLF_draw(fontid, (char *)text, strlen(text));
153 BLF_disable(fontid, BLF_MATRIX|BLF_ASPECT);
156 void BL_print_gamedebug_line(const char* text, int xco, int yco, int width, int height)
160 glDisable(GL_DEPTH_TEST);
162 glMatrixMode(GL_PROJECTION);
166 glOrtho(0, width, 0, height, -100, 100);
168 glMatrixMode(GL_MODELVIEW);
172 /* the actual drawing */
173 glColor3ub(255, 255, 255);
174 BLF_draw_default((float)xco, (float)(height-yco), 0.0f, (char *)text, 65535); /* XXX, use real len */
176 glMatrixMode(GL_PROJECTION);
178 glMatrixMode(GL_MODELVIEW);
180 glEnable(GL_DEPTH_TEST);
183 void BL_print_gamedebug_line_padded(const char* text, int xco, int yco, int width, int height)
185 /* This is a rather important line :( The gl-mode hasn't been left
186 * behind quite as neatly as we'd have wanted to. I don't know
187 * what cause it, though :/ .*/
189 glDisable(GL_DEPTH_TEST);
191 glMatrixMode(GL_PROJECTION);
195 glOrtho(0, width, 0, height, -100, 100);
197 glMatrixMode(GL_MODELVIEW);
201 /* draw in black first*/
203 BLF_draw_default((float)(xco+2), (float)(height-yco-2), 0.0f, text, 65535); /* XXX, use real len */
204 glColor3ub(255, 255, 255);
205 BLF_draw_default((float)xco, (float)(height-yco), 0.0f, text, 65535); /* XXX, use real len */
207 glMatrixMode(GL_PROJECTION);
209 glMatrixMode(GL_MODELVIEW);
211 glEnable(GL_DEPTH_TEST);
214 void BL_HideMouse(wmWindow *win)
216 WM_cursor_set(win, CURSOR_NONE);
220 void BL_WaitMouse(wmWindow *win)
222 WM_cursor_set(win, CURSOR_WAIT);
226 void BL_NormalMouse(wmWindow *win)
228 WM_cursor_set(win, CURSOR_STD);
230 #define MAX_FILE_LENGTH 512
232 /* get shot from frontbuffer sort of a copy from screendump.c */
233 static unsigned int *screenshot(ScrArea *curarea, int *dumpsx, int *dumpsy)
236 unsigned int *dumprect= NULL;
238 x= curarea->totrct.xmin;
239 y= curarea->totrct.ymin;
240 *dumpsx= curarea->totrct.xmax-x;
241 *dumpsy= curarea->totrct.ymax-y;
243 if (*dumpsx && *dumpsy) {
245 dumprect= (unsigned int *)MEM_mallocN(sizeof(int) * (*dumpsx) * (*dumpsy), "dumprect");
246 glReadBuffer(GL_FRONT);
247 glReadPixels(x, y, *dumpsx, *dumpsy, GL_RGBA, GL_UNSIGNED_BYTE, dumprect);
249 glReadBuffer(GL_BACK);
255 /* based on screendump.c::screenshot_exec */
256 void BL_MakeScreenShot(ScrArea *curarea, const char* filename)
258 char path[MAX_FILE_LENGTH];
259 strcpy(path,filename);
261 unsigned int *dumprect;
264 dumprect= screenshot(curarea, &dumpsx, &dumpsy);
267 BLI_path_abs(path, G.main->name);
268 /* BKE_add_image_extension() checks for if extension was already set */
269 BKE_add_image_extension(path, R_PNG); /* scene->r.imtype */
270 ibuf= IMB_allocImBuf(dumpsx, dumpsy, 24, 0);
271 ibuf->rect= dumprect;
274 IMB_saveiff(ibuf, path, IB_rect);