Commit 58ea31bb authored by Dave Griffiths's avatar Dave Griffiths
Browse files

fixed sync issue and added screenshot dumping

parent 4be9417d
......@@ -27,7 +27,7 @@ source = ['main.cpp',
]
if platform=='LINUX':
env.Append(LIBS = ['glut', 'GL', 'png', 'pthread', 'dl', 'lo'])
env.Append(LIBS = ['glut', 'GL', 'png', 'pthread', 'dl', 'lo', 'jpeg'])
env.Append(CCFLAGS=' -fpermissive -DFLX_LINUX')
env.Append(CPPPATH = '.')
source.append(['core/db.cpp',
......
......@@ -23,6 +23,11 @@
#include <png.h>
#include <pthread.h>
extern "C"
{
#include <jpeglib.h>
}
#include <lo/lo.h>
#include "engine/importgl.h"
......@@ -63,6 +68,55 @@ static const string ASSETS_LOCATION("../assets/");
static const string ASSETS_LOCATION("assets/");
#endif
GLubyte *GetScreenBuffer(int x, int y, unsigned int width, unsigned int height, int super)
{
// get the raw image
GLubyte *image = (GLubyte *) malloc(width * height * sizeof(GLubyte) * 3);
// OpenGL's default 4 byte pack alignment would leave extra bytes at the
// end of each image row so that each full row contained a number of bytes
// divisible by 4. Ie, an RGB row with 3 pixels and 8-bit componets would
// be laid out like "RGBRGBRGBxxx" where the last three "xxx" bytes exist
// just to pad the row out to 12 bytes (12 is divisible by 4). To make sure
// the rows are packed as tight as possible (no row padding), set the pack
// alignment to 1.
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, image);
if (super==1) return image;
// supersample the image
int newwidth=width/super;
int newheight=height/super;
GLubyte *image2 = (GLubyte *) malloc(newwidth * newheight * sizeof(GLubyte) * 3);
for (int yy=0; yy<newheight; yy++)
{
for (int xx=0; xx<newwidth; xx++)
{
int sx=xx*super;
int sy=yy*super;
int i=(yy*newwidth+xx)*3;
int a=(sy*width+sx)*3;
int b=(sy*width+(sx+1))*3;
int c=((sy+1)*width+(sx+1))*3;
int d=((sy+1)*width+sx)*3;
image2[i]=(image[a]+image[b]+image[c]+image[d])/4;
image2[i+1]=(image[a+1]+image[b+1]+image[c+1]+image[d+1])/4;
image2[i+2]=(image[a+2]+image[b+2]+image[c+2]+image[d+2])/4;
}
}
width=newwidth;
height=newheight;
free(image);
return image2;
}
unsigned char* LoadPNG(const string filename,long &width, long &height)
{
unsigned char *data = NULL;
......@@ -127,6 +181,51 @@ unsigned char* LoadPNG(const string filename,long &width, long &height)
return data;
}
int WriteJPG(GLubyte *image, const char *filename, const char *description, int x, int y, int width, int height, int quality, int super)
{
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
FILE * outfile;
JSAMPROW row_pointer[1];
int row_stride;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
if ((outfile = fopen(filename, "wb")) == NULL)
{
return 1;
}
jpeg_stdio_dest(&cinfo, outfile);
cinfo.image_width = width;
cinfo.image_height = height;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, quality, TRUE);
jpeg_start_compress(&cinfo, TRUE);
row_stride = width * 3;
while (cinfo.next_scanline < cinfo.image_height)
{
row_pointer[0] = & image[(cinfo.image_height-1-cinfo.next_scanline) * row_stride];
(void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
}
jpeg_finish_compress(&cinfo);
fclose(outfile);
jpeg_destroy_compress(&cinfo);
free(image);
return 0;
}
string LoadFile(string filename)
{
......@@ -219,6 +318,8 @@ void glMultMatrixx( GLfixed * mat )
//// common //////////////////////////
static int frame_num=0;
void DisplayCallback()
{
if (!pthread_mutex_trylock(render_mutex)) {
......@@ -231,6 +332,13 @@ void DisplayCallback()
glutSwapBuffers();
#endif
static char fn[256];
sprintf(fn,"shot-%0.4d.jpg",frame_num);
cerr<<fn<<endl;
WriteJPG(GetScreenBuffer(0, 0, w, h, 1),
fn,"",0,0,w,h,95,1);
frame_num++;
pthread_mutex_unlock(render_mutex);
} //else { printf("locked\n"); }
}
......
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; weavecoding raspberry pi installation
(rotate (vector 00 45 0))
(rotate (vector 0 -45 0))
(define weft (build-jellyfish 4096))
(define warp (build-jellyfish 4096))
(define weave-scale (vector 0.2 -0.2 0.2))
......@@ -18,10 +18,10 @@
(weft-t 0)
(draft-pos 0)
(draft-size 4)
(draft 1) (d-b 0) (d-c 0) (d-d 1)
(d-e 1) (d-f 1) (d-g 0) (d-h 0)
(d-i 0) (d-j 1) (d-k 1) (d-l 0)
(d-m 0) (d-n 0) (d-o 1) (d-p 1)
(draft 1) (d-b 0) (d-c 1) (d-d 0)
(d-e 0) (d-f 1) (d-g 0) (d-h 1)
(d-i 1) (d-j 0) (d-k 1) (d-l 0)
(d-m 0) (d-n 1) (d-o 0) (d-p 1)
(weft-z (vector 0 0 0))
(weft-count 0))
......@@ -156,10 +156,10 @@
(weft-t 0)
(draft-pos 0)
(draft-size 4)
(draft 1) (d-b 0) (d-c 0) (d-d 1)
(d-e 1) (d-f 1) (d-g 0) (d-h 0)
(d-i 0) (d-j 1) (d-k 1) (d-l 0)
(d-m 0) (d-n 0) (d-o 1) (d-p 1)
(draft 1) (d-b 0) (d-c 1) (d-d 0)
(d-e 0) (d-f 1) (d-g 0) (d-h 1)
(d-i 1) (d-j 0) (d-k 1) (d-l 0)
(d-m 0) (d-n 1) (d-o 0) (d-p 1)
(last-t 0))
(define build-quad
......@@ -183,13 +183,14 @@
(set! v (if (< weft-t 0.2)
(vector 0 0 2)
(if (> weft-t 0.8)
(vector 0 0 -2)
(vector 0 0 -1.3)
(vector 0 0 0))))
(set! warp-end 0)
(loop (< warp-end 20)
(if (> (read-draft) 0.5)
(write-sub! (- i 6) 0 v 0 0 v v
v 0 v v)
(+ 1 1)
;(write-sub! (- i 6) 0 v 0 0 v v
; v 0 v v)
(write-add! (- i 6) 0 v 0 0 v v
v 0 v v))
(set! i (+ i 24))
......@@ -214,7 +215,9 @@
(set! vertex (+ positions-start 12))
(animate-shed vertex)
(cond ((> (- last-t weft-t) 0.5)
(cond ((> (- last-t weft-t) 0.1)
(set! draft-pos (+ draft-pos 1))
(cond ((> draft-pos draft-size) (set! draft-pos 0)))
(build-warp)))
(set! last-t weft-t)
......@@ -246,12 +249,12 @@
"x" 11 (with-primitive
weft
(pdata-ref "x" 12))))
(with-primitive
warp
(pdata-set!
"x" 12 (with-primitive
weft
(pdata-ref "x" 13))))
;; (with-primitive
;; warp
;; (pdata-set!
;; "x" 12 (with-primitive
;; weft
;; (pdata-ref "x" 13))))
(with-primitive
weft
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment