Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDalai Felinto <dfelinto@gmail.com>2010-10-09 17:46:34 +0400
committerDalai Felinto <dfelinto@gmail.com>2010-10-09 17:46:34 +0400
commit6b8ca3ccdf7643002237fc59ef42ee1046ce2a70 (patch)
treede02c7e4085cbc52b3c3d846a4dcca328455c6c5 /source/gameengine/BlenderRoutines
parentbd00aa972727197daa4b891e7aee8146a706e68c (diff)
patch [#24178] bge.render.makeScreeshot - with help from Campbell(ideasman42)
This patch brings back the old functionality from Blender 2.49. However we are forcing the format to be PNG only (as we had previously on blenderplayer). Note: If letterboxing is on, we are recording only the camera area of the canvas (cool hein?). Note2: I have a feeling that this is faster than what we had in 2.49 (which was really slow imo). Maybe it could be even faster if we disable PNG compression. Maybe an option for the future. * patch finalized and committed as part of the BlenderPRO 2010 - BGE development workshop :) *
Diffstat (limited to 'source/gameengine/BlenderRoutines')
-rw-r--r--source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp4
-rw-r--r--source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp8
-rw-r--r--source/gameengine/BlenderRoutines/KX_BlenderGL.cpp59
-rw-r--r--source/gameengine/BlenderRoutines/KX_BlenderGL.h2
4 files changed, 60 insertions, 13 deletions
diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
index 5a0522a9aa6..2bc24aab526 100644
--- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
+++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
@@ -425,7 +425,7 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
ketsjiengine->SetAnimFrameRate(FPS);
// the mainloop
- printf("\nBlender Game Engine Started\n\n");
+ printf("\nBlender Game Engine Started\n");
while (!exitrequested)
{
// first check if we want to exit
@@ -472,7 +472,7 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
}
}
- printf("\nBlender Game Engine Finished\n\n");
+ printf("Blender Game Engine Finished\n");
exitstring = ketsjiengine->GetExitString();
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp
index b04e951028d..f1e30ed4227 100644
--- a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp
+++ b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp
@@ -203,5 +203,11 @@ void KX_BlenderCanvas::SetMousePosition(int x,int y)
void KX_BlenderCanvas::MakeScreenShot(const char* filename)
{
-// BL_MakeScreenShot(m_ar, filename);
+ ScrArea area_dummy= {0};
+ area_dummy.totrct.xmin = m_frame_rect.GetLeft();
+ area_dummy.totrct.xmax = m_frame_rect.GetRight();
+ area_dummy.totrct.ymin = m_frame_rect.GetBottom();
+ area_dummy.totrct.ymax = m_frame_rect.GetTop();
+
+ BL_MakeScreenShot(&area_dummy, filename);
}
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp
index 55a687c0baa..662222bf990 100644
--- a/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp
+++ b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp
@@ -49,6 +49,8 @@ extern "C" {
#include "GL/glew.h"
+#include "MEM_guardedalloc.h"
+
#include "BL_Material.h" // MAXTEX
/* Data types encoding the game world: */
@@ -68,7 +70,11 @@ extern "C" {
#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"
@@ -206,18 +212,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);
+ }
-void BL_MakeScreenShot(struct ARegion *ar, const char* filename)
+ return dumprect;
+}
+
+/* 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.sce);
+ /* 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, 0);
+ ibuf->rect= dumprect;
+ ibuf->ftype= PNG;
+
+ IMB_saveiff(ibuf, path, IB_rect);
+
+ ibuf->rect= NULL;
+ IMB_freeImBuf(ibuf);
+ MEM_freeN(dumprect);
+ }
}
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderGL.h b/source/gameengine/BlenderRoutines/KX_BlenderGL.h
index 84d174cec68..9c5254dd661 100644
--- a/source/gameengine/BlenderRoutines/KX_BlenderGL.h
+++ b/source/gameengine/BlenderRoutines/KX_BlenderGL.h
@@ -41,7 +41,7 @@ void BL_SwapBuffers(struct wmWindow *win);
void BL_warp_pointer(struct wmWindow *win,int x,int y);
-void BL_MakeScreenShot(struct ARegion *ar, const char* filename);
+void BL_MakeScreenShot(struct ScrArea *curarea, const char* filename);
void BL_HideMouse(struct wmWindow *win);
void BL_NormalMouse(struct wmWindow *win);