2012-04-03 11:08:56 -05:00
|
|
|
/*
|
|
|
|
* SaveRenderer.cpp
|
|
|
|
*
|
|
|
|
* Created on: Apr 3, 2012
|
|
|
|
* Author: Simon
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SaveRenderer.h"
|
2012-07-06 10:06:26 -05:00
|
|
|
#include "graphics/Graphics.h"
|
2012-04-03 11:08:56 -05:00
|
|
|
#include "Simulation.h"
|
2012-07-06 10:06:26 -05:00
|
|
|
#include "graphics/Renderer.h"
|
2012-04-03 11:08:56 -05:00
|
|
|
|
|
|
|
|
|
|
|
SaveRenderer::SaveRenderer(){
|
2012-06-25 16:26:53 -05:00
|
|
|
g = new Graphics();
|
2012-04-03 11:08:56 -05:00
|
|
|
sim = new Simulation();
|
|
|
|
ren = new Renderer(g, sim);
|
2012-06-25 16:26:53 -05:00
|
|
|
|
|
|
|
#if defined(OGLR) || defined(OGLI)
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glGenTextures(1, &fboTex);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, fboTex);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, XRES, YRES, 0, GL_RGBA, GL_FLOAT, NULL);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
|
|
|
|
|
|
|
//FBO
|
|
|
|
glGenFramebuffers(1, &fbo);
|
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fboTex, 0);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); // Reset framebuffer binding
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
#endif
|
2012-04-03 11:08:56 -05:00
|
|
|
}
|
|
|
|
|
2012-06-05 14:08:35 -05:00
|
|
|
Thumbnail * SaveRenderer::Render(GameSave * save)
|
2012-04-03 11:08:56 -05:00
|
|
|
{
|
|
|
|
int width, height;
|
2012-06-21 09:49:32 -05:00
|
|
|
Thumbnail * tempThumb;
|
2012-06-08 16:04:14 -05:00
|
|
|
width = save->blockWidth;
|
|
|
|
height = save->blockHeight;
|
2012-07-27 20:23:21 -05:00
|
|
|
bool doCollapse = save->Collapsed();
|
2012-06-05 14:08:35 -05:00
|
|
|
|
2012-07-27 14:06:17 -05:00
|
|
|
g->Acquire();
|
2012-04-03 11:08:56 -05:00
|
|
|
g->Clear();
|
|
|
|
sim->clear_sim();
|
2012-06-20 14:05:25 -05:00
|
|
|
|
2012-06-20 13:23:22 -05:00
|
|
|
if(!sim->Load(save))
|
2012-04-03 11:08:56 -05:00
|
|
|
{
|
2012-06-25 16:26:53 -05:00
|
|
|
#if defined(OGLR) || defined(OGLI)
|
|
|
|
pixel * pData = NULL;
|
|
|
|
unsigned char * texData = NULL;
|
|
|
|
|
|
|
|
glTranslated(0, MENUSIZE, 0);
|
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
|
2012-06-25 16:34:04 -05:00
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2012-07-19 10:37:56 -05:00
|
|
|
|
2012-06-25 16:34:04 -05:00
|
|
|
ren->clearScreen(1.0f);
|
2012-07-19 10:37:56 -05:00
|
|
|
ren->ClearAccumulation();
|
|
|
|
ren->RenderBegin();
|
|
|
|
ren->RenderEnd();
|
|
|
|
|
2012-06-25 16:26:53 -05:00
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
|
|
|
glTranslated(0, -MENUSIZE, 0);
|
|
|
|
|
|
|
|
glEnable( GL_TEXTURE_2D );
|
|
|
|
glBindTexture(GL_TEXTURE_2D, fboTex);
|
|
|
|
|
|
|
|
pData = new pixel[XRES*YRES];
|
|
|
|
texData = new unsigned char[(XRES*YRES)*PIXELSIZE];
|
2012-07-27 14:06:17 -05:00
|
|
|
std::fill(texData, texData+(XRES*YRES)*PIXELSIZE, 0xDD);
|
2012-06-25 16:26:53 -05:00
|
|
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
for(int x = 0; x < width*CELL; x++)
|
|
|
|
{
|
|
|
|
for(int y = 0; y < height*CELL; y++)
|
|
|
|
{
|
|
|
|
unsigned char red = texData[((((YRES-1-y)*XRES)+x)*4)];
|
|
|
|
unsigned char green = texData[((((YRES-1-y)*XRES)+x)*4)+1];
|
|
|
|
unsigned char blue = texData[((((YRES-1-y)*XRES)+x)*4)+2];
|
|
|
|
|
|
|
|
pData[(y*(width*CELL))+x] = PIXRGBA(red, green, blue, 255);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tempThumb = new Thumbnail(0, 0, pData, ui::Point(width*CELL, height*CELL));
|
|
|
|
delete[] pData;
|
|
|
|
delete[] texData;
|
|
|
|
pData = NULL;
|
|
|
|
#else
|
|
|
|
pixel * pData = NULL;
|
|
|
|
pixel * dst;
|
|
|
|
pixel * src = g->vid;
|
2012-07-19 10:37:56 -05:00
|
|
|
|
|
|
|
ren->ClearAccumulation();
|
|
|
|
ren->RenderBegin();
|
|
|
|
ren->RenderEnd();
|
2012-06-05 14:08:35 -05:00
|
|
|
|
2012-06-20 13:23:22 -05:00
|
|
|
pData = (pixel *)malloc(PIXELSIZE * ((width*CELL)*(height*CELL)));
|
|
|
|
dst = pData;
|
|
|
|
for(int i = 0; i < height*CELL; i++)
|
|
|
|
{
|
|
|
|
memcpy(dst, src, (width*CELL)*PIXELSIZE);
|
|
|
|
dst+=(width*CELL);///PIXELSIZE;
|
|
|
|
src+=XRES+BARSIZE;
|
|
|
|
}
|
|
|
|
tempThumb = new Thumbnail(0, 0, pData, ui::Point(width*CELL, height*CELL));
|
2012-06-25 16:26:53 -05:00
|
|
|
if(pData)
|
|
|
|
free(pData);
|
|
|
|
#endif
|
2012-06-20 13:23:22 -05:00
|
|
|
}
|
2012-07-27 20:23:21 -05:00
|
|
|
if(doCollapse)
|
|
|
|
save->Collapse();
|
2012-07-27 14:06:17 -05:00
|
|
|
g->Release();
|
2012-04-03 11:08:56 -05:00
|
|
|
return tempThumb;
|
|
|
|
}
|
|
|
|
|
2012-06-05 14:08:35 -05:00
|
|
|
Thumbnail * SaveRenderer::Render(unsigned char * saveData, int dataSize)
|
|
|
|
{
|
2012-06-05 19:46:13 -05:00
|
|
|
GameSave * tempSave;
|
|
|
|
try {
|
|
|
|
tempSave = new GameSave((char*)saveData, dataSize);
|
|
|
|
} catch (exception & e) {
|
2012-06-05 19:54:27 -05:00
|
|
|
|
|
|
|
//Todo: make this look a little less shit
|
|
|
|
VideoBuffer buffer(64, 64);
|
2012-06-20 13:43:03 -05:00
|
|
|
buffer.BlendCharacter(32, 32, 'x', 255, 255, 255, 255);
|
2012-06-05 19:54:27 -05:00
|
|
|
|
|
|
|
Thumbnail * thumb = new Thumbnail(0, 0, buffer.Buffer, ui::Point(64, 64));
|
|
|
|
|
|
|
|
return thumb;
|
2012-06-05 19:46:13 -05:00
|
|
|
}
|
2012-06-05 14:08:35 -05:00
|
|
|
Thumbnail * thumb = Render(tempSave);
|
|
|
|
delete tempSave;
|
|
|
|
return thumb;
|
|
|
|
}
|
|
|
|
|
2012-04-03 11:08:56 -05:00
|
|
|
SaveRenderer::~SaveRenderer() {
|
|
|
|
// TODO Auto-generated destructor stub
|
|
|
|
}
|
|
|
|
|