
Cube map screenshot
- Lackadaisical
- Shutout Match Winner
- Posts: 823
- Joined: Sun Dec 21, 2003 4:58 pm
- Location: Amsterdam, Netherlands
- Contact:
That is ridiculously awesome
edit: could you make one with the new textures from 0.2.8 ?
edit: could you make one with the new textures from 0.2.8 ?
Official Officiant of the Official Armagetron Clan Registration Office
Back (in the sig) by popular demand: Lack draws
Back (in the sig) by popular demand: Lack draws
- Tank Program
- Forum & Project Admin, PhD
- Posts: 6712
- Joined: Thu Dec 18, 2003 7:03 pm
- Jonathan
- A Brave Victim
- Posts: 3391
- Joined: Thu Feb 03, 2005 12:50 am
- Location: Not really lurking anymore
Source.
Requires that eCamera be opened up. It's also dirty in a few ways, but it works for me.

Code: Select all
#include "defs.h"
#include "tConfiguration.h"
#include "rGL.h"
#include "eGrid.h"
#include "eCamera.h"
#include <png.h>
#define CUBE_SIZE 512
static float matrices[6][16] = {
{ 0, 0, -1, 0, // +x
-1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 0, 1},
{ 0, 0, 1, 0, // -x
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 0, 1},
{ 1, 0, 0, 0, // +y
0, 0, -1, 0,
0, 1, 0, 0,
0, 0, 0, 1},
{-1, 0, 0, 0, // -y
0, 0, 1, 0,
0, 1, 0, 0,
0, 0, 0, 1},
{ 0, -1, 0, 0, // +z
-1, 0, 0, 0,
0, 0, -1, 0,
0, 0, 0, 1},
{ 0, 1, 0, 0, // -z
-1, 0, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1}
};
static const char *prefix = "/blah";
static const char names[6][3] = {"+x", "-x", "+y", "-y", "+z", "-z"};
static void process_image(unsigned char *ptr, unsigned size) {
unsigned char *iptr = ptr;
unsigned i, sq = size * size;
for(i=0; i<sq; i++) {
ptr[0] = iptr[1];
ptr[1] = iptr[2];
ptr[2] = iptr[3];
iptr += 4;
ptr += 3;
}
}
static void camera_pos(REAL &x, REAL &y, REAL &z, eCamera *cam) {
eCoord pos_diff = cam->Glance(cam->pos, cam->glanceDir_);
eCoord glancedir = cam->dir.Turn(cam->glanceDir_);
x = pos_diff.x + glancedir.x;
y = pos_diff.y + glancedir.y;
z = cam->z + cam->rise;
}
static void take_cubemap(std::istream &s) {
float zNear = 1;
eGrid *grid = eGrid::CurrentGrid();
const tList<eCamera>& cameras = grid->Cameras();
if(cameras.Len() < 1) {
con << "No cameras\n";
return;
}
eCamera *camera = cameras(0);
glViewport(0, 0, CUBE_SIZE, CUBE_SIZE);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1, 1, -1, 1, zNear, 1E+20);
unsigned i;
unsigned char *buf = (unsigned char *)malloc(CUBE_SIZE*CUBE_SIZE*4);
if(!buf) {
con << "Couldn't allocate enough\n";
return;
}
for(i=0; i<6; i++) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glMultMatrixf(matrices[i]);
REAL x, y, z;
camera_pos(x, y, z, camera);
glTranslatef(-x, -y, -z);
glMatrixMode(GL_MODELVIEW);
grid->Render(camera, 0, zNear);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glReadPixels(0, 0, CUBE_SIZE, CUBE_SIZE, GL_BGRA_EXT, GL_UNSIGNED_INT_8_8_8_8_REV, buf);
// On my hardware:
// AGP texture trick instead of glReadPixels: very, very fast
// ARGB (used here) : 200+ MiB/s
// Other 4-component: 130 MiB/s
// 3-component : 16 MiB/s (that's why I do my own reduction)
process_image(buf, CUBE_SIZE);
char path[64]; // Not large, but large enough for me
snprintf(path, sizeof path, "%s/%s.png", prefix, names[i]);
FILE *fp = fopen(path, "wb");
if(!fp) {
con << "No FILE\n";
continue;
}
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
if(!png_ptr) {
fclose(fp);
con << "No write struct\n";
continue;
}
png_infop info_ptr = png_create_info_struct(png_ptr);
if(!info_ptr) {
png_destroy_write_struct(&png_ptr, png_infopp_NULL);
fclose(fp);
con << "No info struct\n";
continue;
}
if(setjmp(png_jmpbuf(png_ptr))) {
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
con << "Jumped\n";
continue;
}
png_init_io(png_ptr, fp);
png_set_IHDR(png_ptr, info_ptr, CUBE_SIZE, CUBE_SIZE, 8, PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_set_gAMA_fixed(png_ptr, info_ptr, 55556);
png_write_info(png_ptr, info_ptr);
unsigned j;
for(j=CUBE_SIZE-1; j<CUBE_SIZE; j--)
png_write_row(png_ptr, buf + 3 * CUBE_SIZE * j);
png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
}
free(buf);
}
static tConfItemFunc cube_func("CUBE", &take_cubemap);