]> git.sesse.net Git - vlc/blob - modules/visualization/galaktos/main.c
Fixes compilation(2)
[vlc] / modules / visualization / galaktos / main.c
1 /*****************************************************************************
2  * main.c:
3  *****************************************************************************
4  * Copyright (C) 2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Cyril Deguet <asmax@videolan.org>
8  *          Adapted from projectM (http://xmms-projectm.sourceforge.net/)
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #include "plugin.h"
26 #include <GL/gl.h>
27 #include <GL/glu.h>
28 #include <unistd.h>
29 #include <math.h>
30 #include "common.h"
31 #include "preset_types.h"
32 #include "preset.h"
33 #include "engine_vars.h"
34 #include "per_pixel_eqn_types.h"
35 #include "per_pixel_eqn.h"
36 #include "interface_types.h"
37 #include "video_init.h"             //Video Init Routines, resizing/fullscreen, creating pbuffers
38 #include "PCM.h"                    //Sound data handler (buffering, FFT, etc.)
39 #include "beat_detect.h"            //beat detection routines
40 #include "custom_wave_types.h"
41 #include "custom_wave.h"
42 #include "custom_shape_types.h"
43 #include "custom_shape.h"
44 //#include <dmalloc.h>
45
46 // Forward declarations
47
48 void read_cfg();
49
50 void modulate_opacity_by_volume();
51 void maximize_colors();
52 void do_per_pixel_math();
53 void do_per_frame();
54
55 void render_interpolation();
56 void render_texture_to_screen();
57 void render_texture_to_studio();
58 void draw_motion_vectors();
59 void draw_borders();
60 void draw_shapes();
61 void draw_waveform();
62 void draw_custom_waves();
63
64 void reset_per_pixel_matrices();
65 void init_per_pixel_matrices();
66 void free_per_pixel_matrices();
67
68 int noSwitch=0;
69 int pcmframes=1;
70 int freqframes=0;
71 int totalframes=1;
72
73 int studio=0;
74
75 extern preset_t * active_preset;
76
77 GLuint RenderTargetTextureID;
78
79 double wave_o;
80
81 //double gx=32;  //size of interpolation
82 //double gy=24;
83
84 int texsize=512;   //size of texture to do actual graphics
85 int vw=512;           //runtime dimensions
86 int vh=512;
87 int fullscreen=0;
88
89 int maxsamples=2048; //size of PCM buffer
90 int numsamples; //size of new PCM info
91 double *pcmdataL;     //holder for most recent pcm data
92 double *pcmdataR;     //holder for most recent pcm data
93
94 int avgtime=500;  //# frames per preset
95
96 char *title = NULL;
97 int drawtitle;
98 int title_font;
99 int other_font;
100
101 int correction=1;
102
103 double vol;
104
105 //per pixel equation variables
106
107
108 double **gridx;  //grid containing interpolated mesh
109 double **gridy;
110 double **origtheta;  //grid containing interpolated mesh reference values
111 double **origrad;
112 double **origx;  //original mesh
113 double **origy;
114
115 char *buffer; //XXX
116
117 int galaktos_init( galaktos_thread_t *p_thread )
118 {
119     init_per_pixel_matrices();
120     pcmdataL=(double *)malloc(maxsamples*sizeof(double));
121     pcmdataR=(double *)malloc(maxsamples*sizeof(double));
122
123     /* Preset loading function */
124     initPresetLoader();
125
126     /* Load default preset directory */
127 //    loadPresetDir("/home/cyril/.vlc/galaktos");
128     loadPresetDir("/etc/projectM/presets");
129
130     initPCM(maxsamples);
131     initBeatDetect();
132
133     // mutex = SDL_CreateMutex();
134     return 0;
135 }
136
137
138 void galaktos_done( galaktos_thread_t *p_thread )
139 {
140     free(pcmdataL);
141     free(pcmdataR);
142
143     freeBeatDetect();
144     freePCM();
145     free_per_pixel_matrices();
146     closePresetDir();
147 //    destroyPresetLoader(); XXX segfaults :(
148 }
149
150
151 int galaktos_update( galaktos_thread_t *p_thread )
152 {
153     static int nohard=0;
154     double vdataL[512];  //holders for FFT data (spectrum)
155     double vdataR[512];
156
157     avgtime=fps*18;
158     totalframes++; //total amount of frames since startup
159
160     Time=(double)(mdate()/1000000);
161
162     frame++;  //number of frames for current preset
163     progress= frame/(double)avgtime;
164     if (progress>1.0) progress=1.0;
165     // printf("start:%d at:%d min:%d stop:%d on:%d %d\n",startframe, frame frame-startframe,avgtime,  noSwitch,progress);
166
167     if (frame>avgtime)
168     {
169         if (noSwitch==0) switchPreset(RANDOM_NEXT,0);
170     }
171
172     evalInitConditions();
173     evalPerFrameEquations();
174
175     evalCustomWaveInitConditions();
176     evalCustomShapeInitConditions();
177
178     //     printf("%f %d\n",Time,frame);
179
180     reset_per_pixel_matrices();
181
182
183     numsamples = getPCMnew(pcmdataR,1,0,fWaveSmoothing,0,0);
184     getPCMnew(pcmdataL,0,0,fWaveSmoothing,0,1);
185     getPCM(vdataL,512,0,1,0,0);
186     getPCM(vdataR,512,1,1,0,0);
187
188     bass=0;mid=0;treb=0;
189
190     getBeatVals(vdataL,vdataR,&vol);
191
192     nohard--;
193     if(vol>8.0 && nohard<0 && noSwitch==0)
194     {
195
196         switchPreset(RANDOM_NEXT, HARD_CUT);
197         nohard=100;
198     }
199
200     //BEGIN PASS 1
201     //
202     //This pass is used to render our texture
203     //the texture is drawn to a subsection of the framebuffer
204     //and then we perform our manipulations on it
205     //in pass 2 we will copy the texture into texture memory
206
207   //  galaktos_glx_activate_pbuffer( p_thread );
208
209     glPushAttrib( GL_ALL_ATTRIB_BITS ); /* Overkill, but safe */
210
211     //   if (RenderTarget) glViewport( 0, 0, RenderTarget->w, RenderTarget->h );
212     if (0) {}
213     else glViewport( 0, 0, texsize, texsize );
214
215
216     glMatrixMode( GL_MODELVIEW );
217     glPushMatrix();
218     glLoadIdentity();
219
220     glMatrixMode( GL_PROJECTION );
221     glPushMatrix();
222     glLoadIdentity();
223
224     glOrtho(0.0, texsize, 0.0,texsize,10,40);
225
226     do_per_pixel_math();
227
228     do_per_frame();               //apply per-frame effects
229     render_interpolation();       //apply per-pixel effects
230     draw_motion_vectors();        //draw motion vectors
231     draw_borders();               //draw borders
232
233     draw_waveform();
234     draw_shapes();
235     draw_custom_waves();
236
237     glMatrixMode( GL_MODELVIEW );
238     glPopMatrix();
239
240     glMatrixMode( GL_PROJECTION );
241     glPopMatrix();
242
243     glPopAttrib();
244
245     //if ( RenderTarget )        SDL_GL_UnlockRenderTarget(RenderTarget);
246         /* Copy our rendering to the fake render target texture */
247     glBindTexture( GL_TEXTURE_2D, RenderTargetTextureID );
248     glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize, texsize);
249 //    galaktos_glx_activate_window( p_thread );
250
251     //BEGIN PASS 2
252     //
253     //end of texture rendering
254     //now we copy the texture from the framebuffer to
255     //video texture memory and render fullscreen on a quad surface.
256     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
257     glMatrixMode(GL_PROJECTION);
258     glLoadIdentity();
259
260     glFrustum(-vw*.5, vw*.5, -vh*.5,vh*.5,10,40);
261
262     glLineWidth(texsize/512.0);
263     if(studio%2)render_texture_to_studio();
264     else render_texture_to_screen();
265
266     glFinish();
267     glFlush();
268     //  printf("Flush %d\n",(SDL_GetTicks()-timestart));
269
270     p_thread->p_opengl->pf_swap( p_thread->p_opengl );
271
272     /* Process events */
273     if( p_thread->p_opengl->pf_manage &&
274         p_thread->p_opengl->pf_manage( p_thread->p_opengl ) )
275     {
276         return 1;
277     }
278
279     return 0;
280 }
281
282
283 void free_per_pixel_matrices()
284 {
285     int x;
286
287     for(x = 0; x < gx; x++)
288     {
289         free(gridx[x]);
290         free(gridy[x]);
291         free(origtheta[x]);
292         free(origrad[x]);
293         free(origx[x]);
294         free(origy[x]);
295         free(x_mesh[x]);
296         free(y_mesh[x]);
297         free(rad_mesh[x]);
298         free(theta_mesh[x]);
299     }
300
301     free(origx);
302     free(origy);
303     free(gridx);
304     free(gridy);
305     free(x_mesh);
306     free(y_mesh);
307     free(rad_mesh);
308     free(theta_mesh);
309 }
310
311
312 void init_per_pixel_matrices()
313 {
314     int x,y;
315
316     gridx=(double **)malloc(gx * sizeof(double *));
317     gridy=(double **)malloc(gx * sizeof(double *));
318
319     origx=(double **)malloc(gx * sizeof(double *));
320     origy=(double **)malloc(gx * sizeof(double *));
321     origrad=(double **)malloc(gx * sizeof(double *));
322     origtheta=(double **)malloc(gx * sizeof(double *));
323
324     x_mesh=(double **)malloc(gx * sizeof(double *));
325     y_mesh=(double **)malloc(gx * sizeof(double *));
326     rad_mesh=(double **)malloc(gx * sizeof(double *));
327     theta_mesh=(double **)malloc(gx * sizeof(double *));
328
329     sx_mesh=(double **)malloc(gx * sizeof(double *));
330     sy_mesh=(double **)malloc(gx * sizeof(double *));
331     dx_mesh=(double **)malloc(gx * sizeof(double *));
332     dy_mesh=(double **)malloc(gx * sizeof(double *));
333     cx_mesh=(double **)malloc(gx * sizeof(double *));
334     cy_mesh=(double **)malloc(gx * sizeof(double *));
335     zoom_mesh=(double **)malloc(gx * sizeof(double *));
336     zoomexp_mesh=(double **)malloc(gx * sizeof(double *));
337     rot_mesh=(double **)malloc(gx * sizeof(double *));
338
339     for(x = 0; x < gx; x++)
340     {
341         gridx[x] = (double *)malloc(gy * sizeof(double));
342         gridy[x] = (double *)malloc(gy * sizeof(double));
343
344         origtheta[x] = (double *)malloc(gy * sizeof(double));
345         origrad[x] = (double *)malloc(gy * sizeof(double));
346         origx[x] = (double *)malloc(gy * sizeof(double));
347         origy[x] = (double *)malloc(gy * sizeof(double));
348
349         x_mesh[x] = (double *)malloc(gy * sizeof(double));
350         y_mesh[x] = (double *)malloc(gy * sizeof(double));
351
352         rad_mesh[x] = (double *)malloc(gy * sizeof(double));
353         theta_mesh[x] = (double *)malloc(gy * sizeof(double));
354
355         sx_mesh[x] = (double *)malloc(gy * sizeof(double));
356         sy_mesh[x] = (double *)malloc(gy * sizeof(double));
357         dx_mesh[x] = (double *)malloc(gy * sizeof(double));
358         dy_mesh[x] = (double *)malloc(gy * sizeof(double));
359         cx_mesh[x] = (double *)malloc(gy * sizeof(double));
360         cy_mesh[x] = (double *)malloc(gy * sizeof(double));
361
362         zoom_mesh[x] = (double *)malloc(gy * sizeof(double));
363         zoomexp_mesh[x] = (double *)malloc(gy * sizeof(double));
364
365         rot_mesh[x] = (double *)malloc(gy * sizeof(double));
366     }
367
368     //initialize reference grid values
369     for (x=0;x<gx;x++)
370     {
371         for(y=0;y<gy;y++)
372         {
373             origx[x][y]=x/(double)(gx-1);
374             origy[x][y]=-((y/(double)(gy-1))-1);
375             origrad[x][y]=hypot((origx[x][y]-.5)*2,(origy[x][y]-.5)*2) * .7071067;
376             origtheta[x][y]=atan2(((origy[x][y]-.5)*2),((origx[x][y]-.5)*2));
377             gridx[x][y]=origx[x][y]*texsize;
378             gridy[x][y]=origy[x][y]*texsize;
379         }
380     }
381 }
382
383
384
385 //calculate matrices for per_pixel
386 void do_per_pixel_math()
387 {
388     int x,y;
389
390     double rotx=0,roty=0;
391     evalPerPixelEqns();
392
393     if(!isPerPixelEqn(CX_OP))
394     {
395         for (x=0;x<gx;x++)
396         {
397             for(y=0;y<gy;y++){
398                 cx_mesh[x][y]=cx;
399             }
400         }
401     }
402
403     if(!isPerPixelEqn(CY_OP))
404     {
405         for (x=0;x<gx;x++)
406         {
407             for(y=0;y<gy;y++)
408             {
409                 cy_mesh[x][y]=cy;
410             }
411         }
412     }
413
414     if(isPerPixelEqn(ROT_OP))
415     {
416         for (x=0;x<gx;x++)
417         {
418             for(y=0;y<gy;y++)
419             {
420                 x_mesh[x][y]=x_mesh[x][y]-cx_mesh[x][y];
421                 y_mesh[x][y]=y_mesh[x][y]-cy_mesh[x][y];
422                 rotx=(x_mesh[x][y])*cos(rot_mesh[x][y])-(y_mesh[x][y])*sin(rot_mesh[x][y]);
423                 roty=(x_mesh[x][y])*sin(rot_mesh[x][y])+(y_mesh[x][y])*cos(rot_mesh[x][y]);
424                 x_mesh[x][y]=rotx+cx_mesh[x][y];
425                 y_mesh[x][y]=roty+cy_mesh[x][y];
426             }
427         }
428     }
429
430
431
432     if(!isPerPixelEqn(ZOOM_OP))
433     {
434         for (x=0;x<gx;x++)
435         {
436             for(y=0;y<gy;y++)
437             {
438                 zoom_mesh[x][y]=zoom;
439             }
440         }
441     }
442
443     if(!isPerPixelEqn(ZOOMEXP_OP))
444     {
445         for (x=0;x<gx;x++)
446         {
447             for(y=0;y<gy;y++)
448             {
449                 zoomexp_mesh[x][y]=zoomexp;
450             }
451         }
452     }
453
454
455     //DO ZOOM PER PIXEL
456     for (x=0;x<gx;x++)
457     {
458         for(y=0;y<gy;y++)
459         {
460             x_mesh[x][y]=(x_mesh[x][y]-.5)*2;
461             y_mesh[x][y]=(y_mesh[x][y]-.5)*2;
462             x_mesh[x][y]=x_mesh[x][y]/(((zoom_mesh[x][y]-1)*(pow(rad_mesh[x][y],zoomexp_mesh[x][y])/rad_mesh[x][y]))+1);
463             y_mesh[x][y]=y_mesh[x][y]/(((zoom_mesh[x][y]-1)*(pow(rad_mesh[x][y],zoomexp_mesh[x][y])/rad_mesh[x][y]))+1);
464             x_mesh[x][y]=(x_mesh[x][y]*.5)+.5;
465             y_mesh[x][y]=(y_mesh[x][y]*.5)+.5;
466         }
467     }
468
469     if(isPerPixelEqn(SX_OP))
470     {
471         for (x=0;x<gx;x++)
472         {
473             for(y=0;y<gy;y++)
474             {
475                 x_mesh[x][y]=((x_mesh[x][y]-cx_mesh[x][y])/sx_mesh[x][y])+cx_mesh[x][y];
476             }
477         }
478     }
479
480     if(isPerPixelEqn(SY_OP))
481     {
482         for (x=0;x<gx;x++)
483         {
484             for(y=0;y<gy;y++)
485             {
486                 y_mesh[x][y]=((y_mesh[x][y]-cy_mesh[x][y])/sy_mesh[x][y])+cy_mesh[x][y];
487             }
488         }
489     }
490
491     if(isPerPixelEqn(DX_OP))
492     {
493         for (x=0;x<gx;x++)
494         {
495             for(y=0;y<gy;y++)
496             {
497
498                 x_mesh[x][y]=x_mesh[x][y]-dx_mesh[x][y];
499
500             }
501         }
502     }
503
504     if(isPerPixelEqn(DY_OP))
505     {
506         for (x=0;x<gx;x++)
507         {
508             for(y=0;y<gy;y++)
509             {
510                 y_mesh[x][y]=y_mesh[x][y]-dy_mesh[x][y];
511
512             }
513         }
514     }
515
516
517 }
518
519 void reset_per_pixel_matrices()
520 {
521     int x,y;
522
523     for (x=0;x<gx;x++)
524     {
525         for(y=0;y<gy;y++)
526         {
527             x_mesh[x][y]=origx[x][y];
528             y_mesh[x][y]=origy[x][y];
529             rad_mesh[x][y]=origrad[x][y];
530             theta_mesh[x][y]=origtheta[x][y];
531         }
532     }
533 }
534
535
536
537 void draw_custom_waves()
538 {
539     int x;
540
541     custom_wave_t *wavecode;
542     glPointSize(texsize/512);
543     //printf("%d\n",wavecode);
544     //  more=isMoreCustomWave();
545     // printf("not inner loop\n");
546     while ((wavecode = nextCustomWave()) != NULL)
547     {
548         //printf("begin inner loop\n");
549         if(wavecode->enabled==1)
550         {
551             // nextCustomWave();
552
553             //glPushMatrix();
554
555             //if(wavecode->bUseDots==1) glEnable(GL_LINE_STIPPLE);
556             if (wavecode->bAdditive==0)  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
557             else    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
558             if (wavecode->bDrawThick==1)  glLineWidth(2*texsize/512);
559
560             //  xx= ((pcmdataL[x]-pcmdataL[x-1])*80*fWaveScale)*2;
561             //yy=pcmdataL[x]*80*fWaveScale,-1;
562             //glVertex3f( (wave_x*texsize)+(xx+yy)*cos(45), (wave_y*texsize)+(-yy+xx)*cos(45),-1);
563             // printf("samples: %d\n", wavecode->samples);
564
565             getPCM(wavecode->value1,wavecode->samples,0,wavecode->bSpectrum,wavecode->smoothing,0);
566             getPCM(wavecode->value2,wavecode->samples,1,wavecode->bSpectrum,wavecode->smoothing,0);
567             // printf("%f\n",pcmL[0]);
568             for(x=0;x<wavecode->samples;x++)
569             {wavecode->value1[x]=wavecode->value1[x]*wavecode->scaling;}
570
571             for(x=0;x<wavecode->samples;x++)
572             {wavecode->value2[x]=wavecode->value2[x]*wavecode->scaling;}
573
574             for(x=0;x<wavecode->samples;x++)
575             {wavecode->sample_mesh[x]=((double)x)/((double)(wavecode->samples-1));}
576
577             // printf("mid inner loop\n");
578             evalPerPointEqns();
579             /*
580                if(!isPerPointEquation("x"))
581                {for(x=0;x<wavecode->samples;x++)
582                {cw_x[x]=0;} }
583
584                if(!isPerPointEquation(Y_POINT_OP))
585                {for(x=0;x<wavecode->samples;x++)
586                {cw_y[x]=0;}}
587
588                if(!isPerPointEquation(R_POINT_OP))
589                {for(x=0;x<wavecode->samples;x++)
590                {cw_r[x]=wavecode->r;}}
591                if(!isPerPointEquation(G_POINT_OP))
592                {for(x=0;x<wavecode->samples;x++)
593                {cw_g[x]=wavecode->g;}}
594                if(!isPerPointEquation(B_POINT_OP))
595                {for(x=0;x<wavecode->samples;x++)
596                {cw_b[x]=wavecode->b;}}
597                if(!isPerPointEquation(A_POINT_OP))
598                {for(x=0;x<wavecode->samples;x++)
599                {cw_a[x]=wavecode->a;}}
600              */
601             //put drawing code here
602             if (wavecode->bUseDots==1)   glBegin(GL_POINTS);
603             else   glBegin(GL_LINE_STRIP);
604
605             for(x=0;x<wavecode->samples;x++)
606             {
607                 //          printf("x:%f y:%f a:%f g:%f %f\n", wavecode->x_mesh[x], wavecode->y_mesh[x], wavecode->a_mesh[x], wavecode->g_mesh[x], wavecode->sample_mesh[x]);
608                 glColor4f(wavecode->r_mesh[x],wavecode->g_mesh[x],wavecode->b_mesh[x],wavecode->a_mesh[x]);
609                 glVertex3f(wavecode->x_mesh[x]*texsize,-(wavecode->y_mesh[x]-1)*texsize,-1);
610             }
611             glEnd();
612             glPointSize(texsize/512);
613             glLineWidth(texsize/512);
614             glDisable(GL_LINE_STIPPLE);
615             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
616             //  glPopMatrix();
617
618         }
619
620     }
621 }
622
623
624
625 void draw_shapes()
626 {
627     int i;
628
629     double theta;
630     double rad2;
631
632     double pi = 3.14159265;
633     double start,inc,xval,yval;
634     custom_shape_t *shapecode;
635
636     while ((shapecode = nextCustomShape()) != NULL)
637     {
638         if(shapecode->enabled==1)
639         {
640             // printf("drawing shape %f\n",shapecode->ang);
641             shapecode->y=-((shapecode->y)-1);
642             rad2=.5;
643             shapecode->rad=shapecode->rad*(texsize*.707*.707*.707*1.04);
644             //Additive Drawing or Overwrite
645             if (shapecode->additive==0)  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
646             else    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
647
648             glMatrixMode(GL_MODELVIEW);
649             glPushMatrix();
650             if(correction)
651             {
652                 glTranslatef(texsize*.5,texsize*.5, 0);
653                 glScalef(1.0,vw/(double)vh,1.0);
654                 glTranslatef((-texsize*.5) ,(-texsize*.5),0);
655             }
656
657             start=.78539+shapecode->ang;
658             inc=(pi*2)/(double)shapecode->sides;
659             xval=shapecode->x*texsize;
660             yval=shapecode->y*texsize;
661
662             if (shapecode->textured)
663             {
664                 glMatrixMode(GL_TEXTURE);
665                 glPushMatrix();
666                 glLoadIdentity();
667
668                 glTranslatef(.5,.5, 0);
669                 if (correction) glScalef(1,vw/(double)vh,1);
670
671                 glRotatef((shapecode->tex_ang*360/6.280), 0, 0, 1);
672
673                 glScalef(1/(shapecode->tex_zoom),1/(shapecode->tex_zoom),1);
674
675                 // glScalef(1,vh/(double)vw,1);
676                 glTranslatef((-.5) ,(-.5),0);
677                 // glScalef(1,vw/(double)vh,1);
678                 glEnable(GL_TEXTURE_2D);
679
680
681                 glBegin(GL_TRIANGLE_FAN);
682
683                 glColor4f(shapecode->r,shapecode->g,shapecode->b,shapecode->a);
684                 theta=start;
685                 glTexCoord2f(.5,.5);
686                 glVertex3f(xval,yval,-1);
687                 glColor4f(shapecode->r2,shapecode->g2,shapecode->b2,shapecode->a2);
688
689                 for ( i=0;i<shapecode->sides+1;i++)
690                 {
691
692                     theta+=inc;
693                     //  glColor4f(shapecode->r2,shapecode->g2,shapecode->b2,shapecode->a2);
694                     glTexCoord2f(rad2*cos(theta)+.5 ,rad2*sin(theta)+.5 );
695                     glVertex3f(shapecode->rad*cos(theta)+xval,shapecode->rad*sin(theta)+yval,-1);
696                 }
697                 glEnd();
698
699
700
701
702                 glDisable(GL_TEXTURE_2D);
703                 glPopMatrix();
704                 glMatrixMode(GL_MODELVIEW);
705             }
706             else
707             {//Untextured (use color values)
708                 //printf("untextured %f %f %f @:%f,%f %f %f\n",shapecode->a2,shapecode->a,shapecode->border_a, shapecode->x,shapecode->y,shapecode->rad,shapecode->ang);
709                 //draw first n-1 triangular pieces
710                 glBegin(GL_TRIANGLE_FAN);
711
712                 glColor4f(shapecode->r,shapecode->g,shapecode->b,shapecode->a);
713                 theta=start;
714                 // glTexCoord2f(.5,.5);
715                 glVertex3f(xval,yval,-1);
716                 glColor4f(shapecode->r2,shapecode->g2,shapecode->b2,shapecode->a2);
717
718                 for ( i=0;i<shapecode->sides+1;i++)
719                 {
720
721                     theta+=inc;
722                     //  glColor4f(shapecode->r2,shapecode->g2,shapecode->b2,shapecode->a2);
723                     //  glTexCoord2f(rad2*cos(theta)+.5 ,rad2*sin(theta)+.5 );
724                     glVertex3f(shapecode->rad*cos(theta)+xval,shapecode->rad*sin(theta)+yval,-1);
725                 }
726                 glEnd();
727
728
729             }
730             if (bWaveThick==1)  glLineWidth(2*texsize/512);
731             glBegin(GL_LINE_LOOP);
732             glColor4f(shapecode->border_r,shapecode->border_g,shapecode->border_b,shapecode->border_a);
733             for ( i=0;i<shapecode->sides;i++)
734             {
735                 theta+=inc;
736                 glVertex3f(shapecode->rad*cos(theta)+xval,shapecode->rad*sin(theta)+yval,-1);
737             }
738             glEnd();
739             if (bWaveThick==1)  glLineWidth(texsize/512);
740
741             glPopMatrix();
742         }
743     }
744
745 }
746
747
748 void draw_waveform()
749 {
750
751     int x;
752
753     double r,theta;
754
755     double offset,scale,dy2_adj;
756
757     double co;
758
759     double wave_x_temp=0;
760     double wave_y_temp=0;
761
762     modulate_opacity_by_volume();
763     maximize_colors();
764
765     if(bWaveDots==1) glEnable(GL_LINE_STIPPLE);
766
767     offset=(wave_x-.5)*texsize;
768     scale=texsize/505.0;
769
770     //Thick wave drawing
771     if (bWaveThick==1)  glLineWidth(2*texsize/512);
772
773     //Additive wave drawing (vice overwrite)
774     if (bAdditiveWaves==0)  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
775     else    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
776
777     switch(nWaveMode)
778     {
779         case 8://monitor
780
781             glPushMatrix();
782
783             glTranslatef(texsize*.5,texsize*.5, 0);
784             glRotated(-wave_mystery*90,0,0,1);
785
786             glTranslatef(-texsize*.5,-texsize*.825, 0);
787
788             /*
789                for (x=0;x<16;x++)
790                {
791                glBegin(GL_LINE_STRIP);
792                glColor4f(1.0-(x/15.0),.5,x/15.0,1.0);
793                glVertex3f((totalframes%256)*2*scale, -beat_val[x]*fWaveScale+texsize*wave_y,-1);
794                glColor4f(.5,.5,.5,1.0);
795                glVertex3f((totalframes%256)*2*scale, texsize*wave_y,-1);
796                glColor4f(1.0,1.0,0,1.0);
797             //glVertex3f((totalframes%256)*scale*2, beat_val_att[x]*fWaveScale+texsize*wave_y,-1);
798             glEnd();
799
800             glTranslatef(0,texsize*(1/36.0), 0);
801             }
802              */
803
804             glTranslatef(0,texsize*(1/18.0), 0);
805
806
807             glBegin(GL_LINE_STRIP);
808             glColor4f(1.0,1.0,0.5,1.0);
809             glVertex3f((totalframes%256)*2*scale, treb_att*5*fWaveScale+texsize*wave_y,-1);
810             glColor4f(.2,.2,.2,1.0);
811             glVertex3f((totalframes%256)*2*scale, texsize*wave_y,-1);
812             glColor4f(1.0,1.0,0,1.0);
813             glVertex3f((totalframes%256)*scale*2, treb*-5*fWaveScale+texsize*wave_y,-1);
814             glEnd();
815
816             glTranslatef(0,texsize*.075, 0);
817             glBegin(GL_LINE_STRIP);
818             glColor4f(0,1.0,0.0,1.0);
819             glVertex3f((totalframes%256)*2*scale, mid_att*5*fWaveScale+texsize*wave_y,-1);
820             glColor4f(.2,.2,.2,1.0);
821             glVertex3f((totalframes%256)*2*scale, texsize*wave_y,-1);
822             glColor4f(.5,1.0,.5,1.0);
823             glVertex3f((totalframes%256)*scale*2, mid*-5*fWaveScale+texsize*wave_y,-1);
824             glEnd();
825
826
827             glTranslatef(0,texsize*.075, 0);
828             glBegin(GL_LINE_STRIP);
829             glColor4f(1.0,0,0,1.0);
830             glVertex3f((totalframes%256)*2*scale, bass_att*5*fWaveScale+texsize*wave_y,-1);
831             glColor4f(.2,.2,.2,1.0);
832             glVertex3f((totalframes%256)*2*scale, texsize*wave_y,-1);
833             glColor4f(1.0,.5,.5,1.0);
834             glVertex3f((totalframes%256)*scale*2, bass*-5*fWaveScale+texsize*wave_y,-1);
835             glEnd();
836
837
838             glPopMatrix();
839             break;
840
841         case 0://circular waveforms
842             //  double co;
843             glPushMatrix();
844
845             glTranslatef(texsize*.5,texsize*.5, 0);
846             glScalef(1.0,vw/(double)vh,1.0);
847             glTranslatef((-texsize*.5) ,(-texsize*.5),0);
848
849             wave_y=-1*(wave_y-1.0);
850
851             glBegin(GL_LINE_STRIP);
852
853             for ( x=0;x<numsamples;x++)
854             {
855                 co= -(abs(x-((numsamples*.5)-1))/numsamples)+1;
856                 // printf("%d %f\n",x,co);
857                 theta=x*(6.28/numsamples);
858                 r= ((1+2*wave_mystery)*(texsize/5.0)+
859                     ( co*pcmdataL[x]+ (1-co)*pcmdataL[-(x-(numsamples-1))])
860                     *25*fWaveScale);
861
862                 glVertex3f(r*cos(theta)+(wave_x*texsize),r*sin(theta)+(wave_y*texsize),-1);
863             }
864
865             r= ( (1+2*wave_mystery)*(texsize/5.0)+
866                  (0.5*pcmdataL[0]+ 0.5*pcmdataL[numsamples-1])
867                  *20*fWaveScale);
868
869             glVertex3f(r*cos(0)+(wave_x*texsize),r*sin(0)+(wave_y*texsize),-1);
870
871             glEnd();
872             /*
873                glBegin(GL_LINE_LOOP);
874
875                for ( x=0;x<(512/pcmbreak);x++)
876                {
877                theta=(blockstart+x)*((6.28*pcmbreak)/512.0);
878                r= ((1+2*wave_mystery)*(texsize/5.0)+fdata_buffer[fbuffer][0][blockstart+x]*.0025*fWaveScale);
879
880                glVertex3f(r*cos(theta)+(wave_x*texsize),r*sin(theta)+(wave_y*texsize),-1);
881                }
882                glEnd();
883              */
884             glPopMatrix();
885
886             break;
887
888         case 1://circularly moving waveform
889             //  double co;
890             glPushMatrix();
891
892             glTranslatef(texsize*.5,texsize*.5, 0);
893             glScalef(1.0,vw/(double)vh,1.0);
894             glTranslatef((-texsize*.5) ,(-texsize*.5),0);
895
896             wave_y=-1*(wave_y-1.0);
897
898             glBegin(GL_LINE_STRIP);
899             //theta=(frame%512)*(6.28/512.0);
900
901             for ( x=1;x<512;x++)
902             {
903                 co= -(abs(x-255)/512.0)+1;
904                 // printf("%d %f\n",x,co);
905                 theta=((frame%256)*(2*6.28/512.0))+pcmdataL[x]*.2*fWaveScale;
906                 r= ((1+2*wave_mystery)*(texsize/5.0)+
907                     (pcmdataL[x]-pcmdataL[x-1])*80*fWaveScale);
908
909                 glVertex3f(r*cos(theta)+(wave_x*texsize),r*sin(theta)+(wave_y*texsize),-1);
910             }
911
912             glEnd();
913
914             glPopMatrix();
915
916             break;
917
918         case 2://EXPERIMENTAL
919             wave_y=-1*(wave_y-1.0);
920             glPushMatrix();
921             glBegin(GL_LINE_STRIP);
922             double xx,yy;
923             // double xr= (wave_x*texsize), yr=(wave_y*texsize);
924             xx=0;
925             for ( x=1;x<512;x++)
926             {
927                 //xx = ((pcmdataL[x]-pcmdataL[x-1])*80*fWaveScale)*2;
928                 xx += (pcmdataL[x]*fWaveScale);
929                 yy= pcmdataL[x]*80*fWaveScale;
930                 //  glVertex3f( (wave_x*texsize)+(xx+yy)*2, (wave_y*texsize)+(xx-yy)*2,-1);
931                 glVertex3f( (wave_x*texsize)+(xx)*2, (wave_y*texsize)+(yy)*2,-1);
932
933
934                 //   xr+=fdata_buffer[fbuffer][0][x] *.0005* fWaveScale;
935                 //yr=(fdata_buffer[fbuffer][0][x]-fdata_buffer[fbuffer][0][x-1])*.05*fWaveScale+(wave_y*texsize);
936                 //glVertex3f(xr,yr,-1);
937
938             }
939             glEnd();
940             glPopMatrix();
941             break;
942
943         case 3://EXPERIMENTAL
944             glPushMatrix();
945             wave_y=-1*(wave_y-1.0);
946             glBegin(GL_LINE_STRIP);
947
948
949             for ( x=1;x<512;x++)
950             {
951                 xx= ((pcmdataL[x]-pcmdataL[x-1])*80*fWaveScale)*2;
952                 yy=pcmdataL[x]*80*fWaveScale,-1;
953                 glVertex3f( (wave_x*texsize)+(xx+yy)*cos(45), (wave_y*texsize)+(-yy+xx)*cos(45),-1);
954             }
955             glEnd();
956             glPopMatrix();
957             break;
958
959         case 4://single x-axis derivative waveform
960             glPushMatrix();
961             wave_y=-1*(wave_y-1.0);
962             glTranslatef(texsize*.5,texsize*.5, 0);
963             glRotated(-wave_mystery*90,0,0,1);
964             glTranslatef(-texsize*.5,-texsize*.5, 0);
965             wave_x=(wave_x*.75)+.125;      wave_x=-(wave_x-1);
966             glBegin(GL_LINE_STRIP);
967
968             double dy_adj;
969             for ( x=1;x<512;x++)
970             {
971                 dy_adj=  pcmdataL[x]*20*fWaveScale-pcmdataL[x-1]*20*fWaveScale;
972                 glVertex3f((x*scale)+dy_adj, pcmdataL[x]*20*fWaveScale+texsize*wave_x,-1);
973             }
974             glEnd();
975             glPopMatrix();
976             break;
977
978         case 5://EXPERIMENTAL
979             glPushMatrix();
980
981
982             wave_y=-1*(wave_y-1.0);
983             wave_x_temp=(wave_x*.75)+.125;
984             wave_x_temp=-(wave_x_temp-1);
985             glBegin(GL_LINE_STRIP);
986
987             for ( x=1;x<(512);x++)
988             {
989                 dy2_adj=  (pcmdataL[x]-pcmdataL[x-1])*20*fWaveScale;
990                 glVertex3f((wave_x_temp*texsize)+dy2_adj*2, pcmdataL[x]*20*fWaveScale+texsize*wave_y,-1);
991             }
992             glEnd();
993             glPopMatrix();
994             break;
995
996         case 6://single waveform
997
998
999
1000
1001             glTranslatef(0,0, -1);
1002
1003             //glMatrixMode(GL_MODELVIEW);
1004             glPushMatrix();
1005             //            glLoadIdentity();
1006
1007             glTranslatef(texsize*.5,texsize*.5, 0);
1008             glRotated(-wave_mystery*90,0,0,1);
1009
1010             wave_x_temp=-2*0.4142*(abs(abs(wave_mystery)-.5)-.5);
1011             glScalef(1.0+wave_x_temp,1.0,1.0);
1012             glTranslatef(-texsize*.5,-texsize*.5, 0);
1013             wave_x_temp=-1*(wave_x-1.0);
1014
1015             glBegin(GL_LINE_STRIP);
1016             //      wave_x_temp=(wave_x*.75)+.125;
1017             //      wave_x_temp=-(wave_x_temp-1);
1018             for ( x=0;x<numsamples;x++)
1019             {
1020
1021                 //glVertex3f(x*scale, fdata_buffer[fbuffer][0][blockstart+x]*.0012*fWaveScale+texsize*wave_x_temp,-1);
1022                 glVertex3f(x*texsize/(double)numsamples, pcmdataR[x]*20*fWaveScale+texsize*wave_x_temp,-1);
1023
1024                 //glVertex3f(x*scale, texsize*wave_y_temp,-1);
1025             }
1026             //      printf("%f %f\n",texsize*wave_y_temp,wave_y_temp);
1027             glEnd();
1028             glPopMatrix();
1029             break;
1030
1031         case 7://dual waveforms
1032
1033             glPushMatrix();
1034
1035             glTranslatef(texsize*.5,texsize*.5, 0);
1036             glRotated(-wave_mystery*90,0,0,1);
1037
1038             wave_x_temp=-2*0.4142*(abs(abs(wave_mystery)-.5)-.5);
1039             glScalef(1.0+wave_x_temp,1.0,1.0);
1040             glTranslatef(-texsize*.5,-texsize*.5, 0);
1041
1042             wave_y_temp=-1*(wave_x-1);
1043
1044             glBegin(GL_LINE_STRIP);
1045
1046             for ( x=0;x<numsamples;x++)
1047             {
1048
1049                 glVertex3f((x*texsize)/(double)numsamples, pcmdataL[x]*20*fWaveScale+texsize*(wave_y_temp+(wave_y*wave_y*.5)),-1);
1050             }
1051             glEnd();
1052
1053             glBegin(GL_LINE_STRIP);
1054
1055
1056             for ( x=0;x<numsamples;x++)
1057             {
1058
1059                 glVertex3f((x*texsize)/(double)numsamples, pcmdataR[x]*20*fWaveScale+texsize*(wave_y_temp-(wave_y*wave_y*.5)),-1);
1060             }
1061             glEnd();
1062             glPopMatrix();
1063             break;
1064
1065         default:
1066             glBegin(GL_LINE_LOOP);
1067
1068             for ( x=0;x<512;x++)
1069             {
1070                 theta=(x)*(6.28/512.0);
1071                 r= (texsize/5.0+pcmdataL[x]*.002);
1072
1073                 glVertex3f(r*cos(theta)+(wave_x*texsize),r*sin(theta)+(wave_y*texsize),-1);
1074             }
1075             glEnd();
1076
1077             glBegin(GL_LINE_STRIP);
1078
1079             for ( x=0;x<512;x++)
1080             {
1081                 glVertex3f(x*scale, pcmdataL[x]*20*fWaveScale+(texsize*(wave_x+.1)),-1);
1082             }
1083             glEnd();
1084
1085             glBegin(GL_LINE_STRIP);
1086
1087             for ( x=0;x<512;x++)
1088             {
1089                 glVertex3f(x*scale, pcmdataR[x]*20*fWaveScale+(texsize*(wave_x-.1)),-1);
1090
1091             }
1092             glEnd();
1093             break;
1094             if (bWaveThick==1)  glLineWidth(2*texsize/512);
1095     }
1096     glLineWidth(texsize/512);
1097     glDisable(GL_LINE_STIPPLE);
1098 }
1099
1100
1101 void maximize_colors()
1102 {
1103     float wave_r_switch=0,wave_g_switch=0,wave_b_switch=0;
1104     //wave color brightening
1105     //
1106     //forces max color value to 1.0 and scales
1107     // the rest accordingly
1108
1109     if (bMaximizeWaveColor==1)
1110     {
1111         if(wave_r>=wave_g && wave_r>=wave_b)   //red brightest
1112         {
1113             wave_b_switch=wave_b*(1/wave_r);
1114             wave_g_switch=wave_g*(1/wave_r);
1115             wave_r_switch=1.0;
1116         }
1117         else if   (wave_b>=wave_g && wave_b>=wave_r)         //blue brightest
1118         {
1119             wave_r_switch=wave_r*(1/wave_b);
1120             wave_g_switch=wave_g*(1/wave_b);
1121             wave_b_switch=1.0;
1122
1123         }
1124
1125         else  if (wave_g>=wave_b && wave_g>=wave_r)         //green brightest
1126         {
1127             wave_b_switch=wave_b*(1/wave_g);
1128             wave_r_switch=wave_r*(1/wave_g);
1129             wave_g_switch=1.0;
1130         }
1131         glColor4f(wave_r_switch, wave_g_switch, wave_b_switch, wave_o);
1132     }
1133     else
1134     {
1135         glColor4f(wave_r, wave_g, wave_b, wave_o);
1136     }
1137
1138 }
1139
1140
1141 void modulate_opacity_by_volume()
1142
1143 {
1144     //modulate volume by opacity
1145     //
1146     //set an upper and lower bound and linearly
1147     //calculate the opacity from 0=lower to 1=upper
1148     //based on current volume
1149
1150     if (bModWaveAlphaByVolume==1)
1151     {if (vol<=fModWaveAlphaStart)  wave_o=0.0;
1152         else if (vol>=fModWaveAlphaEnd) wave_o=fWaveAlpha;
1153         else wave_o=fWaveAlpha*((vol-fModWaveAlphaStart)/(fModWaveAlphaEnd-fModWaveAlphaStart));}
1154     else wave_o=fWaveAlpha;
1155 }
1156
1157
1158 void draw_motion_vectors()
1159 {
1160     int x,y;
1161
1162     double offsetx=mv_dx*texsize, intervalx=texsize/(double)mv_x;
1163     double offsety=mv_dy*texsize, intervaly=texsize/(double)mv_y;
1164
1165     glPointSize(mv_l);
1166     glColor4f(mv_r, mv_g, mv_b, mv_a);
1167     glBegin(GL_POINTS);
1168     for (x=0;x<mv_x;x++){
1169         for(y=0;y<mv_y;y++){
1170             glVertex3f(offsetx+x*intervalx,offsety+y*intervaly,-1);
1171         }}
1172
1173     glEnd();
1174 }
1175
1176
1177 void draw_borders()
1178 {
1179     //no additive drawing for borders
1180     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1181
1182     glTranslatef(0,0,-1);
1183     //Draw Borders
1184     double of=texsize*ob_size*.5;
1185     double iff=(texsize*ib_size*.5);
1186     double texof=texsize-of;
1187
1188     glColor4d(ob_r,ob_g,ob_b,ob_a);
1189
1190     glRectd(0,0,of,texsize);
1191     glRectd(of,0,texof,of);
1192     glRectd(texof,0,texsize,texsize);
1193     glRectd(of,texsize,texof,texof);
1194     glColor4d(ib_r,ib_g,ib_b,ib_a);
1195     glRectd(of,of,of+iff,texof);
1196     glRectd(of+iff,of,texof-iff,of+iff);
1197     glRectd(texof-iff,of,texof,texof);
1198     glRectd(of+iff,texof,texof-iff,texof-iff);
1199 }
1200
1201
1202 //Here we render the interpolated mesh, and then apply the texture to it.
1203 //Well, we actually do the inverse, but its all the same.
1204 void render_interpolation()
1205 {
1206
1207     int x,y;
1208
1209     glMatrixMode(GL_MODELVIEW);
1210     glLoadIdentity();
1211     glTranslated(0, 0, -9);
1212
1213     glColor4f(0.0, 0.0, 0.0,decay);
1214
1215     glEnable(GL_TEXTURE_2D);
1216
1217     for (x=0;x<gx-1;x++)
1218     {
1219         glBegin(GL_TRIANGLE_STRIP);
1220         for(y=0;y<gy;y++)
1221         {
1222             glTexCoord4f(x_mesh[x][y], y_mesh[x][y],-1,1); glVertex4f(gridx[x][y], gridy[x][y],-1,1);
1223             glTexCoord4f(x_mesh[x+1][y], y_mesh[x+1][y],-1,1); glVertex4f(gridx[x+1][y], gridy[x+1][y],-1,1);
1224         }
1225         glEnd();
1226     }
1227     glDisable(GL_TEXTURE_2D);
1228 }
1229
1230
1231 void do_per_frame()
1232 {
1233     //Texture wrapping( clamp vs. wrap)
1234     if (bTexWrap==0)
1235     {
1236         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
1237         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
1238     }
1239     else
1240     {
1241         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1242         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1243     }
1244
1245
1246     //      glRasterPos2i(0,0);
1247     //      glClear(GL_COLOR_BUFFER_BIT);
1248     //      glColor4d(0.0, 0.0, 0.0,1.0);
1249
1250     //      glMatrixMode(GL_TEXTURE);
1251     //  glLoadIdentity();
1252
1253     glRasterPos2i(0,0);
1254     glClear(GL_COLOR_BUFFER_BIT);
1255     glColor4d(0.0, 0.0, 0.0,1.0);
1256
1257     glMatrixMode(GL_TEXTURE);
1258     glLoadIdentity();
1259
1260     glTranslatef(cx,cy, 0);
1261     if(correction)  glScalef(1,vw/(double)vh,1);
1262
1263     if(!isPerPixelEqn(ROT_OP))
1264     {
1265         //    printf("ROTATING: rot = %f\n", rot);
1266         glRotatef(rot*90, 0, 0, 1);
1267     }
1268     if(!isPerPixelEqn(SX_OP)) glScalef(1/sx,1,1);
1269     if(!isPerPixelEqn(SY_OP)) glScalef(1,1/sy,1);
1270
1271     if(correction) glScalef(1,vh/(double)vw,1);
1272     glTranslatef((-cx) ,(-cy),0);
1273
1274     if(!isPerPixelEqn(DX_OP)) glTranslatef(-dx,0,0);
1275     if(!isPerPixelEqn(DY_OP)) glTranslatef(0 ,-dy,0);
1276
1277 }
1278
1279
1280 //Actually draws the texture to the screen
1281 //
1282 //The Video Echo effect is also applied here
1283 void render_texture_to_screen()
1284 {
1285     glMatrixMode(GL_TEXTURE);
1286     glLoadIdentity();
1287
1288     glMatrixMode(GL_MODELVIEW);
1289     glLoadIdentity();
1290     glTranslatef(0, 0, -9);
1291
1292     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1293     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1294
1295     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,  GL_DECAL);
1296     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
1297
1298     //       glClear(GL_ACCUM_BUFFER_BIT);
1299     glColor4d(0.0, 0.0, 0.0,1.0f);
1300
1301     glBegin(GL_QUADS);
1302     glVertex4d(-vw*.5,-vh*.5,-1,1);
1303     glVertex4d(-vw*.5,  vh*.5,-1,1);
1304     glVertex4d(vw*.5,  vh*.5,-1,1);
1305     glVertex4d(vw*.5, -vh*.5,-1,1);
1306     glEnd();
1307
1308     //      glBindTexture( GL_TEXTURE_2D, tex2 );
1309     glEnable(GL_TEXTURE_2D);
1310
1311     // glAccum(GL_LOAD,0);
1312     // if (bDarken==1)  glBlendFunc(GL_SRC_COLOR,GL_ZERO);
1313
1314     //Draw giant rectangle and texture it with our texture!
1315     glBegin(GL_QUADS);
1316     glTexCoord4d(0, 1,0,1); glVertex4d(-vw*.5,-vh*.5,-1,1);
1317     glTexCoord4d(0, 0,0,1); glVertex4d(-vw*.5,  vh*.5,-1,1);
1318     glTexCoord4d(1, 0,0,1); glVertex4d(vw*.5,  vh*.5,-1,1);
1319     glTexCoord4d(1, 1,0,1); glVertex4d(vw*.5, -vh*.5,-1,1);
1320     glEnd();
1321
1322     glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1323
1324     //  if (bDarken==1)  glBlendFunc(GL_SRC_COLOR,GL_ONE_MINUS_SRC_ALPHA);
1325
1326     // if (bDarken==1) { glAccum(GL_ACCUM,1-fVideoEchoAlpha); glBlendFunc(GL_SRC_COLOR,GL_ZERO); }
1327
1328     glMatrixMode(GL_TEXTURE);
1329
1330     //draw video echo
1331     glColor4f(0.0, 0.0, 0.0,fVideoEchoAlpha);
1332     glTranslated(.5,.5,0);
1333     glScaled(1/fVideoEchoZoom,1/fVideoEchoZoom,1);
1334     glTranslated(-.5,-.5,0);
1335
1336     int flipx=1,flipy=1;
1337     switch (((int)nVideoEchoOrientation))
1338     {
1339         case 0: flipx=1;flipy=1;break;
1340         case 1: flipx=-1;flipy=1;break;
1341         case 2: flipx=1;flipy=-1;break;
1342         case 3: flipx=-1;flipy=-1;break;
1343         default: flipx=1;flipy=1; break;
1344     }
1345     glBegin(GL_QUADS);
1346     glTexCoord4d(0, 1,0,1); glVertex4f(-vw*.5*flipx,-vh*.5*flipy,-1,1);
1347     glTexCoord4d(0, 0,0,1); glVertex4f(-vw*.5*flipx,  vh*.5*flipy,-1,1);
1348     glTexCoord4d(1, 0,0,1); glVertex4f(vw*.5*flipx,  vh*.5*flipy,-1,1);
1349     glTexCoord4d(1, 1,0,1); glVertex4f(vw*.5*flipx, -vh*.5*flipy,-1,1);
1350     glEnd();
1351
1352
1353     glDisable(GL_TEXTURE_2D);
1354     glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1355
1356     // if (bDarken==1) { glAccum(GL_ACCUM,fVideoEchoAlpha); glAccum(GL_RETURN,1);}
1357
1358     if (bInvert==1)
1359     {
1360         glColor4f(1.0, 1.0, 1.0,1.0);
1361         glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
1362         glBegin(GL_QUADS);
1363         glVertex4f(-vw*.5*flipx,-vh*.5*flipy,-1,1);
1364         glVertex4f(-vw*.5*flipx,  vh*.5*flipy,-1,1);
1365         glVertex4f(vw*.5*flipx,  vh*.5*flipy,-1,1);
1366         glVertex4f(vw*.5*flipx, -vh*.5*flipy,-1,1);
1367         glEnd();
1368         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1369     }
1370 }
1371
1372
1373 void render_texture_to_studio()
1374 {
1375     glMatrixMode(GL_TEXTURE);
1376     glLoadIdentity();
1377
1378     glMatrixMode(GL_MODELVIEW);
1379     glLoadIdentity();
1380     glTranslatef(0, 0, -9);
1381
1382     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1383     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1384
1385     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,  GL_DECAL);
1386     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
1387
1388     //       glClear(GL_ACCUM_BUFFER_BIT);
1389     glColor4f(0.0, 0.0, 0.0,0.04);
1390
1391     glVertex4d(-vw*.5,-vh*.5,-1,1);
1392     glVertex4d(-vw*.5,  vh*.5,-1,1);
1393     glVertex4d(vw*.5,  vh*.5,-1,1);
1394     glVertex4d(vw*.5, -vh*.5,-1,1);
1395     glEnd();
1396
1397     glColor4f(0.0, 0.0, 0.0,1.0);
1398
1399     glBegin(GL_QUADS);
1400     glVertex4d(-vw*.5,0,-1,1);
1401     glVertex4d(-vw*.5,  vh*.5,-1,1);
1402     glVertex4d(vw*.5,  vh*.5,-1,1);
1403     glVertex4d(vw*.5, 0,-1,1);
1404     glEnd();
1405
1406     glBegin(GL_QUADS);
1407     glVertex4d(0,-vh*.5,-1,1);
1408     glVertex4d(0,  vh*.5,-1,1);
1409     glVertex4d(vw*.5,  vh*.5,-1,1);
1410     glVertex4d(vw*.5, -vh*.5,-1,1);
1411     glEnd();
1412
1413     glPushMatrix();
1414     glTranslatef(.25*vw, .25*vh, 0);
1415     glScalef(.5,.5,1);
1416
1417     //      glBindTexture( GL_TEXTURE_2D, tex2 );
1418     glEnable(GL_TEXTURE_2D);
1419
1420     // glAccum(GL_LOAD,0);
1421     // if (bDarken==1)  glBlendFunc(GL_SRC_COLOR,GL_ZERO);
1422
1423     //Draw giant rectangle and texture it with our texture!
1424     glBegin(GL_QUADS);
1425     glTexCoord4d(0, 1,0,1); glVertex4d(-vw*.5,-vh*.5,-1,1);
1426     glTexCoord4d(0, 0,0,1); glVertex4d(-vw*.5,  vh*.5,-1,1);
1427     glTexCoord4d(1, 0,0,1); glVertex4d(vw*.5,  vh*.5,-1,1);
1428     glTexCoord4d(1, 1,0,1); glVertex4d(vw*.5, -vh*.5,-1,1);
1429     glEnd();
1430
1431     glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1432
1433     //  if (bDarken==1)  glBlendFunc(GL_SRC_COLOR,GL_ONE_MINUS_SRC_ALPHA);
1434
1435     // if (bDarken==1) { glAccum(GL_ACCUM,1-fVideoEchoAlpha); glBlendFunc(GL_SRC_COLOR,GL_ZERO); }
1436
1437     glMatrixMode(GL_TEXTURE);
1438
1439     //draw video echo
1440     glColor4f(0.0, 0.0, 0.0,fVideoEchoAlpha);
1441     glTranslated(.5,.5,0);
1442     glScaled(1/fVideoEchoZoom,1/fVideoEchoZoom,1);
1443     glTranslated(-.5,-.5,0);
1444
1445     int flipx=1,flipy=1;
1446     switch (((int)nVideoEchoOrientation))
1447     {
1448         case 0: flipx=1;flipy=1;break;
1449         case 1: flipx=-1;flipy=1;break;
1450         case 2: flipx=1;flipy=-1;break;
1451         case 3: flipx=-1;flipy=-1;break;
1452         default: flipx=1;flipy=1; break;
1453     }
1454     glBegin(GL_QUADS);
1455     glTexCoord4d(0, 1,0,1); glVertex4f(-vw*.5*flipx,-vh*.5*flipy,-1,1);
1456     glTexCoord4d(0, 0,0,1); glVertex4f(-vw*.5*flipx,  vh*.5*flipy,-1,1);
1457     glTexCoord4d(1, 0,0,1); glVertex4f(vw*.5*flipx,  vh*.5*flipy,-1,1);
1458     glTexCoord4d(1, 1,0,1); glVertex4f(vw*.5*flipx, -vh*.5*flipy,-1,1);
1459     glEnd();
1460
1461     glDisable(GL_TEXTURE_2D);
1462     glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1463
1464     // if (bDarken==1) { glAccum(GL_ACCUM,fVideoEchoAlpha); glAccum(GL_RETURN,1);}
1465
1466
1467     if (bInvert==1)
1468     {
1469         glColor4f(1.0, 1.0, 1.0,1.0);
1470         glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
1471         glBegin(GL_QUADS);
1472         glVertex4f(-vw*.5*flipx,-vh*.5*flipy,-1,1);
1473         glVertex4f(-vw*.5*flipx,  vh*.5*flipy,-1,1);
1474         glVertex4f(vw*.5*flipx,  vh*.5*flipy,-1,1);
1475         glVertex4f(vw*.5*flipx, -vh*.5*flipy,-1,1);
1476         glEnd();
1477         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1478     }
1479
1480     //  glTranslated(.5,.5,0);
1481     //  glScaled(1/fVideoEchoZoom,1/fVideoEchoZoom,1);
1482     //   glTranslated(-.5,-.5,0);
1483     //glTranslatef(0,.5*vh,0);
1484
1485     //per_pixel monitor
1486     //glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
1487     int x,y;
1488     glMatrixMode(GL_MODELVIEW);
1489     glPopMatrix();
1490     glPushMatrix();
1491     glTranslatef(.25*vw, -.25*vh, 0);
1492     glScalef(.5,.5,1);
1493     glColor4f(1,1,1,.6);
1494
1495     for (x=0;x<gx;x++)
1496     {
1497         glBegin(GL_LINE_STRIP);
1498         for(y=0;y<gy;y++)
1499         {
1500             glVertex4f((x_mesh[x][y]-.5)* vw, (y_mesh[x][y]-.5)*vh,-1,1);
1501             //glVertex4f((origx[x+1][y]-.5) * vw, (origy[x+1][y]-.5) *vh ,-1,1);
1502         }
1503         glEnd();
1504     }
1505
1506     for (y=0;y<gy;y++)
1507     {
1508         glBegin(GL_LINE_STRIP);
1509         for(x=0;x<gx;x++)
1510         {
1511             glVertex4f((x_mesh[x][y]-.5)* vw, (y_mesh[x][y]-.5)*vh,-1,1);
1512             //glVertex4f((origx[x+1][y]-.5) * vw, (origy[x+1][y]-.5) *vh ,-1,1);
1513         }
1514         glEnd();
1515     }
1516
1517     /*
1518        for (x=0;x<gx-1;x++){
1519        glBegin(GL_POINTS);
1520        for(y=0;y<gy;y++){
1521        glVertex4f((origx[x][y]-.5)* vw, (origy[x][y]-.5)*vh,-1,1);
1522        glVertex4f((origx[x+1][y]-.5) * vw, (origy[x+1][y]-.5) *vh ,-1,1);
1523        }
1524        glEnd();
1525        }
1526      */
1527     // glTranslated(-.5,-.5,0);     glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1528     glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1529     glMatrixMode(GL_MODELVIEW);
1530     glPopMatrix();
1531     glPushMatrix();
1532     glTranslatef(-.5*vw,0, 0);
1533
1534
1535     glTranslatef(0,-vh*.10, 0);
1536     glBegin(GL_LINE_STRIP);
1537     glColor4f(0,1.0,1.0,1.0);
1538     glVertex3f((((totalframes%256)/551.0))*vw, treb_att*-7,-1);
1539     glColor4f(1.0,1.0,1.0,1.0);
1540     glVertex3f((((totalframes%256)/551.0))*vw,0 ,-1);
1541     glColor4f(.5,1.0,1.0,1.0);
1542     glVertex3f((((totalframes%256)/551.0))*vw, treb*7,-1);
1543     glEnd();
1544
1545     glTranslatef(0,-vh*.13, 0);
1546     glBegin(GL_LINE_STRIP);
1547     glColor4f(0,1.0,0.0,1.0);
1548     glVertex3f((((totalframes%256)/551.0))*vw, mid_att*-7,-1);
1549     glColor4f(1.0,1.0,1.0,1.0);
1550     glVertex3f((((totalframes%256)/551.0))*vw,0 ,-1);
1551     glColor4f(.5,1.0,0.0,0.5);
1552     glVertex3f((((totalframes%256)/551.0))*vw, mid*7,-1);
1553     glEnd();
1554
1555     glTranslatef(0,-vh*.13, 0);
1556     glBegin(GL_LINE_STRIP);
1557     glColor4f(1.0,0.0,0.0,1.0);
1558     glVertex3f((((totalframes%256)/551.0))*vw, bass_att*-7,-1);
1559     glColor4f(1.0,1.0,1.0,1.0);
1560     glVertex3f((((totalframes%256)/551.0))*vw,0 ,-1);
1561     glColor4f(.7,0.2,0.2,1.0);
1562     glVertex3f((((totalframes%256)/551.0))*vw, bass*7,-1);
1563     glEnd();
1564
1565     glTranslatef(0,-vh*.13, 0);
1566     glBegin(GL_LINES);
1567
1568     glColor4f(1.0,1.0,1.0,1.0);
1569     glVertex3f((((totalframes%256)/551.0))*vw,0 ,-1);
1570     glColor4f(1.0,0.6,1.0,1.0);
1571     glVertex3f((((totalframes%256)/551.0))*vw, vol*7,-1);
1572     glEnd();
1573
1574     glPopMatrix();
1575 }
1576
1577