Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

main.c

00001 /*****************************************************************************
00002  * main.c:
00003  *****************************************************************************
00004  * Copyright (C) 2004 the VideoLAN team
00005  * $Id: main.c 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Cyril Deguet <[email protected]>
00008  *          Adapted from projectM (http://xmms-projectm.sourceforge.net/)
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 #include "plugin.h"
00026 #include <GL/gl.h>
00027 #include <GL/glu.h>
00028 #include <unistd.h>
00029 #include <math.h>
00030 #include <stdio.h>
00031 #include <string.h>
00032 #include <stdlib.h>
00033 #include "common.h"
00034 #include "preset_types.h"
00035 #include "preset.h"
00036 #include "engine_vars.h"
00037 #include "per_pixel_eqn_types.h"
00038 #include "per_pixel_eqn.h"
00039 #include "interface_types.h"
00040 #include "video_init.h"             //Video Init Routines, resizing/fullscreen, creating pbuffers
00041 #include "PCM.h"                    //Sound data handler (buffering, FFT, etc.)
00042 #include "beat_detect.h"            //beat detection routines
00043 #include "custom_wave_types.h"
00044 #include "custom_wave.h"
00045 #include "custom_shape_types.h"
00046 #include "custom_shape.h"
00047 //#include <dmalloc.h>
00048 
00049 // Forward declarations
00050 
00051 void read_cfg();
00052 
00053 void modulate_opacity_by_volume();
00054 void maximize_colors();
00055 void do_per_pixel_math();
00056 void do_per_frame();
00057 
00058 void render_interpolation();
00059 void render_texture_to_screen();
00060 void render_texture_to_studio();
00061 void draw_motion_vectors();
00062 void draw_borders();
00063 void draw_shapes();
00064 void draw_waveform();
00065 void draw_custom_waves();
00066 
00067 void reset_per_pixel_matrices();
00068 void init_per_pixel_matrices();
00069 void free_per_pixel_matrices();
00070 
00071 int noSwitch=0;
00072 int pcmframes=1;
00073 int freqframes=0;
00074 int totalframes=1;
00075 
00076 int studio=0;
00077 
00078 extern preset_t * active_preset;
00079 
00080 GLuint RenderTargetTextureID;
00081 
00082 double wave_o;
00083 
00084 //double gx=32;  //size of interpolation
00085 //double gy=24;
00086 
00087 int texsize=512;   //size of texture to do actual graphics
00088 int vw=512;           //runtime dimensions
00089 int vh=512;
00090 int fullscreen=0;
00091 
00092 int maxsamples=2048; //size of PCM buffer
00093 int numsamples; //size of new PCM info
00094 double *pcmdataL;     //holder for most recent pcm data
00095 double *pcmdataR;     //holder for most recent pcm data
00096 
00097 int avgtime=500;  //# frames per preset
00098 
00099 char *title = NULL;
00100 int drawtitle;
00101 int title_font;
00102 int other_font;
00103 
00104 int correction=1;
00105 
00106 double vol;
00107 
00108 //per pixel equation variables
00109 
00110 
00111 double **gridx;  //grid containing interpolated mesh
00112 double **gridy;
00113 double **origtheta;  //grid containing interpolated mesh reference values
00114 double **origrad;
00115 double **origx;  //original mesh
00116 double **origy;
00117 
00118 char *buffer; //XXX
00119 
00120 int galaktos_init( galaktos_thread_t *p_thread )
00121 {
00122     init_per_pixel_matrices();
00123     pcmdataL=(double *)malloc(maxsamples*sizeof(double));
00124     pcmdataR=(double *)malloc(maxsamples*sizeof(double));
00125 
00126     /* Preset loading function */
00127     initPresetLoader();
00128 
00129     /* Load default preset directory */
00130 //    loadPresetDir("/home/cyril/.vlc/galaktos");
00131     loadPresetDir("/etc/projectM/presets");
00132 
00133     initPCM(maxsamples);
00134     initBeatDetect();
00135 
00136     // mutex = SDL_CreateMutex();
00137     return 0;
00138 }
00139 
00140 
00141 void galaktos_done( galaktos_thread_t *p_thread )
00142 {
00143     free(pcmdataL);
00144     free(pcmdataR);
00145 
00146     freeBeatDetect();
00147     freePCM();
00148     free_per_pixel_matrices();
00149     closePresetDir();
00150 //    destroyPresetLoader(); XXX segfaults :(
00151 }
00152 
00153 
00154 int galaktos_update( galaktos_thread_t *p_thread )
00155 {
00156     static int nohard=0;
00157     double vdataL[512];  //holders for FFT data (spectrum)
00158     double vdataR[512];
00159 
00160     avgtime=fps*18;
00161     totalframes++; //total amount of frames since startup
00162 
00163     Time=(double)(mdate()/1000000);
00164 
00165     frame++;  //number of frames for current preset
00166     progress= frame/(double)avgtime;
00167     if (progress>1.0) progress=1.0;
00168     // printf("start:%d at:%d min:%d stop:%d on:%d %d\n",startframe, frame frame-startframe,avgtime,  noSwitch,progress);
00169 
00170     if (frame>avgtime)
00171     {
00172         if (noSwitch==0) switchPreset(RANDOM_NEXT,0);
00173     }
00174 
00175     evalInitConditions();
00176     evalPerFrameEquations();
00177 
00178     evalCustomWaveInitConditions();
00179     evalCustomShapeInitConditions();
00180 
00181     //     printf("%f %d\n",Time,frame);
00182 
00183     reset_per_pixel_matrices();
00184 
00185 
00186     numsamples = getPCMnew(pcmdataR,1,0,fWaveSmoothing,0,0);
00187     getPCMnew(pcmdataL,0,0,fWaveSmoothing,0,1);
00188     getPCM(vdataL,512,0,1,0,0);
00189     getPCM(vdataR,512,1,1,0,0);
00190 
00191     bass=0;mid=0;treb=0;
00192 
00193     getBeatVals(vdataL,vdataR,&vol);
00194 
00195     nohard--;
00196     if(vol>8.0 && nohard<0 && noSwitch==0)
00197     {
00198 
00199         switchPreset(RANDOM_NEXT, HARD_CUT);
00200         nohard=100;
00201     }
00202 
00203     //BEGIN PASS 1
00204     //
00205     //This pass is used to render our texture
00206     //the texture is drawn to a subsection of the framebuffer
00207     //and then we perform our manipulations on it
00208     //in pass 2 we will copy the texture into texture memory
00209 
00210   //  galaktos_glx_activate_pbuffer( p_thread );
00211 
00212     glPushAttrib( GL_ALL_ATTRIB_BITS ); /* Overkill, but safe */
00213 
00214     //   if (RenderTarget) glViewport( 0, 0, RenderTarget->w, RenderTarget->h );
00215     if (0) {}
00216     else glViewport( 0, 0, texsize, texsize );
00217 
00218 
00219     glMatrixMode( GL_MODELVIEW );
00220     glPushMatrix();
00221     glLoadIdentity();
00222 
00223     glMatrixMode( GL_PROJECTION );
00224     glPushMatrix();
00225     glLoadIdentity();
00226 
00227     glOrtho(0.0, texsize, 0.0,texsize,10,40);
00228 
00229     do_per_pixel_math();
00230 
00231     do_per_frame();               //apply per-frame effects
00232     render_interpolation();       //apply per-pixel effects
00233     draw_motion_vectors();        //draw motion vectors
00234     draw_borders();               //draw borders
00235 
00236     draw_waveform();
00237     draw_shapes();
00238     draw_custom_waves();
00239 
00240     glMatrixMode( GL_MODELVIEW );
00241     glPopMatrix();
00242 
00243     glMatrixMode( GL_PROJECTION );
00244     glPopMatrix();
00245 
00246     glPopAttrib();
00247 
00248     //if ( RenderTarget )        SDL_GL_UnlockRenderTarget(RenderTarget);
00249         /* Copy our rendering to the fake render target texture */
00250     glBindTexture( GL_TEXTURE_2D, RenderTargetTextureID );
00251     glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, texsize, texsize);
00252 //    galaktos_glx_activate_window( p_thread );
00253 
00254     //BEGIN PASS 2
00255     //
00256     //end of texture rendering
00257     //now we copy the texture from the framebuffer to
00258     //video texture memory and render fullscreen on a quad surface.
00259     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00260     glMatrixMode(GL_PROJECTION);
00261     glLoadIdentity();
00262 
00263     glFrustum(-vw*.5, vw*.5, -vh*.5,vh*.5,10,40);
00264 
00265     glLineWidth(texsize/512.0);
00266     if(studio%2)render_texture_to_studio();
00267     else render_texture_to_screen();
00268 
00269     glFinish();
00270     glFlush();
00271     //  printf("Flush %d\n",(SDL_GetTicks()-timestart));
00272 
00273     p_thread->p_opengl->pf_swap( p_thread->p_opengl );
00274 
00275     /* Process events */
00276     if( p_thread->p_opengl->pf_manage &&
00277         p_thread->p_opengl->pf_manage( p_thread->p_opengl ) )
00278     {
00279         return 1;
00280     }
00281 
00282     return 0;
00283 }
00284 
00285 
00286 void free_per_pixel_matrices()
00287 {
00288     int x;
00289 
00290     for(x = 0; x < gx; x++)
00291     {
00292         free(gridx[x]);
00293         free(gridy[x]);
00294         free(origtheta[x]);
00295         free(origrad[x]);
00296         free(origx[x]);
00297         free(origy[x]);
00298         free(x_mesh[x]);
00299         free(y_mesh[x]);
00300         free(rad_mesh[x]);
00301         free(theta_mesh[x]);
00302     }
00303 
00304     free(origx);
00305     free(origy);
00306     free(gridx);
00307     free(gridy);
00308     free(x_mesh);
00309     free(y_mesh);
00310     free(rad_mesh);
00311     free(theta_mesh);
00312 }
00313 
00314 
00315 void init_per_pixel_matrices()
00316 {
00317     int x,y;
00318 
00319     gridx=(double **)malloc(gx * sizeof(double *));
00320     gridy=(double **)malloc(gx * sizeof(double *));
00321 
00322     origx=(double **)malloc(gx * sizeof(double *));
00323     origy=(double **)malloc(gx * sizeof(double *));
00324     origrad=(double **)malloc(gx * sizeof(double *));
00325     origtheta=(double **)malloc(gx * sizeof(double *));
00326 
00327     x_mesh=(double **)malloc(gx * sizeof(double *));
00328     y_mesh=(double **)malloc(gx * sizeof(double *));
00329     rad_mesh=(double **)malloc(gx * sizeof(double *));
00330     theta_mesh=(double **)malloc(gx * sizeof(double *));
00331 
00332     sx_mesh=(double **)malloc(gx * sizeof(double *));
00333     sy_mesh=(double **)malloc(gx * sizeof(double *));
00334     dx_mesh=(double **)malloc(gx * sizeof(double *));
00335     dy_mesh=(double **)malloc(gx * sizeof(double *));
00336     cx_mesh=(double **)malloc(gx * sizeof(double *));
00337     cy_mesh=(double **)malloc(gx * sizeof(double *));
00338     zoom_mesh=(double **)malloc(gx * sizeof(double *));
00339     zoomexp_mesh=(double **)malloc(gx * sizeof(double *));
00340     rot_mesh=(double **)malloc(gx * sizeof(double *));
00341 
00342     for(x = 0; x < gx; x++)
00343     {
00344         gridx[x] = (double *)malloc(gy * sizeof(double));
00345         gridy[x] = (double *)malloc(gy * sizeof(double));
00346 
00347         origtheta[x] = (double *)malloc(gy * sizeof(double));
00348         origrad[x] = (double *)malloc(gy * sizeof(double));
00349         origx[x] = (double *)malloc(gy * sizeof(double));
00350         origy[x] = (double *)malloc(gy * sizeof(double));
00351 
00352         x_mesh[x] = (double *)malloc(gy * sizeof(double));
00353         y_mesh[x] = (double *)malloc(gy * sizeof(double));
00354 
00355         rad_mesh[x] = (double *)malloc(gy * sizeof(double));
00356         theta_mesh[x] = (double *)malloc(gy * sizeof(double));
00357 
00358         sx_mesh[x] = (double *)malloc(gy * sizeof(double));
00359         sy_mesh[x] = (double *)malloc(gy * sizeof(double));
00360         dx_mesh[x] = (double *)malloc(gy * sizeof(double));
00361         dy_mesh[x] = (double *)malloc(gy * sizeof(double));
00362         cx_mesh[x] = (double *)malloc(gy * sizeof(double));
00363         cy_mesh[x] = (double *)malloc(gy * sizeof(double));
00364 
00365         zoom_mesh[x] = (double *)malloc(gy * sizeof(double));
00366         zoomexp_mesh[x] = (double *)malloc(gy * sizeof(double));
00367 
00368         rot_mesh[x] = (double *)malloc(gy * sizeof(double));
00369     }
00370 
00371     //initialize reference grid values
00372     for (x=0;x<gx;x++)
00373     {
00374         for(y=0;y<gy;y++)
00375         {
00376             origx[x][y]=x/(double)(gx-1);
00377             origy[x][y]=-((y/(double)(gy-1))-1);
00378             origrad[x][y]=hypot((origx[x][y]-.5)*2,(origy[x][y]-.5)*2) * .7071067;
00379             origtheta[x][y]=atan2(((origy[x][y]-.5)*2),((origx[x][y]-.5)*2));
00380             gridx[x][y]=origx[x][y]*texsize;
00381             gridy[x][y]=origy[x][y]*texsize;
00382         }
00383     }
00384 }
00385 
00386 
00387 
00388 //calculate matrices for per_pixel
00389 void do_per_pixel_math()
00390 {
00391     int x,y;
00392 
00393     double rotx=0,roty=0;
00394     evalPerPixelEqns();
00395 
00396     if(!isPerPixelEqn(CX_OP))
00397     {
00398         for (x=0;x<gx;x++)
00399         {
00400             for(y=0;y<gy;y++){
00401                 cx_mesh[x][y]=cx;
00402             }
00403         }
00404     }
00405 
00406     if(!isPerPixelEqn(CY_OP))
00407     {
00408         for (x=0;x<gx;x++)
00409         {
00410             for(y=0;y<gy;y++)
00411             {
00412                 cy_mesh[x][y]=cy;
00413             }
00414         }
00415     }
00416 
00417     if(isPerPixelEqn(ROT_OP))
00418     {
00419         for (x=0;x<gx;x++)
00420         {
00421             for(y=0;y<gy;y++)
00422             {
00423                 x_mesh[x][y]=x_mesh[x][y]-cx_mesh[x][y];
00424                 y_mesh[x][y]=y_mesh[x][y]-cy_mesh[x][y];
00425                 rotx=(x_mesh[x][y])*cos(rot_mesh[x][y])-(y_mesh[x][y])*sin(rot_mesh[x][y]);
00426                 roty=(x_mesh[x][y])*sin(rot_mesh[x][y])+(y_mesh[x][y])*cos(rot_mesh[x][y]);
00427                 x_mesh[x][y]=rotx+cx_mesh[x][y];
00428                 y_mesh[x][y]=roty+cy_mesh[x][y];
00429             }
00430         }
00431     }
00432 
00433 
00434 
00435     if(!isPerPixelEqn(ZOOM_OP))
00436     {
00437         for (x=0;x<gx;x++)
00438         {
00439             for(y=0;y<gy;y++)
00440             {
00441                 zoom_mesh[x][y]=zoom;
00442             }
00443         }
00444     }
00445 
00446     if(!isPerPixelEqn(ZOOMEXP_OP))
00447     {
00448         for (x=0;x<gx;x++)
00449         {
00450             for(y=0;y<gy;y++)
00451             {
00452                 zoomexp_mesh[x][y]=zoomexp;
00453             }
00454         }
00455     }
00456 
00457 
00458     //DO ZOOM PER PIXEL
00459     for (x=0;x<gx;x++)
00460     {
00461         for(y=0;y<gy;y++)
00462         {
00463             x_mesh[x][y]=(x_mesh[x][y]-.5)*2;
00464             y_mesh[x][y]=(y_mesh[x][y]-.5)*2;
00465             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);
00466             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);
00467             x_mesh[x][y]=(x_mesh[x][y]*.5)+.5;
00468             y_mesh[x][y]=(y_mesh[x][y]*.5)+.5;
00469         }
00470     }
00471 
00472     if(isPerPixelEqn(SX_OP))
00473     {
00474         for (x=0;x<gx;x++)
00475         {
00476             for(y=0;y<gy;y++)
00477             {
00478                 x_mesh[x][y]=((x_mesh[x][y]-cx_mesh[x][y])/sx_mesh[x][y])+cx_mesh[x][y];
00479             }
00480         }
00481     }
00482 
00483     if(isPerPixelEqn(SY_OP))
00484     {
00485         for (x=0;x<gx;x++)
00486         {
00487             for(y=0;y<gy;y++)
00488             {
00489                 y_mesh[x][y]=((y_mesh[x][y]-cy_mesh[x][y])/sy_mesh[x][y])+cy_mesh[x][y];
00490             }
00491         }
00492     }
00493 
00494     if(isPerPixelEqn(DX_OP))
00495     {
00496         for (x=0;x<gx;x++)
00497         {
00498             for(y=0;y<gy;y++)
00499             {
00500 
00501                 x_mesh[x][y]=x_mesh[x][y]-dx_mesh[x][y];
00502 
00503             }
00504         }
00505     }
00506 
00507     if(isPerPixelEqn(DY_OP))
00508     {
00509         for (x=0;x<gx;x++)
00510         {
00511             for(y=0;y<gy;y++)
00512             {
00513                 y_mesh[x][y]=y_mesh[x][y]-dy_mesh[x][y];
00514 
00515             }
00516         }
00517     }
00518 
00519 
00520 }
00521 
00522 void reset_per_pixel_matrices()
00523 {
00524     int x,y;
00525 
00526     for (x=0;x<gx;x++)
00527     {
00528         for(y=0;y<gy;y++)
00529         {
00530             x_mesh[x][y]=origx[x][y];
00531             y_mesh[x][y]=origy[x][y];
00532             rad_mesh[x][y]=origrad[x][y];
00533             theta_mesh[x][y]=origtheta[x][y];
00534         }
00535     }
00536 }
00537 
00538 
00539 
00540 void draw_custom_waves()
00541 {
00542     int x;
00543 
00544     custom_wave_t *wavecode;
00545     glPointSize(texsize/512);
00546     //printf("%d\n",wavecode);
00547     //  more=isMoreCustomWave();
00548     // printf("not inner loop\n");
00549     while ((wavecode = nextCustomWave()) != NULL)
00550     {
00551         //printf("begin inner loop\n");
00552         if(wavecode->enabled==1)
00553         {
00554             // nextCustomWave();
00555 
00556             //glPushMatrix();
00557 
00558             //if(wavecode->bUseDots==1) glEnable(GL_LINE_STIPPLE);
00559             if (wavecode->bAdditive==0)  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00560             else    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
00561             if (wavecode->bDrawThick==1)  glLineWidth(2*texsize/512);
00562 
00563             //  xx= ((pcmdataL[x]-pcmdataL[x-1])*80*fWaveScale)*2;
00564             //yy=pcmdataL[x]*80*fWaveScale,-1;
00565             //glVertex3f( (wave_x*texsize)+(xx+yy)*cos(45), (wave_y*texsize)+(-yy+xx)*cos(45),-1);
00566             // printf("samples: %d\n", wavecode->samples);
00567 
00568             getPCM(wavecode->value1,wavecode->samples,0,wavecode->bSpectrum,wavecode->smoothing,0);
00569             getPCM(wavecode->value2,wavecode->samples,1,wavecode->bSpectrum,wavecode->smoothing,0);
00570             // printf("%f\n",pcmL[0]);
00571             for(x=0;x<wavecode->samples;x++)
00572             {wavecode->value1[x]=wavecode->value1[x]*wavecode->scaling;}
00573 
00574             for(x=0;x<wavecode->samples;x++)
00575             {wavecode->value2[x]=wavecode->value2[x]*wavecode->scaling;}
00576 
00577             for(x=0;x<wavecode->samples;x++)
00578             {wavecode->sample_mesh[x]=((double)x)/((double)(wavecode->samples-1));}
00579 
00580             // printf("mid inner loop\n");
00581             evalPerPointEqns();
00582             /*
00583                if(!isPerPointEquation("x"))
00584                {for(x=0;x<wavecode->samples;x++)
00585                {cw_x[x]=0;} }
00586 
00587                if(!isPerPointEquation(Y_POINT_OP))
00588                {for(x=0;x<wavecode->samples;x++)
00589                {cw_y[x]=0;}}
00590 
00591                if(!isPerPointEquation(R_POINT_OP))
00592                {for(x=0;x<wavecode->samples;x++)
00593                {cw_r[x]=wavecode->r;}}
00594                if(!isPerPointEquation(G_POINT_OP))
00595                {for(x=0;x<wavecode->samples;x++)
00596                {cw_g[x]=wavecode->g;}}
00597                if(!isPerPointEquation(B_POINT_OP))
00598                {for(x=0;x<wavecode->samples;x++)
00599                {cw_b[x]=wavecode->b;}}
00600                if(!isPerPointEquation(A_POINT_OP))
00601                {for(x=0;x<wavecode->samples;x++)
00602                {cw_a[x]=wavecode->a;}}
00603              */
00604             //put drawing code here
00605             if (wavecode->bUseDots==1)   glBegin(GL_POINTS);
00606             else   glBegin(GL_LINE_STRIP);
00607 
00608             for(x=0;x<wavecode->samples;x++)
00609             {
00610                 //          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]);
00611                 glColor4f(wavecode->r_mesh[x],wavecode->g_mesh[x],wavecode->b_mesh[x],wavecode->a_mesh[x]);
00612                 glVertex3f(wavecode->x_mesh[x]*texsize,-(wavecode->y_mesh[x]-1)*texsize,-1);
00613             }
00614             glEnd();
00615             glPointSize(texsize/512);
00616             glLineWidth(texsize/512);
00617             glDisable(GL_LINE_STIPPLE);
00618             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00619             //  glPopMatrix();
00620 
00621         }
00622 
00623     }
00624 }
00625 
00626 
00627 
00628 void draw_shapes()
00629 {
00630     int i;
00631 
00632     double theta;
00633     double rad2;
00634 
00635     double pi = 3.14159265;
00636     double start,inc,xval,yval;
00637     custom_shape_t *shapecode;
00638 
00639     while ((shapecode = nextCustomShape()) != NULL)
00640     {
00641         if(shapecode->enabled==1)
00642         {
00643             // printf("drawing shape %f\n",shapecode->ang);
00644             shapecode->y=-((shapecode->y)-1);
00645             rad2=.5;
00646             shapecode->rad=shapecode->rad*(texsize*.707*.707*.707*1.04);
00647             //Additive Drawing or Overwrite
00648             if (shapecode->additive==0)  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00649             else    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
00650 
00651             glMatrixMode(GL_MODELVIEW);
00652             glPushMatrix();
00653             if(correction)
00654             {
00655                 glTranslatef(texsize*.5,texsize*.5, 0);
00656                 glScalef(1.0,vw/(double)vh,1.0);
00657                 glTranslatef((-texsize*.5) ,(-texsize*.5),0);
00658             }
00659 
00660             start=.78539+shapecode->ang;
00661             inc=(pi*2)/(double)shapecode->sides;
00662             xval=shapecode->x*texsize;
00663             yval=shapecode->y*texsize;
00664 
00665             if (shapecode->textured)
00666             {
00667                 glMatrixMode(GL_TEXTURE);
00668                 glPushMatrix();
00669                 glLoadIdentity();
00670 
00671                 glTranslatef(.5,.5, 0);
00672                 if (correction) glScalef(1,vw/(double)vh,1);
00673 
00674                 glRotatef((shapecode->tex_ang*360/6.280), 0, 0, 1);
00675 
00676                 glScalef(1/(shapecode->tex_zoom),1/(shapecode->tex_zoom),1);
00677 
00678                 // glScalef(1,vh/(double)vw,1);
00679                 glTranslatef((-.5) ,(-.5),0);
00680                 // glScalef(1,vw/(double)vh,1);
00681                 glEnable(GL_TEXTURE_2D);
00682 
00683 
00684                 glBegin(GL_TRIANGLE_FAN);
00685 
00686                 glColor4f(shapecode->r,shapecode->g,shapecode->b,shapecode->a);
00687                 theta=start;
00688                 glTexCoord2f(.5,.5);
00689                 glVertex3f(xval,yval,-1);
00690                 glColor4f(shapecode->r2,shapecode->g2,shapecode->b2,shapecode->a2);
00691 
00692                 for ( i=0;i<shapecode->sides+1;i++)
00693                 {
00694 
00695                     theta+=inc;
00696                     //  glColor4f(shapecode->r2,shapecode->g2,shapecode->b2,shapecode->a2);
00697                     glTexCoord2f(rad2*cos(theta)+.5 ,rad2*sin(theta)+.5 );
00698                     glVertex3f(shapecode->rad*cos(theta)+xval,shapecode->rad*sin(theta)+yval,-1);
00699                 }
00700                 glEnd();
00701 
00702 
00703 
00704 
00705                 glDisable(GL_TEXTURE_2D);
00706                 glPopMatrix();
00707                 glMatrixMode(GL_MODELVIEW);
00708             }
00709             else
00710             {//Untextured (use color values)
00711                 //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);
00712                 //draw first n-1 triangular pieces
00713                 glBegin(GL_TRIANGLE_FAN);
00714 
00715                 glColor4f(shapecode->r,shapecode->g,shapecode->b,shapecode->a);
00716                 theta=start;
00717                 // glTexCoord2f(.5,.5);
00718                 glVertex3f(xval,yval,-1);
00719                 glColor4f(shapecode->r2,shapecode->g2,shapecode->b2,shapecode->a2);
00720 
00721                 for ( i=0;i<shapecode->sides+1;i++)
00722                 {
00723 
00724                     theta+=inc;
00725                     //  glColor4f(shapecode->r2,shapecode->g2,shapecode->b2,shapecode->a2);
00726                     //  glTexCoord2f(rad2*cos(theta)+.5 ,rad2*sin(theta)+.5 );
00727                     glVertex3f(shapecode->rad*cos(theta)+xval,shapecode->rad*sin(theta)+yval,-1);
00728                 }
00729                 glEnd();
00730 
00731 
00732             }
00733             if (bWaveThick==1)  glLineWidth(2*texsize/512);
00734             glBegin(GL_LINE_LOOP);
00735             glColor4f(shapecode->border_r,shapecode->border_g,shapecode->border_b,shapecode->border_a);
00736             for ( i=0;i<shapecode->sides;i++)
00737             {
00738                 theta+=inc;
00739                 glVertex3f(shapecode->rad*cos(theta)+xval,shapecode->rad*sin(theta)+yval,-1);
00740             }
00741             glEnd();
00742             if (bWaveThick==1)  glLineWidth(texsize/512);
00743 
00744             glPopMatrix();
00745         }
00746     }
00747 
00748 }
00749 
00750 
00751 void draw_waveform()
00752 {
00753 
00754     int x;
00755 
00756     double r,theta;
00757 
00758     double offset,scale,dy2_adj;
00759 
00760     double co;
00761 
00762     double wave_x_temp=0;
00763     double wave_y_temp=0;
00764 
00765     modulate_opacity_by_volume();
00766     maximize_colors();
00767 
00768     if(bWaveDots==1) glEnable(GL_LINE_STIPPLE);
00769 
00770     offset=(wave_x-.5)*texsize;
00771     scale=texsize/505.0;
00772 
00773     //Thick wave drawing
00774     if (bWaveThick==1)  glLineWidth(2*texsize/512);
00775 
00776     //Additive wave drawing (vice overwrite)
00777     if (bAdditiveWaves==0)  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00778     else    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
00779 
00780     switch(nWaveMode)
00781     {
00782         case 8://monitor
00783 
00784             glPushMatrix();
00785 
00786             glTranslatef(texsize*.5,texsize*.5, 0);
00787             glRotated(-wave_mystery*90,0,0,1);
00788 
00789             glTranslatef(-texsize*.5,-texsize*.825, 0);
00790 
00791             /*
00792                for (x=0;x<16;x++)
00793                {
00794                glBegin(GL_LINE_STRIP);
00795                glColor4f(1.0-(x/15.0),.5,x/15.0,1.0);
00796                glVertex3f((totalframes%256)*2*scale, -beat_val[x]*fWaveScale+texsize*wave_y,-1);
00797                glColor4f(.5,.5,.5,1.0);
00798                glVertex3f((totalframes%256)*2*scale, texsize*wave_y,-1);
00799                glColor4f(1.0,1.0,0,1.0);
00800             //glVertex3f((totalframes%256)*scale*2, beat_val_att[x]*fWaveScale+texsize*wave_y,-1);
00801             glEnd();
00802 
00803             glTranslatef(0,texsize*(1/36.0), 0);
00804             }
00805              */
00806 
00807             glTranslatef(0,texsize*(1/18.0), 0);
00808 
00809 
00810             glBegin(GL_LINE_STRIP);
00811             glColor4f(1.0,1.0,0.5,1.0);
00812             glVertex3f((totalframes%256)*2*scale, treb_att*5*fWaveScale+texsize*wave_y,-1);
00813             glColor4f(.2,.2,.2,1.0);
00814             glVertex3f((totalframes%256)*2*scale, texsize*wave_y,-1);
00815             glColor4f(1.0,1.0,0,1.0);
00816             glVertex3f((totalframes%256)*scale*2, treb*-5*fWaveScale+texsize*wave_y,-1);
00817             glEnd();
00818 
00819             glTranslatef(0,texsize*.075, 0);
00820             glBegin(GL_LINE_STRIP);
00821             glColor4f(0,1.0,0.0,1.0);
00822             glVertex3f((totalframes%256)*2*scale, mid_att*5*fWaveScale+texsize*wave_y,-1);
00823             glColor4f(.2,.2,.2,1.0);
00824             glVertex3f((totalframes%256)*2*scale, texsize*wave_y,-1);
00825             glColor4f(.5,1.0,.5,1.0);
00826             glVertex3f((totalframes%256)*scale*2, mid*-5*fWaveScale+texsize*wave_y,-1);
00827             glEnd();
00828 
00829 
00830             glTranslatef(0,texsize*.075, 0);
00831             glBegin(GL_LINE_STRIP);
00832             glColor4f(1.0,0,0,1.0);
00833             glVertex3f((totalframes%256)*2*scale, bass_att*5*fWaveScale+texsize*wave_y,-1);
00834             glColor4f(.2,.2,.2,1.0);
00835             glVertex3f((totalframes%256)*2*scale, texsize*wave_y,-1);
00836             glColor4f(1.0,.5,.5,1.0);
00837             glVertex3f((totalframes%256)*scale*2, bass*-5*fWaveScale+texsize*wave_y,-1);
00838             glEnd();
00839 
00840 
00841             glPopMatrix();
00842             break;
00843 
00844         case 0://circular waveforms
00845             //  double co;
00846             glPushMatrix();
00847 
00848             glTranslatef(texsize*.5,texsize*.5, 0);
00849             glScalef(1.0,vw/(double)vh,1.0);
00850             glTranslatef((-texsize*.5) ,(-texsize*.5),0);
00851 
00852             wave_y=-1*(wave_y-1.0);
00853 
00854             glBegin(GL_LINE_STRIP);
00855 
00856             for ( x=0;x<numsamples;x++)
00857             {
00858                 co= -(abs(x-((numsamples*.5)-1))/numsamples)+1;
00859                 // printf("%d %f\n",x,co);
00860                 theta=x*(6.28/numsamples);
00861                 r= ((1+2*wave_mystery)*(texsize/5.0)+
00862                     ( co*pcmdataL[x]+ (1-co)*pcmdataL[-(x-(numsamples-1))])
00863                     *25*fWaveScale);
00864 
00865                 glVertex3f(r*cos(theta)+(wave_x*texsize),r*sin(theta)+(wave_y*texsize),-1);
00866             }
00867 
00868             r= ( (1+2*wave_mystery)*(texsize/5.0)+
00869                  (0.5*pcmdataL[0]+ 0.5*pcmdataL[numsamples-1])
00870                  *20*fWaveScale);
00871 
00872             glVertex3f(r*cos(0)+(wave_x*texsize),r*sin(0)+(wave_y*texsize),-1);
00873 
00874             glEnd();
00875             /*
00876                glBegin(GL_LINE_LOOP);
00877 
00878                for ( x=0;x<(512/pcmbreak);x++)
00879                {
00880                theta=(blockstart+x)*((6.28*pcmbreak)/512.0);
00881                r= ((1+2*wave_mystery)*(texsize/5.0)+fdata_buffer[fbuffer][0][blockstart+x]*.0025*fWaveScale);
00882 
00883                glVertex3f(r*cos(theta)+(wave_x*texsize),r*sin(theta)+(wave_y*texsize),-1);
00884                }
00885                glEnd();
00886              */
00887             glPopMatrix();
00888 
00889             break;
00890 
00891         case 1://circularly moving waveform
00892             //  double co;
00893             glPushMatrix();
00894 
00895             glTranslatef(texsize*.5,texsize*.5, 0);
00896             glScalef(1.0,vw/(double)vh,1.0);
00897             glTranslatef((-texsize*.5) ,(-texsize*.5),0);
00898 
00899             wave_y=-1*(wave_y-1.0);
00900 
00901             glBegin(GL_LINE_STRIP);
00902             //theta=(frame%512)*(6.28/512.0);
00903 
00904             for ( x=1;x<512;x++)
00905             {
00906                 co= -(abs(x-255)/512.0)+1;
00907                 // printf("%d %f\n",x,co);
00908                 theta=((frame%256)*(2*6.28/512.0))+pcmdataL[x]*.2*fWaveScale;
00909                 r= ((1+2*wave_mystery)*(texsize/5.0)+
00910                     (pcmdataL[x]-pcmdataL[x-1])*80*fWaveScale);
00911 
00912                 glVertex3f(r*cos(theta)+(wave_x*texsize),r*sin(theta)+(wave_y*texsize),-1);
00913             }
00914 
00915             glEnd();
00916 
00917             glPopMatrix();
00918 
00919             break;
00920 
00921         case 2://EXPERIMENTAL
00922             wave_y=-1*(wave_y-1.0);
00923             glPushMatrix();
00924             glBegin(GL_LINE_STRIP);
00925             double xx,yy;
00926             // double xr= (wave_x*texsize), yr=(wave_y*texsize);
00927             xx=0;
00928             for ( x=1;x<512;x++)
00929             {
00930                 //xx = ((pcmdataL[x]-pcmdataL[x-1])*80*fWaveScale)*2;
00931                 xx += (pcmdataL[x]*fWaveScale);
00932                 yy= pcmdataL[x]*80*fWaveScale;
00933                 //  glVertex3f( (wave_x*texsize)+(xx+yy)*2, (wave_y*texsize)+(xx-yy)*2,-1);
00934                 glVertex3f( (wave_x*texsize)+(xx)*2, (wave_y*texsize)+(yy)*2,-1);
00935 
00936 
00937                 //   xr+=fdata_buffer[fbuffer][0][x] *.0005* fWaveScale;
00938                 //yr=(fdata_buffer[fbuffer][0][x]-fdata_buffer[fbuffer][0][x-1])*.05*fWaveScale+(wave_y*texsize);
00939                 //glVertex3f(xr,yr,-1);
00940 
00941             }
00942             glEnd();
00943             glPopMatrix();
00944             break;
00945 
00946         case 3://EXPERIMENTAL
00947             glPushMatrix();
00948             wave_y=-1*(wave_y-1.0);
00949             glBegin(GL_LINE_STRIP);
00950 
00951 
00952             for ( x=1;x<512;x++)
00953             {
00954                 xx= ((pcmdataL[x]-pcmdataL[x-1])*80*fWaveScale)*2;
00955                 yy=pcmdataL[x]*80*fWaveScale,-1;
00956                 glVertex3f( (wave_x*texsize)+(xx+yy)*cos(45), (wave_y*texsize)+(-yy+xx)*cos(45),-1);
00957             }
00958             glEnd();
00959             glPopMatrix();
00960             break;
00961 
00962         case 4://single x-axis derivative waveform
00963             glPushMatrix();
00964             wave_y=-1*(wave_y-1.0);
00965             glTranslatef(texsize*.5,texsize*.5, 0);
00966             glRotated(-wave_mystery*90,0,0,1);
00967             glTranslatef(-texsize*.5,-texsize*.5, 0);
00968             wave_x=(wave_x*.75)+.125;      wave_x=-(wave_x-1);
00969             glBegin(GL_LINE_STRIP);
00970 
00971             double dy_adj;
00972             for ( x=1;x<512;x++)
00973             {
00974                 dy_adj=  pcmdataL[x]*20*fWaveScale-pcmdataL[x-1]*20*fWaveScale;
00975                 glVertex3f((x*scale)+dy_adj, pcmdataL[x]*20*fWaveScale+texsize*wave_x,-1);
00976             }
00977             glEnd();
00978             glPopMatrix();
00979             break;
00980 
00981         case 5://EXPERIMENTAL
00982             glPushMatrix();
00983 
00984 
00985             wave_y=-1*(wave_y-1.0);
00986             wave_x_temp=(wave_x*.75)+.125;
00987             wave_x_temp=-(wave_x_temp-1);
00988             glBegin(GL_LINE_STRIP);
00989 
00990             for ( x=1;x<(512);x++)
00991             {
00992                 dy2_adj=  (pcmdataL[x]-pcmdataL[x-1])*20*fWaveScale;
00993                 glVertex3f((wave_x_temp*texsize)+dy2_adj*2, pcmdataL[x]*20*fWaveScale+texsize*wave_y,-1);
00994             }
00995             glEnd();
00996             glPopMatrix();
00997             break;
00998 
00999         case 6://single waveform
01000 
01001 
01002 
01003 
01004             glTranslatef(0,0, -1);
01005 
01006             //glMatrixMode(GL_MODELVIEW);
01007             glPushMatrix();
01008             //            glLoadIdentity();
01009 
01010             glTranslatef(texsize*.5,texsize*.5, 0);
01011             glRotated(-wave_mystery*90,0,0,1);
01012 
01013             wave_x_temp=-2*0.4142*(abs(abs(wave_mystery)-.5)-.5);
01014             glScalef(1.0+wave_x_temp,1.0,1.0);
01015             glTranslatef(-texsize*.5,-texsize*.5, 0);
01016             wave_x_temp=-1*(wave_x-1.0);
01017 
01018             glBegin(GL_LINE_STRIP);
01019             //      wave_x_temp=(wave_x*.75)+.125;
01020             //      wave_x_temp=-(wave_x_temp-1);
01021             for ( x=0;x<numsamples;x++)
01022             {
01023 
01024                 //glVertex3f(x*scale, fdata_buffer[fbuffer][0][blockstart+x]*.0012*fWaveScale+texsize*wave_x_temp,-1);
01025                 glVertex3f(x*texsize/(double)numsamples, pcmdataR[x]*20*fWaveScale+texsize*wave_x_temp,-1);
01026 
01027                 //glVertex3f(x*scale, texsize*wave_y_temp,-1);
01028             }
01029             //      printf("%f %f\n",texsize*wave_y_temp,wave_y_temp);
01030             glEnd();
01031             glPopMatrix();
01032             break;
01033 
01034         case 7://dual waveforms
01035 
01036             glPushMatrix();
01037 
01038             glTranslatef(texsize*.5,texsize*.5, 0);
01039             glRotated(-wave_mystery*90,0,0,1);
01040 
01041             wave_x_temp=-2*0.4142*(abs(abs(wave_mystery)-.5)-.5);
01042             glScalef(1.0+wave_x_temp,1.0,1.0);
01043             glTranslatef(-texsize*.5,-texsize*.5, 0);
01044 
01045             wave_y_temp=-1*(wave_x-1);
01046 
01047             glBegin(GL_LINE_STRIP);
01048 
01049             for ( x=0;x<numsamples;x++)
01050             {
01051 
01052                 glVertex3f((x*texsize)/(double)numsamples, pcmdataL[x]*20*fWaveScale+texsize*(wave_y_temp+(wave_y*wave_y*.5)),-1);
01053             }
01054             glEnd();
01055 
01056             glBegin(GL_LINE_STRIP);
01057 
01058 
01059             for ( x=0;x<numsamples;x++)
01060             {
01061 
01062                 glVertex3f((x*texsize)/(double)numsamples, pcmdataR[x]*20*fWaveScale+texsize*(wave_y_temp-(wave_y*wave_y*.5)),-1);
01063             }
01064             glEnd();
01065             glPopMatrix();
01066             break;
01067 
01068         default:
01069             glBegin(GL_LINE_LOOP);
01070 
01071             for ( x=0;x<512;x++)
01072             {
01073                 theta=(x)*(6.28/512.0);
01074                 r= (texsize/5.0+pcmdataL[x]*.002);
01075 
01076                 glVertex3f(r*cos(theta)+(wave_x*texsize),r*sin(theta)+(wave_y*texsize),-1);
01077             }
01078             glEnd();
01079 
01080             glBegin(GL_LINE_STRIP);
01081 
01082             for ( x=0;x<512;x++)
01083             {
01084                 glVertex3f(x*scale, pcmdataL[x]*20*fWaveScale+(texsize*(wave_x+.1)),-1);
01085             }
01086             glEnd();
01087 
01088             glBegin(GL_LINE_STRIP);
01089 
01090             for ( x=0;x<512;x++)
01091             {
01092                 glVertex3f(x*scale, pcmdataR[x]*20*fWaveScale+(texsize*(wave_x-.1)),-1);
01093 
01094             }
01095             glEnd();
01096             break;
01097             if (bWaveThick==1)  glLineWidth(2*texsize/512);
01098     }
01099     glLineWidth(texsize/512);
01100     glDisable(GL_LINE_STIPPLE);
01101 }
01102 
01103 
01104 void maximize_colors()
01105 {
01106     float wave_r_switch=0,wave_g_switch=0,wave_b_switch=0;
01107     //wave color brightening
01108     //
01109     //forces max color value to 1.0 and scales
01110     // the rest accordingly
01111 
01112     if (bMaximizeWaveColor==1)
01113     {
01114         if(wave_r>=wave_g && wave_r>=wave_b)   //red brightest
01115         {
01116             wave_b_switch=wave_b*(1/wave_r);
01117             wave_g_switch=wave_g*(1/wave_r);
01118             wave_r_switch=1.0;
01119         }
01120         else if   (wave_b>=wave_g && wave_b>=wave_r)         //blue brightest
01121         {
01122             wave_r_switch=wave_r*(1/wave_b);
01123             wave_g_switch=wave_g*(1/wave_b);
01124             wave_b_switch=1.0;
01125 
01126         }
01127 
01128         else  if (wave_g>=wave_b && wave_g>=wave_r)         //green brightest
01129         {
01130             wave_b_switch=wave_b*(1/wave_g);
01131             wave_r_switch=wave_r*(1/wave_g);
01132             wave_g_switch=1.0;
01133         }
01134         glColor4f(wave_r_switch, wave_g_switch, wave_b_switch, wave_o);
01135     }
01136     else
01137     {
01138         glColor4f(wave_r, wave_g, wave_b, wave_o);
01139     }
01140 
01141 }
01142 
01143 
01144 void modulate_opacity_by_volume()
01145 
01146 {
01147     //modulate volume by opacity
01148     //
01149     //set an upper and lower bound and linearly
01150     //calculate the opacity from 0=lower to 1=upper
01151     //based on current volume
01152 
01153     if (bModWaveAlphaByVolume==1)
01154     {if (vol<=fModWaveAlphaStart)  wave_o=0.0;
01155         else if (vol>=fModWaveAlphaEnd) wave_o=fWaveAlpha;
01156         else wave_o=fWaveAlpha*((vol-fModWaveAlphaStart)/(fModWaveAlphaEnd-fModWaveAlphaStart));}
01157     else wave_o=fWaveAlpha;
01158 }
01159 
01160 
01161 void draw_motion_vectors()
01162 {
01163     int x,y;
01164 
01165     double offsetx=mv_dx*texsize, intervalx=texsize/(double)mv_x;
01166     double offsety=mv_dy*texsize, intervaly=texsize/(double)mv_y;
01167 
01168     glPointSize(mv_l);
01169     glColor4f(mv_r, mv_g, mv_b, mv_a);
01170     glBegin(GL_POINTS);
01171     for (x=0;x<mv_x;x++){
01172         for(y=0;y<mv_y;y++){
01173             glVertex3f(offsetx+x*intervalx,offsety+y*intervaly,-1);
01174         }}
01175 
01176     glEnd();
01177 }
01178 
01179 
01180 void draw_borders()
01181 {
01182     //no additive drawing for borders
01183     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
01184 
01185     glTranslatef(0,0,-1);
01186     //Draw Borders
01187     double of=texsize*ob_size*.5;
01188     double iff=(texsize*ib_size*.5);
01189     double texof=texsize-of;
01190 
01191     glColor4d(ob_r,ob_g,ob_b,ob_a);
01192 
01193     glRectd(0,0,of,texsize);
01194     glRectd(of,0,texof,of);
01195     glRectd(texof,0,texsize,texsize);
01196     glRectd(of,texsize,texof,texof);
01197     glColor4d(ib_r,ib_g,ib_b,ib_a);
01198     glRectd(of,of,of+iff,texof);
01199     glRectd(of+iff,of,texof-iff,of+iff);
01200     glRectd(texof-iff,of,texof,texof);
01201     glRectd(of+iff,texof,texof-iff,texof-iff);
01202 }
01203 
01204 
01205 //Here we render the interpolated mesh, and then apply the texture to it.
01206 //Well, we actually do the inverse, but its all the same.
01207 void render_interpolation()
01208 {
01209 
01210     int x,y;
01211 
01212     glMatrixMode(GL_MODELVIEW);
01213     glLoadIdentity();
01214     glTranslated(0, 0, -9);
01215 
01216     glColor4f(0.0, 0.0, 0.0,decay);
01217 
01218     glEnable(GL_TEXTURE_2D);
01219 
01220     for (x=0;x<gx-1;x++)
01221     {
01222         glBegin(GL_TRIANGLE_STRIP);
01223         for(y=0;y<gy;y++)
01224         {
01225             glTexCoord4f(x_mesh[x][y], y_mesh[x][y],-1,1); glVertex4f(gridx[x][y], gridy[x][y],-1,1);
01226             glTexCoord4f(x_mesh[x+1][y], y_mesh[x+1][y],-1,1); glVertex4f(gridx[x+1][y], gridy[x+1][y],-1,1);
01227         }
01228         glEnd();
01229     }
01230     glDisable(GL_TEXTURE_2D);
01231 }
01232 
01233 
01234 void do_per_frame()
01235 {
01236     //Texture wrapping( clamp vs. wrap)
01237     if (bTexWrap==0)
01238     {
01239         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
01240         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
01241     }
01242     else
01243     {
01244         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
01245         glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
01246     }
01247 
01248 
01249     //      glRasterPos2i(0,0);
01250     //      glClear(GL_COLOR_BUFFER_BIT);
01251     //      glColor4d(0.0, 0.0, 0.0,1.0);
01252 
01253     //      glMatrixMode(GL_TEXTURE);
01254     //  glLoadIdentity();
01255 
01256     glRasterPos2i(0,0);
01257     glClear(GL_COLOR_BUFFER_BIT);
01258     glColor4d(0.0, 0.0, 0.0,1.0);
01259 
01260     glMatrixMode(GL_TEXTURE);
01261     glLoadIdentity();
01262 
01263     glTranslatef(cx,cy, 0);
01264     if(correction)  glScalef(1,vw/(double)vh,1);
01265 
01266     if(!isPerPixelEqn(ROT_OP))
01267     {
01268         //    printf("ROTATING: rot = %f\n", rot);
01269         glRotatef(rot*90, 0, 0, 1);
01270     }
01271     if(!isPerPixelEqn(SX_OP)) glScalef(1/sx,1,1);
01272     if(!isPerPixelEqn(SY_OP)) glScalef(1,1/sy,1);
01273 
01274     if(correction) glScalef(1,vh/(double)vw,1);
01275     glTranslatef((-cx) ,(-cy),0);
01276 
01277     if(!isPerPixelEqn(DX_OP)) glTranslatef(-dx,0,0);
01278     if(!isPerPixelEqn(DY_OP)) glTranslatef(0 ,-dy,0);
01279 
01280 }
01281 
01282 
01283 //Actually draws the texture to the screen
01284 //
01285 //The Video Echo effect is also applied here
01286 void render_texture_to_screen()
01287 {
01288     glMatrixMode(GL_TEXTURE);
01289     glLoadIdentity();
01290 
01291     glMatrixMode(GL_MODELVIEW);
01292     glLoadIdentity();
01293     glTranslatef(0, 0, -9);
01294 
01295     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
01296     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
01297 
01298     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,  GL_DECAL);
01299     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
01300 
01301     //       glClear(GL_ACCUM_BUFFER_BIT);
01302     glColor4d(0.0, 0.0, 0.0,1.0f);
01303 
01304     glBegin(GL_QUADS);
01305     glVertex4d(-vw*.5,-vh*.5,-1,1);
01306     glVertex4d(-vw*.5,  vh*.5,-1,1);
01307     glVertex4d(vw*.5,  vh*.5,-1,1);
01308     glVertex4d(vw*.5, -vh*.5,-1,1);
01309     glEnd();
01310 
01311     //      glBindTexture( GL_TEXTURE_2D, tex2 );
01312     glEnable(GL_TEXTURE_2D);
01313 
01314     // glAccum(GL_LOAD,0);
01315     // if (bDarken==1)  glBlendFunc(GL_SRC_COLOR,GL_ZERO);
01316 
01317     //Draw giant rectangle and texture it with our texture!
01318     glBegin(GL_QUADS);
01319     glTexCoord4d(0, 1,0,1); glVertex4d(-vw*.5,-vh*.5,-1,1);
01320     glTexCoord4d(0, 0,0,1); glVertex4d(-vw*.5,  vh*.5,-1,1);
01321     glTexCoord4d(1, 0,0,1); glVertex4d(vw*.5,  vh*.5,-1,1);
01322     glTexCoord4d(1, 1,0,1); glVertex4d(vw*.5, -vh*.5,-1,1);
01323     glEnd();
01324 
01325     glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
01326 
01327     //  if (bDarken==1)  glBlendFunc(GL_SRC_COLOR,GL_ONE_MINUS_SRC_ALPHA);
01328 
01329     // if (bDarken==1) { glAccum(GL_ACCUM,1-fVideoEchoAlpha); glBlendFunc(GL_SRC_COLOR,GL_ZERO); }
01330 
01331     glMatrixMode(GL_TEXTURE);
01332 
01333     //draw video echo
01334     glColor4f(0.0, 0.0, 0.0,fVideoEchoAlpha);
01335     glTranslated(.5,.5,0);
01336     glScaled(1/fVideoEchoZoom,1/fVideoEchoZoom,1);
01337     glTranslated(-.5,-.5,0);
01338 
01339     int flipx=1,flipy=1;
01340     switch (((int)nVideoEchoOrientation))
01341     {
01342         case 0: flipx=1;flipy=1;break;
01343         case 1: flipx=-1;flipy=1;break;
01344         case 2: flipx=1;flipy=-1;break;
01345         case 3: flipx=-1;flipy=-1;break;
01346         default: flipx=1;flipy=1; break;
01347     }
01348     glBegin(GL_QUADS);
01349     glTexCoord4d(0, 1,0,1); glVertex4f(-vw*.5*flipx,-vh*.5*flipy,-1,1);
01350     glTexCoord4d(0, 0,0,1); glVertex4f(-vw*.5*flipx,  vh*.5*flipy,-1,1);
01351     glTexCoord4d(1, 0,0,1); glVertex4f(vw*.5*flipx,  vh*.5*flipy,-1,1);
01352     glTexCoord4d(1, 1,0,1); glVertex4f(vw*.5*flipx, -vh*.5*flipy,-1,1);
01353     glEnd();
01354 
01355 
01356     glDisable(GL_TEXTURE_2D);
01357     glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
01358 
01359     // if (bDarken==1) { glAccum(GL_ACCUM,fVideoEchoAlpha); glAccum(GL_RETURN,1);}
01360 
01361     if (bInvert==1)
01362     {
01363         glColor4f(1.0, 1.0, 1.0,1.0);
01364         glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
01365         glBegin(GL_QUADS);
01366         glVertex4f(-vw*.5*flipx,-vh*.5*flipy,-1,1);
01367         glVertex4f(-vw*.5*flipx,  vh*.5*flipy,-1,1);
01368         glVertex4f(vw*.5*flipx,  vh*.5*flipy,-1,1);
01369         glVertex4f(vw*.5*flipx, -vh*.5*flipy,-1,1);
01370         glEnd();
01371         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
01372     }
01373 }
01374 
01375 
01376 void render_texture_to_studio()
01377 {
01378     glMatrixMode(GL_TEXTURE);
01379     glLoadIdentity();
01380 
01381     glMatrixMode(GL_MODELVIEW);
01382     glLoadIdentity();
01383     glTranslatef(0, 0, -9);
01384 
01385     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
01386     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
01387 
01388     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,  GL_DECAL);
01389     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
01390 
01391     //       glClear(GL_ACCUM_BUFFER_BIT);
01392     glColor4f(0.0, 0.0, 0.0,0.04);
01393 
01394     glVertex4d(-vw*.5,-vh*.5,-1,1);
01395     glVertex4d(-vw*.5,  vh*.5,-1,1);
01396     glVertex4d(vw*.5,  vh*.5,-1,1);
01397     glVertex4d(vw*.5, -vh*.5,-1,1);
01398     glEnd();
01399 
01400     glColor4f(0.0, 0.0, 0.0,1.0);
01401 
01402     glBegin(GL_QUADS);
01403     glVertex4d(-vw*.5,0,-1,1);
01404     glVertex4d(-vw*.5,  vh*.5,-1,1);
01405     glVertex4d(vw*.5,  vh*.5,-1,1);
01406     glVertex4d(vw*.5, 0,-1,1);
01407     glEnd();
01408 
01409     glBegin(GL_QUADS);
01410     glVertex4d(0,-vh*.5,-1,1);
01411     glVertex4d(0,  vh*.5,-1,1);
01412     glVertex4d(vw*.5,  vh*.5,-1,1);
01413     glVertex4d(vw*.5, -vh*.5,-1,1);
01414     glEnd();
01415 
01416     glPushMatrix();
01417     glTranslatef(.25*vw, .25*vh, 0);
01418     glScalef(.5,.5,1);
01419 
01420     //      glBindTexture( GL_TEXTURE_2D, tex2 );
01421     glEnable(GL_TEXTURE_2D);
01422 
01423     // glAccum(GL_LOAD,0);
01424     // if (bDarken==1)  glBlendFunc(GL_SRC_COLOR,GL_ZERO);
01425 
01426     //Draw giant rectangle and texture it with our texture!
01427     glBegin(GL_QUADS);
01428     glTexCoord4d(0, 1,0,1); glVertex4d(-vw*.5,-vh*.5,-1,1);
01429     glTexCoord4d(0, 0,0,1); glVertex4d(-vw*.5,  vh*.5,-1,1);
01430     glTexCoord4d(1, 0,0,1); glVertex4d(vw*.5,  vh*.5,-1,1);
01431     glTexCoord4d(1, 1,0,1); glVertex4d(vw*.5, -vh*.5,-1,1);
01432     glEnd();
01433 
01434     glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
01435 
01436     //  if (bDarken==1)  glBlendFunc(GL_SRC_COLOR,GL_ONE_MINUS_SRC_ALPHA);
01437 
01438     // if (bDarken==1) { glAccum(GL_ACCUM,1-fVideoEchoAlpha); glBlendFunc(GL_SRC_COLOR,GL_ZERO); }
01439 
01440     glMatrixMode(GL_TEXTURE);
01441 
01442     //draw video echo
01443     glColor4f(0.0, 0.0, 0.0,fVideoEchoAlpha);
01444     glTranslated(.5,.5,0);
01445     glScaled(1/fVideoEchoZoom,1/fVideoEchoZoom,1);
01446     glTranslated(-.5,-.5,0);
01447 
01448     int flipx=1,flipy=1;
01449     switch (((int)nVideoEchoOrientation))
01450     {
01451         case 0: flipx=1;flipy=1;break;
01452         case 1: flipx=-1;flipy=1;break;
01453         case 2: flipx=1;flipy=-1;break;
01454         case 3: flipx=-1;flipy=-1;break;
01455         default: flipx=1;flipy=1; break;
01456     }
01457     glBegin(GL_QUADS);
01458     glTexCoord4d(0, 1,0,1); glVertex4f(-vw*.5*flipx,-vh*.5*flipy,-1,1);
01459     glTexCoord4d(0, 0,0,1); glVertex4f(-vw*.5*flipx,  vh*.5*flipy,-1,1);
01460     glTexCoord4d(1, 0,0,1); glVertex4f(vw*.5*flipx,  vh*.5*flipy,-1,1);
01461     glTexCoord4d(1, 1,0,1); glVertex4f(vw*.5*flipx, -vh*.5*flipy,-1,1);
01462     glEnd();
01463 
01464     glDisable(GL_TEXTURE_2D);
01465     glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
01466 
01467     // if (bDarken==1) { glAccum(GL_ACCUM,fVideoEchoAlpha); glAccum(GL_RETURN,1);}
01468 
01469 
01470     if (bInvert==1)
01471     {
01472         glColor4f(1.0, 1.0, 1.0,1.0);
01473         glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
01474         glBegin(GL_QUADS);
01475         glVertex4f(-vw*.5*flipx,-vh*.5*flipy,-1,1);
01476         glVertex4f(-vw*.5*flipx,  vh*.5*flipy,-1,1);
01477         glVertex4f(vw*.5*flipx,  vh*.5*flipy,-1,1);
01478         glVertex4f(vw*.5*flipx, -vh*.5*flipy,-1,1);
01479         glEnd();
01480         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
01481     }
01482 
01483     //  glTranslated(.5,.5,0);
01484     //  glScaled(1/fVideoEchoZoom,1/fVideoEchoZoom,1);
01485     //   glTranslated(-.5,-.5,0);
01486     //glTranslatef(0,.5*vh,0);
01487 
01488     //per_pixel monitor
01489     //glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
01490     int x,y;
01491     glMatrixMode(GL_MODELVIEW);
01492     glPopMatrix();
01493     glPushMatrix();
01494     glTranslatef(.25*vw, -.25*vh, 0);
01495     glScalef(.5,.5,1);
01496     glColor4f(1,1,1,.6);
01497 
01498     for (x=0;x<gx;x++)
01499     {
01500         glBegin(GL_LINE_STRIP);
01501         for(y=0;y<gy;y++)
01502         {
01503             glVertex4f((x_mesh[x][y]-.5)* vw, (y_mesh[x][y]-.5)*vh,-1,1);
01504             //glVertex4f((origx[x+1][y]-.5) * vw, (origy[x+1][y]-.5) *vh ,-1,1);
01505         }
01506         glEnd();
01507     }
01508 
01509     for (y=0;y<gy;y++)
01510     {
01511         glBegin(GL_LINE_STRIP);
01512         for(x=0;x<gx;x++)
01513         {
01514             glVertex4f((x_mesh[x][y]-.5)* vw, (y_mesh[x][y]-.5)*vh,-1,1);
01515             //glVertex4f((origx[x+1][y]-.5) * vw, (origy[x+1][y]-.5) *vh ,-1,1);
01516         }
01517         glEnd();
01518     }
01519 
01520     /*
01521        for (x=0;x<gx-1;x++){
01522        glBegin(GL_POINTS);
01523        for(y=0;y<gy;y++){
01524        glVertex4f((origx[x][y]-.5)* vw, (origy[x][y]-.5)*vh,-1,1);
01525        glVertex4f((origx[x+1][y]-.5) * vw, (origy[x+1][y]-.5) *vh ,-1,1);
01526        }
01527        glEnd();
01528        }
01529      */
01530     // glTranslated(-.5,-.5,0);     glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
01531     glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
01532     glMatrixMode(GL_MODELVIEW);
01533     glPopMatrix();
01534     glPushMatrix();
01535     glTranslatef(-.5*vw,0, 0);
01536 
01537 
01538     glTranslatef(0,-vh*.10, 0);
01539     glBegin(GL_LINE_STRIP);
01540     glColor4f(0,1.0,1.0,1.0);
01541     glVertex3f((((totalframes%256)/551.0))*vw, treb_att*-7,-1);
01542     glColor4f(1.0,1.0,1.0,1.0);
01543     glVertex3f((((totalframes%256)/551.0))*vw,0 ,-1);
01544     glColor4f(.5,1.0,1.0,1.0);
01545     glVertex3f((((totalframes%256)/551.0))*vw, treb*7,-1);
01546     glEnd();
01547 
01548     glTranslatef(0,-vh*.13, 0);
01549     glBegin(GL_LINE_STRIP);
01550     glColor4f(0,1.0,0.0,1.0);
01551     glVertex3f((((totalframes%256)/551.0))*vw, mid_att*-7,-1);
01552     glColor4f(1.0,1.0,1.0,1.0);
01553     glVertex3f((((totalframes%256)/551.0))*vw,0 ,-1);
01554     glColor4f(.5,1.0,0.0,0.5);
01555     glVertex3f((((totalframes%256)/551.0))*vw, mid*7,-1);
01556     glEnd();
01557 
01558     glTranslatef(0,-vh*.13, 0);
01559     glBegin(GL_LINE_STRIP);
01560     glColor4f(1.0,0.0,0.0,1.0);
01561     glVertex3f((((totalframes%256)/551.0))*vw, bass_att*-7,-1);
01562     glColor4f(1.0,1.0,1.0,1.0);
01563     glVertex3f((((totalframes%256)/551.0))*vw,0 ,-1);
01564     glColor4f(.7,0.2,0.2,1.0);
01565     glVertex3f((((totalframes%256)/551.0))*vw, bass*7,-1);
01566     glEnd();
01567 
01568     glTranslatef(0,-vh*.13, 0);
01569     glBegin(GL_LINES);
01570 
01571     glColor4f(1.0,1.0,1.0,1.0);
01572     glVertex3f((((totalframes%256)/551.0))*vw,0 ,-1);
01573     glColor4f(1.0,0.6,1.0,1.0);
01574     glVertex3f((((totalframes%256)/551.0))*vw, vol*7,-1);
01575     glEnd();
01576 
01577     glPopMatrix();
01578 }
01579 
01580 

Generated on Tue Dec 20 10:14:58 2005 for vlc-0.8.4a by  doxygen 1.4.2