Index: code/renderer/tr_local.h =================================================================== --- code/renderer/tr_local.h (revision 1323) +++ code/renderer/tr_local.h (working copy) @@ -30,6 +30,18 @@ #include "tr_public.h" #include "qgl.h" +// FOR CAMPROXY +#include +#include +#include +#include +#include +#include +#include //close +#include + + + #define GL_INDEX_TYPE GL_UNSIGNED_INT typedef unsigned int glIndex_t; @@ -963,6 +975,10 @@ float sawToothTable[FUNCTABLE_SIZE]; float inverseSawToothTable[FUNCTABLE_SIZE]; float fogTable[FOG_TABLE_SIZE]; + + image_t *livecameraImage; // from shared memory + int use_livecamera; + } trGlobals_t; extern backEndState_t backEnd; Index: code/renderer/tr_shader.c =================================================================== --- code/renderer/tr_shader.c (revision 1323) +++ code/renderer/tr_shader.c (working copy) @@ -625,6 +625,12 @@ stage->bundle[0].image[0] = tr.whiteImage; continue; } + else if ( !Q_stricmp( token, "$livecameraimage" ) ) + { + stage->bundle[0].image[0] = tr.livecameraImage; + tr.use_livecamera = 1; + continue; + } else if ( !Q_stricmp( token, "$lightmap" ) ) { stage->bundle[0].isLightmap = qtrue; Index: code/renderer/tr_image.c =================================================================== --- code/renderer/tr_image.c (revision 1323) +++ code/renderer/tr_image.c (working copy) @@ -1132,6 +1132,10 @@ tr.identityLightImage = R_CreateImage("*identityLight", (byte *)data, 8, 8, qfalse, qfalse, GL_REPEAT ); + byte livedata[320][240][4]; + Com_Memset( livedata, 128, sizeof( livedata ) ); + tr.livecameraImage = R_CreateImage("*livecamera", (byte *)livedata, 320, 240, qfalse, qfalse, GL_REPEAT ); + tr.use_livecamera = 0; // this turns to 1 once we detect a livecamera texture (tr_shader.c) for(x=0;x<32;x++) { // scratchimage is usually used for cinematic drawing Index: code/renderer/tr_main.c =================================================================== --- code/renderer/tr_main.c (revision 1323) +++ code/renderer/tr_main.c (working copy) @@ -25,6 +25,9 @@ #include // memcpy +#include +#include + trGlobals_t tr; static float s_flipMatrix[16] = { @@ -1308,6 +1311,54 @@ } + +#define STATE_FILE "/camproxy.shared" +#define SIZE 320*240*3 + + + +void R_UpdateLiveCameraImage( void ) { + + static int shm_fd = 0; + static unsigned char *shared_frame = 0; + + if (!tr.use_livecamera) return; + + if (!shm_fd) { + if((shm_fd = shm_open(STATE_FILE, (O_CREAT | O_RDWR), + (S_IREAD | S_IWRITE))) < 0 ) { + Com_Printf("Camproxy not running?\n"); + tr.use_livecamera = 0; + return; + } + + ftruncate(shm_fd, SIZE); + if((shared_frame = mmap(0, SIZE, (PROT_READ | PROT_WRITE), + MAP_SHARED, shm_fd, 0)) == MAP_FAILED) { + + Com_Printf("2) Camproxy not running?\n"); + tr.use_livecamera = 0; + return; + } + } + + + static int prevchecksum = 0; + int checksum = 0, i; + for (i=0; i<10; i++) + checksum += shared_frame[i*10]; + if (checksum == prevchecksum) return; + + prevchecksum = checksum; + + // The camera image has changed; let's rebuild the live camera texture. + GL_Bind(tr.livecameraImage); + gluBuild2DMipmaps( GL_TEXTURE_2D, 3, 320, 240, + GL_RGB, GL_UNSIGNED_BYTE, shared_frame); + +} + + /* ================ R_RenderView @@ -1333,6 +1384,8 @@ tr.viewCount++; + R_UpdateLiveCameraImage(); + // set viewParms.world R_RotateForViewer (); Index: Makefile =================================================================== --- Makefile (revision 1323) +++ Makefile (working copy) @@ -82,7 +82,7 @@ export CROSS_COMPILING ifndef COPYDIR -COPYDIR="/usr/local/games/quake3" +COPYDIR="/opt/quake3" endif ifndef MOUNT_DIR @@ -260,7 +260,7 @@ THREAD_LDFLAGS=-lpthread LDFLAGS=-ldl -lm -lrt - CLIENT_LDFLAGS=$(shell sdl-config --libs) -lGL + CLIENT_LDFLAGS=$(shell sdl-config --libs) -lGL -lGLU ifeq ($(USE_OPENAL),1) ifneq ($(USE_OPENAL_DLOPEN),1)