4 #include "dpvsimpledecode.h"
6 mempool_t *clvideomempool;
8 int cl_videoplaying = false;
11 double cl_videostarttime;
13 double cl_videoframerate;
15 int cl_videoimagewidth;
16 int cl_videoimageheight;
17 int cl_videoimagedata_rmask;
18 int cl_videoimagedata_gmask;
19 int cl_videoimagedata_bmask;
20 int cl_videoimagedata_bytesperpixel;
21 void *cl_videoimagedata;
23 rtexture_t *cl_videotexture;
24 rtexturepool_t *cl_videotexturepool;
26 void CL_VideoFrame(void)
31 framenum = (realtime - cl_videostarttime) * cl_videoframerate;
32 //Con_Printf("frame %i\n", framenum);
36 while (cl_videoframenum < framenum)
40 if (dpvsimpledecode_video(cl_videostream, cl_videoimagedata, cl_videoimagedata_rmask, cl_videoimagedata_gmask, cl_videoimagedata_bmask, cl_videoimagedata_bytesperpixel, cl_videoimagewidth * cl_videoimagedata_bytesperpixel))
48 R_UpdateTexture(cl_videotexture, cl_videoimagedata);
49 //Draw_NewPic("engine_videoframe", cl_videoimagewidth, cl_videoimageheight, false, cl_videoimagedata);
53 void CL_DrawVideo(void)
61 float s1, t1, s2, t2, x1, y1, x2, y2;
66 R_FragmentLocation(cl_videotexture, NULL, NULL, &s1, &t1, &s2, &t2);
67 texcoord2f[0] = s1;texcoord2f[1] = t1;
68 texcoord2f[2] = s2;texcoord2f[3] = t1;
69 texcoord2f[4] = s2;texcoord2f[5] = t2;
70 texcoord2f[6] = s1;texcoord2f[7] = t2;
71 R_FillColors(color4f, 4, 1, 1, 1, 1);
72 vertex3f[ 0] = x1;vertex3f[ 1] = y1;vertex3f[ 2] = 0;
73 vertex3f[ 3] = x2;vertex3f[ 4] = y1;vertex3f[ 5] = 0;
74 vertex3f[ 6] = x2;vertex3f[ 7] = y2;vertex3f[ 8] = 0;
75 vertex3f[ 9] = x1;vertex3f[10] = y2;vertex3f[11] = 0;
76 mesh.texture = cl_videotexture;
77 mesh.num_triangles = 2;
78 mesh.num_vertices = 4;
79 mesh.data_element3i = polygonelements;
80 mesh.data_vertex3f = vertex3f;
81 mesh.data_texcoord2f = texcoord2f;
82 mesh.data_color4f = color4f;
84 //DrawQ_Pic(0, 0, "engine_videoframe", vid.conwidth, vid.conheight, 1, 1, 1, 1, 0);
88 void CL_VideoStart(char *filename)
91 cl_videostream = dpvsimpledecode_open(filename, &errorstring);
94 Con_Printf("unable to open \"%s\", error: %s\n", filename, errorstring);
98 cl_videoplaying = true;
99 cl_videostarttime = realtime;
100 cl_videoframenum = -1;
101 cl_videoframerate = dpvsimpledecode_getframerate(cl_videostream);
102 cl_videoimagewidth = dpvsimpledecode_getwidth(cl_videostream);
103 cl_videoimageheight = dpvsimpledecode_getheight(cl_videostream);
106 cl_videoimagedata_bytesperpixel = 4;
107 cl_videoimagedata_rmask = BigLong(0xFF000000);
108 cl_videoimagedata_gmask = BigLong(0x00FF0000);
109 cl_videoimagedata_bmask = BigLong(0x0000FF00);
110 cl_videoimagedata = Mem_Alloc(clvideomempool, cl_videoimagewidth * cl_videoimageheight * cl_videoimagedata_bytesperpixel);
111 //memset(cl_videoimagedata, 97, cl_videoimagewidth * cl_videoimageheight * cl_videoimagedata_bytesperpixel);
113 cl_videotexturepool = R_AllocTexturePool();
114 cl_videotexture = R_LoadTexture2D(cl_videotexturepool, "videotexture", cl_videoimagewidth, cl_videoimageheight, NULL, TEXTYPE_RGBA, TEXF_FRAGMENT, NULL);
117 void CL_VideoStop(void)
119 cl_videoplaying = false;
122 dpvsimpledecode_close(cl_videostream);
123 cl_videostream = NULL;
125 if (cl_videoimagedata)
126 Mem_Free(cl_videoimagedata);
127 cl_videoimagedata = NULL;
129 cl_videotexture = NULL;
130 R_FreeTexturePool(&cl_videotexturepool);
132 Draw_FreePic("engine_videoframe");
135 static void CL_PlayVideo_f(void)
141 Con_Print("usage: playvideo <videoname>\nplays video named video/<videoname>.dpv\n");
145 sprintf(name, "video/%s.dpv", Cmd_Argv(1));
149 static void CL_StopVideo_f(void)
154 void CL_Video_Init(void)
156 Cmd_AddCommand("playvideo", CL_PlayVideo_f);
157 Cmd_AddCommand("stopvideo", CL_StopVideo_f);
159 clvideomempool = Mem_AllocPool("CL_Video", 0, NULL);