vpost_plugins
changeset 0:7f7342bfbb25 tip
vpost plugin for that video: http://www.youtube.com/watch?v=txt6SGL483E
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 19 Oct 2011 06:23:32 +0300 |
parents | |
children | |
files | hullsdr/Makefile hullsdr/encode hullsdr/hullsdr_post.c hullsdr/script hullsdr/test |
diffstat | 5 files changed, 213 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/hullsdr/Makefile Wed Oct 19 06:23:32 2011 +0300 1.3 @@ -0,0 +1,14 @@ 1.4 +obj = hullsdr_post.o 1.5 +so = hullsdr_post.so 1.6 + 1.7 +CC = gcc 1.8 +CFLAGS = -pedantic -Wall -g -fPIC 1.9 +LDFLAGS = -limago -ldsys -ldrawtext -lGL -lGLU -lglut 1.10 + 1.11 +$(so): $(obj) 1.12 + $(CC) -o $@ -shared $(obj) $(LDFLAGS) 1.13 + 1.14 + 1.15 +.PHONY: clean 1.16 +clean: 1.17 + rm -f $(obj) $(so)
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/hullsdr/encode Wed Oct 19 06:23:32 2011 +0300 2.3 @@ -0,0 +1,6 @@ 2.4 +#!/bin/sh 2.5 + 2.6 +ffmpeg -i output/frame%4d.png -vpre libvpx-720p -b 3900k -pass 1 -an -f webm -y output.webm 2.7 + 2.8 +ffmpeg -i output/frame%4d.png -vpre libvpx-720p -b 3900k -pass 2 -an -f webm -y output.webm 2.9 +#ffmpeg -i output/frame%4d.png -vpre libvpx-720p -b 3900k -pass 2 -acodec libvorbis -ab 100k -f webm -y output.webm
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/hullsdr/hullsdr_post.c Wed Oct 19 06:23:32 2011 +0300 3.3 @@ -0,0 +1,177 @@ 3.4 +#include <math.h> 3.5 +#include <assert.h> 3.6 +#include <GL/glut.h> 3.7 +#include <GL/freeglut_ext.h> 3.8 +#include <imago2.h> 3.9 +#include <drawtext.h> 3.10 +#include <dsys.h> 3.11 + 3.12 +static void disp(void); 3.13 +static void draw_text(void); 3.14 +static void reshape(int x, int y); 3.15 + 3.16 +static struct img_pixmap *curfrm; 3.17 +static int nfrm; 3.18 +static int xsz = -1, ysz; 3.19 +static float tsec; 3.20 + 3.21 +static struct dsys_demo *script; 3.22 + 3.23 +static struct dtx_font *font; 3.24 + 3.25 +static struct { 3.26 + const char *name, *caption; 3.27 + struct dsys_event *ev; 3.28 +} events[] = { 3.29 + {"diffuse", "diffuse only - 1 light", 0}, 3.30 + {"diffuse2", "diffuse only - 2 lights", 0}, 3.31 + {"vmanip", "vertex manipulation", 0}, 3.32 + {"2tone", "two-tone paint", 0}, 3.33 + {"specular2", "full phong - 2 lights", 0}, 3.34 + {"celshade", "cel shading", 0}, 3.35 + {"sphmap", "reflection - spherical env. map", 0}, 3.36 + {"cubemap", "reflection - cubic env. map", 0}, 3.37 + {"refract", "relfection & refraction - cubic env. map w/fresnel", 0}, 3.38 + {"distort1", "image distortion", 0}, 3.39 + {"blur", "blur", 0}, 3.40 + {"distort2", "image distortion (again)", 0}, 3.41 + {0, 0, 0} 3.42 +}; 3.43 + 3.44 + 3.45 +int init(void) 3.46 +{ 3.47 + int i, argc = 1; 3.48 + char *argv[] = {"./vpost", 0}; 3.49 + 3.50 + if(!(font = dtx_open_font("linux-libertine.ttf", 32))) { 3.51 + fprintf(stderr, "failed to open font\n"); 3.52 + return -1; 3.53 + } 3.54 + 3.55 + if(!(script = dsys_open("script"))) { 3.56 + fprintf(stderr, "failed to open script\n"); 3.57 + return -1; 3.58 + } 3.59 + 3.60 + for(i=0; events[i].name; i++) { 3.61 + events[i].ev = dsys_event(script, events[i].name); 3.62 + } 3.63 + 3.64 + glutInit(&argc, argv); 3.65 + glutInitWindowSize(32, 32); 3.66 + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); 3.67 + 3.68 + glutCreateWindow("foo"); 3.69 + 3.70 + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 3.71 + 3.72 + glutDisplayFunc(disp); 3.73 + glutReshapeFunc(reshape); 3.74 + return 0; 3.75 +} 3.76 + 3.77 +void shutdown(void) 3.78 +{ 3.79 + printf("shutdown called\n"); 3.80 +} 3.81 + 3.82 +int process(struct img_pixmap *frame, int frm_num, float sec) 3.83 +{ 3.84 + curfrm = frame; 3.85 + nfrm = frm_num; 3.86 + tsec = sec; 3.87 + 3.88 + if(frame->width != xsz || frame->height != ysz) { 3.89 + glutReshapeWindow(frame->width, frame->height); 3.90 + } 3.91 + glutPostRedisplay(); 3.92 + 3.93 + while(curfrm) { 3.94 + glutMainLoopEvent(); 3.95 + } 3.96 + return 0; 3.97 +} 3.98 + 3.99 +static void disp(void) 3.100 +{ 3.101 + assert(curfrm); 3.102 + glClear(GL_COLOR_BUFFER_BIT); 3.103 + 3.104 + dsys_update(script, dsys_msec_to_dtime(nfrm)); 3.105 + 3.106 + glDrawPixels(xsz, ysz, GL_RGB, GL_UNSIGNED_BYTE, curfrm->pixels); 3.107 + 3.108 + draw_text(); 3.109 + 3.110 + glFlush(); 3.111 + glReadPixels(0, 0, xsz, ysz, GL_RGB, GL_UNSIGNED_BYTE, curfrm->pixels); 3.112 + 3.113 + glutSwapBuffers(); 3.114 + curfrm = 0; 3.115 + 3.116 + assert(glGetError() == GL_NO_ERROR); 3.117 +} 3.118 + 3.119 +static float fade(float x) 3.120 +{ 3.121 + x = 1.0 - (cos((x) * M_PI * 2.0) * 0.5 + 0.5); 3.122 + x *= 10.0f; 3.123 + 3.124 + return x > 1.0 ? 1.0 : x; 3.125 +} 3.126 + 3.127 +static void caption(const char *text, struct dsys_event *ev) 3.128 +{ 3.129 + float t = fade(dsys_event_value(ev)); 3.130 + 3.131 + if(t < (1.0f / 255.0f)) { 3.132 + return; 3.133 + } 3.134 + 3.135 + glMatrixMode(GL_MODELVIEW); 3.136 + glPushMatrix(); 3.137 + glTranslatef(0, 40 * t - 20, 0); 3.138 + 3.139 + glBegin(GL_QUADS); 3.140 + glColor4f(0.7, 0.2, 0.1, t); 3.141 + glVertex2f(0, -10); 3.142 + glVertex2f(xsz, -10); 3.143 + glVertex2f(xsz, 30); 3.144 + glVertex2f(0, 30); 3.145 + glEnd(); 3.146 + 3.147 + glTranslatef(20, 0, 0); 3.148 + 3.149 + glColor4f(1, 1, 1, t); 3.150 + dtx_string(text); 3.151 + 3.152 + glPopMatrix(); 3.153 +} 3.154 + 3.155 + 3.156 +static void draw_text(void) 3.157 +{ 3.158 + int i; 3.159 + dtx_use_font(font, 32); 3.160 + 3.161 + glPushAttrib(GL_ENABLE_BIT); 3.162 + glEnable(GL_BLEND); 3.163 + 3.164 + for(i=0; events[i].name; i++) { 3.165 + caption(events[i].caption, events[i].ev); 3.166 + } 3.167 + 3.168 + glPopAttrib(); 3.169 +} 3.170 + 3.171 +static void reshape(int x, int y) 3.172 +{ 3.173 + xsz = x; 3.174 + ysz = y; 3.175 + 3.176 + glViewport(0, 0, x, y); 3.177 + glMatrixMode(GL_PROJECTION); 3.178 + glLoadIdentity(); 3.179 + glOrtho(0, x, y, 0, -1, 1); 3.180 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/hullsdr/script Wed Oct 19 06:23:32 2011 +0300 4.3 @@ -0,0 +1,12 @@ 4.4 +0 341 diffuse 4.5 +342 667 diffuse2 4.6 +668 845 vmanip 4.7 +846 1412 2tone 4.8 +1413 1933 specular2 4.9 +1934 2451 celshade 4.10 +2452 2763 sphmap 4.11 +2764 3538 cubemap 4.12 +3539 4666 refract 4.13 +4667 5525 distort1 4.14 +5526 5610 blur 4.15 +5611 5954 distort2