doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / gameengine / BlenderRoutines / KX_BlenderGL.cpp
index b718dfc..08280cd 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
@@ -14,7 +14,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  * All rights reserved.
 
 #include "KX_BlenderGL.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-#include "BLF_api.h"
-#ifdef __cplusplus
-}
-#endif
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 /* 
  * This little block needed for linking to Blender... 
  */
@@ -53,6 +41,8 @@ extern "C" {
 
 #include "GL/glew.h"
 
+#include "MEM_guardedalloc.h"
+
 #include "BL_Material.h" // MAXTEX
 
 /* Data types encoding the game world: */
@@ -69,27 +59,24 @@ extern "C" {
 #include "DNA_windowmanager_types.h"
 
 #include "BKE_global.h"
+#include "BKE_main.h"
 #include "BKE_bmfont.h"
 #include "BKE_image.h"
 
+#include "BLI_path_util.h"
+
 extern "C" {
+#include "IMB_imbuf_types.h"
+#include "IMB_imbuf.h"
 #include "WM_api.h"
 #include "WM_types.h"
 #include "wm_event_system.h"
 #include "wm_cursors.h"
 #include "wm_window.h"
+#include "BLF_api.h"
 }
 
 /* end of blender block */
-
-/* was in drawmesh.c */
-void spack(unsigned int ucol)
-{
-       char *cp= (char *)&ucol;
-        
-       glColor3ub(cp[3], cp[2], cp[1]);
-}
-
 void BL_warp_pointer(wmWindow *win, int x,int y)
 {
        WM_cursor_warp(win, x, y);
@@ -136,10 +123,36 @@ void DisableForText()
        }
 }
 
+/* Print 3D text */
+void BL_print_game_line(int fontid, const char* text, int size, int dpi, float* color, double* mat, float aspect)
+{
+       /* gl prepping */
+       DisableForText();
+
+       /* the actual drawing */
+       glColor4fv(color);
+
+       /* multiply the text matrix by the object matrix */
+       BLF_enable(fontid, BLF_MATRIX|BLF_ASPECT);
+       BLF_matrix(fontid, mat);
+
+       /* aspect is the inverse scale that allows you to increase */
+       /* your resolution without sizing the final text size      */
+       /* the bigger the size, the smaller the aspect             */
+       BLF_aspect(fontid, aspect, aspect, aspect);
+
+       BLF_size(fontid, size, dpi);
+       BLF_position(fontid, 0, 0, 0);
+       BLF_draw(fontid, (char *)text, strlen(text));
+
+       BLF_disable(fontid, BLF_MATRIX|BLF_ASPECT);
+}
+
 void BL_print_gamedebug_line(const char* text, int xco, int yco, int width, int height)
 {      
        /* gl prepping */
        DisableForText();
+       glDisable(GL_DEPTH_TEST);
 
        glMatrixMode(GL_PROJECTION);
        glPushMatrix();
@@ -153,7 +166,7 @@ void BL_print_gamedebug_line(const char* text, int xco, int yco, int width, int
 
        /* the actual drawing */
        glColor3ub(255, 255, 255);
-       BLF_draw_default(xco, height-yco, 0.0f, (char *)text);
+       BLF_draw_default(xco, height-yco, 0.0f, (char *)text, 65535); /* XXX, use real len */
 
        glMatrixMode(GL_PROJECTION);
        glPopMatrix();
@@ -168,6 +181,7 @@ void BL_print_gamedebug_line_padded(const char* text, int xco, int yco, int widt
         * behind quite as neatly as we'd have wanted to. I don't know
         * what cause it, though :/ .*/
        DisableForText();
+       glDisable(GL_DEPTH_TEST);
 
        glMatrixMode(GL_PROJECTION);
        glPushMatrix();
@@ -181,9 +195,9 @@ void BL_print_gamedebug_line_padded(const char* text, int xco, int yco, int widt
 
        /* draw in black first*/
        glColor3ub(0, 0, 0);
-       BLF_draw_default(xco+2, height-yco-2, 0.0f, (char *)text);
+       BLF_draw_default(xco+2, height-yco-2, 0.0f, text, 65535); /* XXX, use real len */
        glColor3ub(255, 255, 255);
-       BLF_draw_default(xco, height-yco, 0.0f, (char *)text);
+       BLF_draw_default(xco, height-yco, 0.0f, text, 65535); /* XXX, use real len */
 
        glMatrixMode(GL_PROJECTION);
        glPopMatrix();
@@ -210,18 +224,53 @@ void BL_NormalMouse(wmWindow *win)
 }
 #define MAX_FILE_LENGTH 512
 
+/* get shot from frontbuffer sort of a copy from screendump.c */
+static unsigned int *screenshot(ScrArea *curarea, int *dumpsx, int *dumpsy)
+{
+       int x=0, y=0;
+       unsigned int *dumprect= NULL;
+       
+       x= curarea->totrct.xmin;
+       y= curarea->totrct.ymin;
+       *dumpsx= curarea->totrct.xmax-x;
+       *dumpsy= curarea->totrct.ymax-y;
+
+       if (*dumpsx && *dumpsy) {
+               
+               dumprect= (unsigned int *)MEM_mallocN(sizeof(int) * (*dumpsx) * (*dumpsy), "dumprect");
+               glReadBuffer(GL_FRONT);
+               glReadPixels(x, y, *dumpsx, *dumpsy, GL_RGBA, GL_UNSIGNED_BYTE, dumprect);
+               glFinish();
+               glReadBuffer(GL_BACK);
+       }
+
+       return dumprect;
+}
 
-void BL_MakeScreenShot(struct ARegion *ar, const char* filename)
+/* based on screendump.c::screenshot_exec */
+void BL_MakeScreenShot(ScrArea *curarea, const char* filename)
 {
-       char copyfilename[MAX_FILE_LENGTH];
-       strcpy(copyfilename,filename);
+       char path[MAX_FILE_LENGTH];
+       strcpy(path,filename);
 
-       // filename read - only
+       unsigned int *dumprect;
+       int dumpsx, dumpsy;
        
-         /* XXX will need to change at some point */
-       //XXX BIF_screendump(0);
-
-       // write+read filename
-       //XXX write_screendump((char*) copyfilename);
+       dumprect= screenshot(curarea, &dumpsx, &dumpsy);
+       if(dumprect) {
+               ImBuf *ibuf;
+               BLI_path_abs(path, G.main->name);
+               /* BKE_add_image_extension() checks for if extension was already set */
+               BKE_add_image_extension(path, R_PNG); /* scene->r.imtype */
+               ibuf= IMB_allocImBuf(dumpsx, dumpsy, 24, 0);
+               ibuf->rect= dumprect;
+               ibuf->ftype= PNG;
+
+               IMB_saveiff(ibuf, path, IB_rect);
+
+               ibuf->rect= NULL;
+               IMB_freeImBuf(ibuf);
+               MEM_freeN(dumprect);
+       }
 }