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 :) *
This commit is contained in:
Dalai Felinto 2010-10-09 13:46:34 +00:00
parent bd00aa9727
commit 6b8ca3ccdf
4 changed files with 61 additions and 14 deletions

@ -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();

@ -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);
}

@ -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
void BL_MakeScreenShot(struct ARegion *ar, const char* filename)
/* get shot from frontbuffer sort of a copy from screendump.c */
static unsigned int *screenshot(ScrArea *curarea, int *dumpsx, int *dumpsy)
{
char copyfilename[MAX_FILE_LENGTH];
strcpy(copyfilename,filename);
// filename read - only
int x=0, y=0;
unsigned int *dumprect= NULL;
/* XXX will need to change at some point */
//XXX BIF_screendump(0);
x= curarea->totrct.xmin;
y= curarea->totrct.ymin;
*dumpsx= curarea->totrct.xmax-x;
*dumpsy= curarea->totrct.ymax-y;
// write+read filename
//XXX write_screendump((char*) copyfilename);
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;
}
/* based on screendump.c::screenshot_exec */
void BL_MakeScreenShot(ScrArea *curarea, const char* filename)
{
char path[MAX_FILE_LENGTH];
strcpy(path,filename);
unsigned int *dumprect;
int dumpsx, dumpsy;
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);
}
}

@ -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);