Advertisement
AniCator

OG Punch

Feb 1st, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 31.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <memory>
  5. #include <math.h>
  6.  
  7. #include "bass.h"
  8. #include "bassflac.h"
  9. #include "bass_fx.h"
  10.  
  11. #include "GL/glew.h"
  12.  
  13. #include "GL/glfw.h"
  14.  
  15. #include <string>
  16. #include <Windows.h>
  17.  
  18. #include "BPM_Custom.h"
  19.  
  20. int inputStream;
  21. int inputStream_ply;
  22. float fft[512];
  23. float oldFFT[512];
  24.  
  25. float fftMult = 5.0f;
  26.  
  27. int WIDTH = 1280;
  28. int HEIGHT = 720;
  29.  
  30. int FULL_WIDTH = NULL;
  31. int FULL_HEIGHT = NULL;
  32.  
  33. int fboresx = NULL;
  34. int fboresy = NULL;
  35.  
  36. int startId = 0;
  37. int nextId = 0;
  38.  
  39. //framebuffer test stuff
  40. unsigned int fbo; // The frame buffer object  
  41. unsigned int fbo_depth; // The depth buffer for the frame buffer object  
  42. unsigned int fbo_texture; // The texture object to write our frame buffer object to
  43.  
  44. GLuint image1;
  45. GLuint image2;
  46. GLuint image3;
  47.  
  48. GLuint program; // for shader
  49. GLuint program2; // for shader
  50.  
  51. float multGain = 0.12f;
  52. float autoGain = 1.0f;
  53.  
  54. int bass_init = false;
  55.  
  56. bool bPunchEnableDotLoop = true;
  57. bool bPunchOnlySimpleFFTDisplay = false;
  58. bool bPunchEnableSimpleFFTDisplay = true;
  59. int iPunchSwitchBoard = 0;
  60.  
  61. int g_argc;
  62. char **g_argv;
  63.  
  64. //Window mode (windowed, fullscreen)
  65. int windowMode = GLFW_WINDOW;
  66.  
  67. void printError();
  68.  
  69. inline float clamp(float x, float min, float max)
  70. {
  71.     return x < min ? min : (x > max ? max : x);
  72. }
  73.  
  74. std::string ExePath() {
  75.     char buffer[MAX_PATH];
  76.     GetModuleFileName( NULL, buffer, MAX_PATH );
  77.     std::string::size_type pos = std::string( buffer ).find_last_of( "\\/" );
  78.     return std::string( buffer ).substr( 0, pos);
  79. }
  80.  
  81. char *textFileRead(char *fn) {
  82.  
  83.     FILE *fp;
  84.     char *content = "";
  85.  
  86.     int count=0;
  87.  
  88.     char fn2[MAX_PATH];
  89.    
  90.     sprintf_s(fn2,MAX_PATH,"%s\\%s",ExePath().c_str(),fn);
  91.  
  92.     printf("loading file: %s",fn2);
  93.  
  94.     if (fn2 != NULL) {
  95.         fp = fopen(fn2,"rt");
  96.  
  97.         if (fp != NULL) {
  98.  
  99.       fseek(fp, 0, SEEK_END);
  100.       count = ftell(fp);
  101.       rewind(fp);
  102.  
  103.             if (count > 0) {
  104.                 content = (char *)malloc(sizeof(char) * (count+1));
  105.                 count = fread(content,sizeof(char),count,fp);
  106.                 content[count] = '\0';
  107.             }
  108.             fclose(fp);
  109.         }
  110.     }
  111.     return content;
  112. }
  113.  
  114.  
  115.  
  116. void CheckGLErrors(const char* who){
  117.     GLenum error = glGetError();
  118.  
  119.     if(error!=GL_NO_ERROR){
  120.         printf("GL:%s:",who);
  121.     }
  122.  
  123.     switch(error){
  124.         case GL_NO_ERROR:
  125.             return;
  126.             break;
  127.  
  128.         case GL_INVALID_ENUM:
  129.             printf("Invalid enumerator.\n");
  130.             break;
  131.  
  132.         case GL_INVALID_VALUE:
  133.             printf("Invalid value.\n");
  134.             break;
  135.  
  136.         case GL_INVALID_OPERATION:
  137.             printf("Invalid operation.\n");
  138.             break;
  139.  
  140.         case GL_STACK_OVERFLOW:
  141.             printf("Invalid stack overflow.\n");
  142.             break;
  143.  
  144.         case GL_STACK_UNDERFLOW:
  145.             printf("Invalid stack underflow.\n");
  146.             break;
  147.  
  148.         case GL_OUT_OF_MEMORY:
  149.             printf("Out of memory.\n");
  150.             break;
  151.  
  152.         case GL_TABLE_TOO_LARGE:
  153.             printf("Table too large.\n");
  154.             break;
  155.  
  156.         default:
  157.             printf("Unidentified error.\n");
  158.             break;
  159.     }
  160. }
  161.  
  162. void checkShaderCompile(GLuint v){
  163.     GLint blen = 0;
  164.     GLsizei slen = 0;
  165.  
  166.     glGetShaderiv(v, GL_INFO_LOG_LENGTH , &blen);      
  167.     if (blen > 1)
  168.     {
  169.      GLchar* compiler_log = (GLchar*)malloc(blen);
  170.      glGetInfoLogARB(v, blen, &slen, compiler_log);
  171.      std::cout << "compiler_log:\n"<< compiler_log;
  172.      free (compiler_log);
  173.      system("pause");
  174.      //exit(0);
  175.     }
  176. }
  177.  
  178. void setShaders() {
  179.     printf("SETSHADERS1\n");
  180.     GLuint v, f;
  181.     char *vs, *fs;
  182.  
  183.     printf("Creating shaders.\n");
  184.  
  185.     // Create shader handlers
  186.     v = glCreateShader(GL_VERTEX_SHADER);
  187.     f = glCreateShader(GL_FRAGMENT_SHADER);
  188.  
  189.     printf("Reading source files.\n");
  190.  
  191.     // Read source code from files
  192.     //vs = textFileRead("F:\\Projects\\Games\\OpenGL\\Punch\\Release\\example.vert");
  193.     //fs = textFileRead("F:\\Projects\\Games\\OpenGL\\Punch\\Release\\example.frag");
  194.    
  195.     vs = textFileRead("example.vert");
  196.     fs = textFileRead("example.frag");
  197.  
  198.     CheckGLErrors("Error creating shaders");
  199.    
  200.     const char * vv = vs;
  201.     const char * ff = fs;
  202.    
  203.     // Set shader source
  204.     printf("Setting vertex shader source\n");
  205.     glShaderSource(v, 1, &vv,NULL);
  206.     printf("Setting fragment shader source\n");
  207.     glShaderSource(f, 1, &ff,NULL);
  208.  
  209.     free(vs);
  210.     free(fs);
  211.  
  212.     CheckGLErrors("Error setting up shader sources");
  213.  
  214.     printf("Compiling shaders.\n");
  215.  
  216.     // Compile all shaders
  217.     glCompileShader(v);
  218.     checkShaderCompile(v);
  219.     CheckGLErrors("Error compiling 'v'");
  220.     glCompileShader(f);
  221.     checkShaderCompile(f);
  222.     CheckGLErrors("Error compiling 'f'");
  223.  
  224.     printf("Creating program.\n");
  225.  
  226.     // Create the program
  227.     program = glCreateProgram();
  228.  
  229.     printf("Attaching shaders.\n");
  230.  
  231.     // Attach shaders to program
  232.     glAttachShader(program,v);
  233.     glAttachShader(program,f);
  234.  
  235.     printf("Linking program.\n");
  236.  
  237.     // Link and set program to use
  238.     glLinkProgram(program);
  239.  
  240.     GLint linked;
  241.     glGetProgramiv(program, GL_LINK_STATUS, &linked);
  242.     if (!linked)
  243.     {
  244.        printf("Couldn't link program.\n");
  245.     }
  246.  
  247.     printf("Using program.\n");
  248.     CheckGLErrors("Error while setting shaders");
  249. }
  250.  
  251. void setShaders2() {
  252.     printf("SETSHADERS2\n");
  253.     GLuint v, f;
  254.     char *vs, *fs;
  255.  
  256.     printf("Creating shaders.\n");
  257.  
  258.     // Create shader handlers
  259.     v = glCreateShader(GL_VERTEX_SHADER);
  260.     f = glCreateShader(GL_FRAGMENT_SHADER);
  261.  
  262.     printf("Reading source files.\n");
  263.  
  264.     // Read source code from files
  265.     //vs = textFileRead("F:\\Projects\\Games\\OpenGL\\Punch\\Release\\example.vert");
  266.     //fs = textFileRead("F:\\Projects\\Games\\OpenGL\\Punch\\Release\\example2.frag");
  267.    
  268.     vs = textFileRead("\\example.vert");
  269.     fs = textFileRead("\\example2.frag");
  270.  
  271.     CheckGLErrors("Error creating shaders");
  272.    
  273.     const char * vv = vs;
  274.     const char * ff = fs;
  275.    
  276.     // Set shader source
  277.     printf("Setting vertex shader source\n");
  278.     glShaderSource(v, 1, &vv,NULL);
  279.     printf("Setting fragment shader source\n");
  280.     glShaderSource(f, 1, &ff,NULL);
  281.  
  282.     free(vs);
  283.     free(fs);
  284.  
  285.     CheckGLErrors("Error setting up shader sources");
  286.  
  287.     printf("Compiling shaders.\n");
  288.  
  289.     // Compile all shaders
  290.     glCompileShader(v);
  291.     checkShaderCompile(v);
  292.     CheckGLErrors("Error compiling 'v'");
  293.     glCompileShader(f);
  294.     checkShaderCompile(f);
  295.     CheckGLErrors("Error compiling 'f'");
  296.  
  297.     printf("Creating program.\n");
  298.  
  299.     // Create the program
  300.     program2 = glCreateProgram();
  301.  
  302.     printf("Attaching shaders.\n");
  303.  
  304.     // Attach shaders to program
  305.     glAttachShader(program2,v);
  306.     glAttachShader(program2,f);
  307.  
  308.     printf("Linking program.\n");
  309.  
  310.     // Link and set program to use
  311.     glLinkProgram(program2);
  312.  
  313.     GLint linked;
  314.     glGetProgramiv(program2, GL_LINK_STATUS, &linked);
  315.     if (!linked)
  316.     {
  317.        printf("Couldn't link program.\n");
  318.     }
  319.  
  320.     printf("Using program.\n");
  321.     CheckGLErrors("Error while setting shaders");
  322. }
  323.  
  324. void fboSetup()
  325. {
  326.     glGenTextures(1, &fbo_texture); // Generate one texture  
  327.     glBindTexture(GL_TEXTURE_2D, fbo_texture); // Bind the texture fbo_texture  
  328.  
  329.     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fboresx , fboresy, 0, GL_RGBA, GL_FLOAT, NULL); // Create a standard texture with the width and height of our window  
  330.  
  331.     // Setup the basic texture parameters  
  332.     //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);  
  333.     //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);  
  334.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  335.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  336.  
  337.     // Unbind the texture  
  338.     glBindTexture(GL_TEXTURE_2D, 0);  
  339.  
  340.     glGenFramebuffers( 1, &fbo );
  341.     glBindFramebuffer( GL_FRAMEBUFFER, fbo );
  342.  
  343.     glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fbo_texture, 0); // Attach the texture fbo_texture to the color buffer in our frame buffer
  344.  
  345.     GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); // Check that status of our generated frame buffer  
  346.  
  347.     if (status != GL_FRAMEBUFFER_COMPLETE_EXT) // If the frame buffer does not report back as complete  
  348.     {  
  349.     std::cout << "Couldn't create frame buffer" << std::endl; // Output an error to the console  
  350.     system("pause");
  351.     exit(0); // Exit the application  
  352.     }
  353.  
  354.     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // Unbind our frame buffer
  355.  
  356.     CheckGLErrors("There was a problem setting up the FBO.");
  357.     printf("fboSetup() end\n");
  358. }
  359.  
  360. void glSettings()
  361. {
  362.     glEnable( GL_POINT_SMOOTH );
  363.     glPointSize(5.0f*(FULL_WIDTH/WIDTH));
  364.     fboSetup();
  365. }
  366.  
  367. //Calculates the average of input range
  368. //TODO: unstable but it works still have to add some checks
  369. float FFTAverage(float fft[],int index,int range){
  370.     int low = index-(range/2);
  371.     int high = index+(range/2);
  372.  
  373.     float sum = 0;
  374.     int count = 0;
  375.     for(int i = low;i<high;i++){
  376.         sum+=fft[i];
  377.         count++;
  378.     }
  379.     return sum/count;
  380. }
  381.  
  382. void bassFunc()
  383. {
  384.     if(BASS_ChannelIsActive(inputStream)==BASS_ACTIVE_STOPPED)
  385.     {
  386.         if(g_argv[nextId+1]!=0){
  387.            
  388.             nextId+=1;
  389.         }
  390.         else
  391.         {
  392.             nextId=startId;
  393.         }
  394.         printf("Full file: %s\n",g_argv[nextId]);
  395.  
  396.         std::string fileFull = g_argv[nextId];
  397.         std::string fileExt = fileFull.substr(fileFull.rfind("."),std::string::npos);
  398.         printf("File extension: %s\n",fileExt.c_str());
  399.  
  400.         //Check if .txt file was provided
  401.         if(fileExt.compare(".txt") == 0)
  402.         {
  403.             //This is a .txt file
  404.  
  405.             //Read file
  406.             std::string fileContent;
  407.             std::ifstream textFile (fileFull.c_str());
  408.             if (textFile.is_open())
  409.             {
  410.                 std::getline(textFile,fileContent);
  411.                
  412.                 printf("Text file content: %s\n",fileContent.c_str());
  413.             }
  414.             else
  415.             {
  416.                 printf("Unable to open file.\n");
  417.                 system("pause");
  418.                 return;
  419.             }
  420.            
  421.  
  422.             inputStream = BASS_StreamCreateURL(fileContent.c_str(),0, 0, NULL, 0);
  423.         }
  424.         else
  425.         {
  426.                 if(fileExt.compare(".flac") == 0)
  427.                 {
  428.                     //FLAC File
  429.                     inputStream = BASS_FLAC_StreamCreateFile(false,g_argv[nextId],0,0,0);
  430.                 }
  431.                 else
  432.                 {
  433.                     //Not a .txt nor FLAC file
  434.                     inputStream = BASS_StreamCreateFile(false,g_argv[nextId],0,0,0);
  435.                 }
  436.         }
  437.        
  438.  
  439.         printError();
  440.  
  441.         BASS_BFX_DAMP amprams;
  442.         amprams.fTarget = 1.2f;
  443.         amprams.fQuiet = 0.0f;
  444.         amprams.fGain = 4.8f;
  445.         amprams.fRate = 0.6f;
  446.         amprams.fDelay = 0.1f;
  447.         amprams.lChannel = BASS_BFX_CHANALL;
  448.  
  449.         //int fx = BASS_ChannelSetFX(inputStream,BASS_FX_BFX_DAMP,0);
  450.         //BASS_FXSetParameters(fx,&amprams);
  451.  
  452.         bool play = BASS_ChannelPlay(inputStream,true);
  453.  
  454.         printError();
  455.    
  456.  
  457.     //BASS_ChannelSetAttribute(inputStream,BASS_ATTRIB_VOL,0.2);
  458.  
  459.     printError();
  460.  
  461.     printf("init:%i\nplay:%i\n",bass_init,play);
  462.     }
  463.     BASS_ChannelGetData(inputStream,fft,BASS_DATA_FFT1024|BASS_DATA_FLOAT);
  464. }
  465.  
  466. float punchSwitchboardLast = 0.0f;
  467. float punchSwitchMaxDelta = 10.0f;
  468. void punchUpdateSwitchboard()
  469. {
  470.     float punchSwitchCurrentTime = (float)glfwGetTime();
  471.     float punchSwitchDelta = punchSwitchCurrentTime - punchSwitchboardLast;
  472.     if(punchSwitchDelta > punchSwitchMaxDelta)
  473.     {
  474.         if(iPunchSwitchBoard < 2)
  475.             iPunchSwitchBoard += 1;
  476.         else
  477.             iPunchSwitchBoard = 0;
  478.         punchSwitchboardLast = punchSwitchCurrentTime;
  479.     }
  480. }
  481.  
  482. void punchForceSwitchboard()
  483. {
  484.     if(iPunchSwitchBoard < 2)
  485.         iPunchSwitchBoard += 1;
  486.     else
  487.         iPunchSwitchBoard = 0;
  488. }
  489.  
  490. double timecap = 0;
  491.  
  492. float vexRes(float calc)
  493. {
  494.     calc *= 100;
  495.     calc *= (float)glfwGetTime()*0.1f;
  496.     calc += (float)timecap;
  497.     return calc;
  498. }
  499.  
  500. float sinVex(float calc)
  501. {
  502.     calc = vexRes(calc);
  503.     return sin(calc)*0.4f;
  504. }
  505.  
  506. float cosVex(float calc)
  507. {
  508.     calc = vexRes(calc);
  509.     return cos(calc)*0.4f;
  510. }
  511.  
  512. float* multiplyArray3(float array[3], float scale)
  513. {
  514.     array[0] *= scale;
  515.     array[1] *= scale;
  516.     array[2] *= scale;
  517.     return array;
  518. }
  519.  
  520. void drawSquare(float flConvertedAmp, float scale, float color[3], int gridSize)
  521. {
  522.     glBegin(GL_TRIANGLES);
  523.  
  524.     float fanLoc = 0.05f + (0.05f * flConvertedAmp);
  525.     fanLoc /= gridSize/10;
  526.     float offsetX = sin((-1.0f + flConvertedAmp * 10.0f) + ((float)glfwGetTime()*0.1f)) * 0.5f * scale;
  527.     float offsetY = cos((-1.0f + flConvertedAmp * 10.0f) + ((float)glfwGetTime()*0.1f)) * 0.5f * scale;
  528.  
  529.     int iOffsetX = (int)(offsetX * gridSize);
  530.     int iOffsetY = (int)(offsetY * gridSize);
  531.     offsetX = (float)iOffsetX / (float)gridSize;
  532.     offsetY = (float)iOffsetY / (float)gridSize;
  533.  
  534.     glColor3f(color[0],color[1],color[2]);
  535.     glVertex3f(offsetX+0.0f,offsetY+0.0f,0.0f);
  536.     glVertex3f(offsetX+fanLoc,offsetY+0.0f,0.0f);
  537.     glVertex3f(offsetX+fanLoc,offsetY+fanLoc,0.0f);
  538.  
  539.     glColor3f(color[0],color[1],color[2]);
  540.     glVertex3f(offsetX+0.0f,offsetY+0.0f,0.0f);
  541.     glVertex3f(offsetX+0.0f,offsetY+fanLoc,0.0f);
  542.     glVertex3f(offsetX+fanLoc,offsetY+fanLoc,0.0f);
  543.  
  544.     glEnd( );
  545. }
  546.  
  547. void drawSquareSimpleDisplay(float flConvertedAmp, float offsetX)
  548. {
  549.     glBegin(GL_TRIANGLES);
  550.  
  551.     float fanLoc = flConvertedAmp*2.5f;
  552.     float offsetY = -1.0f;
  553.     float barWidth = 0.003f;
  554.  
  555.     glColor3f(1.0,1.0,1.0);
  556.     glVertex3f(offsetX+0.0f,offsetY+0.0f,0.0f);
  557.     glVertex3f(offsetX+barWidth,offsetY+0.0f,0.0f);
  558.     glVertex3f(offsetX+barWidth,offsetY+fanLoc,0.0f);
  559.  
  560.     glColor3f(1.0,1.0,1.0);
  561.     glVertex3f(offsetX+0.0f,offsetY+0.0f,0.0f);
  562.     glVertex3f(offsetX+0.0f,offsetY+fanLoc,0.0f);
  563.     glVertex3f(offsetX+barWidth,offsetY+fanLoc,0.0f);
  564.  
  565.     glEnd( );
  566. }
  567.  
  568. int maxdraw = 100;
  569. float direction = 1.0f;
  570. float timeDir = 0.0f;
  571. float lastForceSwitch = 0.0f;
  572. float lastBeatHit = 0.0f;
  573. double lastFrameTime = 0.0f;
  574.  
  575. //FFT vars
  576. float totalcalc = 0.0f;
  577. float calc;
  578. float FFTDrawData[100]; //maxdraw
  579.  
  580. void calculateFFTVars()
  581. {
  582.     totalcalc = 0.0f;
  583.     calc = 0.0f;
  584.     float newcalc = 0.0f;
  585.     for(int i=0;i<maxdraw;i++)
  586.     {
  587.         int idx = (i*(512/maxdraw));
  588.         calc = FFTAverage(fft,idx,10)*fftMult;
  589.         newcalc = (float)((oldFFT[idx]*0.93)+(calc*0.07));
  590.         FFTDrawData[i] = newcalc;
  591.         //float newcalc2 = ((oldFFT[idx]*0.9)+(calc*0.1));
  592.  
  593.         totalcalc+=newcalc;
  594.  
  595.         timecap+=(0.05f*newcalc);
  596.  
  597.         if(!bPunchEnableDotLoop || iPunchSwitchBoard==1)
  598.         {
  599.             if(!bPunchOnlySimpleFFTDisplay)
  600.                 oldFFT[(i*(512/maxdraw))] = newcalc;
  601.         }
  602.     }
  603. }
  604.  
  605. GLenum drawMode = GL_POINTS;
  606. void drawGL()
  607. {
  608.     CheckGLErrors("unknown location - error");
  609.     int viewWidth = fboresx;
  610.     int viewHeight = fboresy;
  611.     float scaleFactorX = (float)(FULL_WIDTH/fboresx);
  612.     float scaleFactorY = (float)(FULL_HEIGHT/fboresy);
  613.     if(windowMode==GLFW_FULLSCREEN)
  614.     {
  615.         viewWidth *= (int)scaleFactorX;
  616.         viewHeight *= (int)scaleFactorY;
  617.         glViewport(0, 0, viewWidth, viewHeight);
  618.     }
  619.     glViewport(0, 0, viewWidth, viewHeight);
  620.  
  621.     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); // Bind our frame buffer for rendering
  622.     CheckGLErrors("While binding framebuffer");
  623.     glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT); // Push our glEnable and glViewport states
  624.  
  625.     //glClearColor(0.0f, 0.0f, 0.0f, 0.4f);
  626.     //glClear(GL_COLOR_BUFFER_BIT);
  627.  
  628.     CheckGLErrors("smthing");
  629.  
  630.     if(bPunchOnlySimpleFFTDisplay)
  631.     {
  632.         bPunchEnableDotLoop=false;
  633.         iPunchSwitchBoard = -1;
  634.     }
  635.  
  636.     for(int i=0;i<maxdraw;i++)
  637.     {
  638.         int idx = (i*(512/maxdraw));
  639.         float newcalc = FFTDrawData[i];
  640.  
  641.         float dark = 1.0f-(i*(1.0f/maxdraw));
  642.  
  643.         if(!bPunchEnableDotLoop || iPunchSwitchBoard==1)
  644.         {
  645.             if(!bPunchOnlySimpleFFTDisplay)
  646.                 oldFFT[(i*(512/maxdraw))] = newcalc;
  647.             continue;
  648.         }
  649.  
  650.         glPointSize(5.0f*(FULL_WIDTH/WIDTH)+newcalc*50.0f);
  651.  
  652.         glBegin(drawMode);
  653.        
  654.         if(drawMode!=GL_LINES)
  655.         {
  656.             glColor3f(1.0f-(i/maxdraw),newcalc,0.0f);
  657.         }
  658.         else
  659.         {
  660.             glColor3f(0.0f,0.0f,0.0f);
  661.         }
  662.         glVertex3f(-0.5f,0.0f,0.0f);
  663.         if(drawMode==GL_LINES)
  664.         {
  665.             glVertex3f(0.0f,0.0f,0.0f);
  666.         }
  667.  
  668.         glEnd( );
  669.  
  670.         glPointSize(5.0f*(FULL_WIDTH/WIDTH)+newcalc*50.0f);
  671.  
  672.         glBegin(drawMode);
  673.        
  674.        
  675.         if(drawMode!=GL_LINES)
  676.         {
  677.             glColor3f(0,newcalc,1.0f-(i/maxdraw));
  678.         }
  679.         else
  680.         {
  681.             glColor3f(0.0f,0.0f,0.0f);
  682.         }
  683.         glVertex3f(0.0f,0.0f,0.0f);
  684.         if(drawMode==GL_LINES)
  685.         {
  686.             glVertex3f(0.5f,0.0f,0.0f);
  687.         }
  688.  
  689.         glEnd( );
  690.  
  691.         glPointSize(5.0f*(FULL_WIDTH/WIDTH)+newcalc*50.0f);
  692.  
  693.         glBegin(drawMode);
  694.        
  695.         if(drawMode!=GL_LINES)
  696.         {
  697.             glColor3f(1.0f-(i/maxdraw),0.0f,newcalc);
  698.         }
  699.         else
  700.         {
  701.             glColor3f(0.0f,0.0f,0.0f);
  702.         }
  703.         glVertex3f(0.5f,0.0f,0.0f);
  704.         if(drawMode==GL_LINES)
  705.         {
  706.             glVertex3f(0.0f+(i*0.5*direction*cos(glfwGetTime()*0.05)*sinVex(newcalc)*(2.0f/maxdraw))*1.5, 0.1f+cosVex(newcalc), 0.0f);
  707.         }
  708.  
  709.         glEnd( );
  710.  
  711.         glPointSize(5.0f*(FULL_WIDTH/WIDTH)+newcalc);
  712.  
  713.         glBegin(drawMode);
  714.  
  715.         if(drawMode!=GL_LINES)
  716.         {
  717.             glColor3f(1.0f*dark,0.2f*dark,0.8f*dark);
  718.         }
  719.         else
  720.         {
  721.             glColor3f(0.0f,0.0f,0.0f);
  722.         }
  723.         glVertex3f(0.0f+(i*0.5*direction*cos(glfwGetTime()*0.05)*sinVex(newcalc)*(2.0f/maxdraw))*1.5, 0.1f+cosVex(newcalc), 0.0f);
  724.         if(drawMode==GL_LINES)
  725.         {
  726.             glVertex3f(0.0f-(i*0.5*direction*sin(glfwGetTime()*0.05)*cosVex(newcalc)*(2.0f/maxdraw))*1.5, -0.1f+sinVex(newcalc), 0.0f);
  727.         }
  728.        
  729.         glEnd( );
  730.  
  731.         glBegin(drawMode);
  732.  
  733.         if(drawMode!=GL_LINES)
  734.         {
  735.             glColor3f(0.4f*dark,0.8f*dark,0.0f*dark);
  736.         }
  737.         else
  738.         {
  739.             glColor3f(0.0f,0.0f,0.0f);
  740.         }
  741.         glVertex3f(0.0f-(i*0.5*direction*sin(glfwGetTime()*0.05)*cosVex(newcalc)*(2.0f/maxdraw))*1.5, -0.1f+sinVex(newcalc), 0.0f);
  742.        
  743.         glEnd( );
  744.  
  745.         glBegin(drawMode);
  746.  
  747.         glColor3f(1.0f,0.8f,0.0f);
  748.         glVertex3f(-1.0f+(i*(2.0f/maxdraw)), sinVex(newcalc)*0.2, 0.0f);
  749.         if(drawMode==GL_LINES)
  750.         {
  751.             glVertex3f(1.0f-(i*(2.0f/maxdraw)), cosVex(newcalc), 0.0f);
  752.         }
  753.        
  754.         glEnd( );
  755.  
  756.         glBegin(drawMode);
  757.  
  758.         glColor3f(0.0f,0.4f,0.5f);
  759.         glVertex3f(1.0f-(i*(2.0f/maxdraw)), cosVex(newcalc), 0.0f);
  760.         if(drawMode==GL_LINES)
  761.         {
  762.             glVertex3f(-1.0f+(i*(2.0f/maxdraw)), 0.1f+cosVex(newcalc), 0.0f);
  763.         }
  764.        
  765.         glEnd( );
  766.  
  767.         glBegin(drawMode);
  768.  
  769.         glColor3f(0.0f,0.8f,1.0f);
  770.         glVertex3f(-1.0f+(i*(2.0f/maxdraw)), 0.1f+cosVex(newcalc), 0.0f);
  771.         if(drawMode==GL_LINES)
  772.         {
  773.             glVertex3f(1.0f-(i*(2.0f/maxdraw)), -0.3f+sinVex(newcalc)*0.2, 0.0f);
  774.         }
  775.        
  776.         glEnd( );
  777.  
  778.         glBegin(drawMode);
  779.  
  780.         glColor3f(1.0f,0.1f,0.0f);
  781.         glVertex3f(1.0f-(i*(2.0f/maxdraw)), -0.3f+sinVex(newcalc)*0.2, 0.0f);
  782.         if(drawMode==GL_LINES)
  783.         {
  784.             glVertex3f(-1.0f+(i*(2.0f/maxdraw)), -0.8f+calc, 0.0f);
  785.         }
  786.        
  787.         glEnd( );
  788.  
  789.         glPointSize(5.0f*(FULL_WIDTH/WIDTH)+calc*20.0f);
  790.  
  791.         glBegin(drawMode);
  792.        
  793.         glColor3f(1.0f-(i/maxdraw),0.2f+calc,0.2f+calc);
  794.         glVertex3f(-1.0f+(i*(2.0f/maxdraw)), -0.8f+calc, 0.0f);
  795.         if(drawMode==GL_LINES)
  796.         {
  797.             glVertex3f(-1.0f+(i*(2.0f/maxdraw)), -0.8f+newcalc, 0.0f);
  798.         }
  799.  
  800.         glEnd( );
  801.  
  802.         glPointSize(5.0f*(FULL_WIDTH/WIDTH));
  803.  
  804.         glBegin(drawMode);
  805.  
  806.         glColor3f(0.2f+calc,0.0f,1.0f-(i*(i/maxdraw)));
  807.         glVertex3f(-1.0f+(i*(2.0f/maxdraw)), -0.8f+newcalc, 0.0f);
  808.        
  809.         glEnd( );
  810.  
  811.         oldFFT[(i*(512/maxdraw))] = newcalc;
  812.     }
  813.  
  814.     if(bPunchOnlySimpleFFTDisplay || bPunchEnableSimpleFFTDisplay)
  815.     {
  816.         static float fftSimpleAmp[512];
  817.         for(int i=0;i<512;i++)
  818.         {
  819.             float equalAmp = (float)i / 51.2;
  820.             if(!bPunchOnlySimpleFFTDisplay)
  821.                 equalAmp *= 0.6f;
  822.             float fftAmp = FFTAverage(fft,i,2)*fftMult*equalAmp;
  823.             fftAmp = (fftAmp*0.1) + (fftSimpleAmp[i]*0.9);
  824.             fftSimpleAmp[i] = fftAmp;
  825.  
  826.             float offset = -1.0f;
  827.             offset += ((float)i/256) * 2.0f;
  828.             drawSquareSimpleDisplay(fftSimpleAmp[i], offset);
  829.         }
  830.     }
  831.  
  832.     if(iPunchSwitchBoard==1)
  833.     {
  834.         float color1[3] = {1.0f,0.2f,0.1f};
  835.         float color2[3] = {0.2f,1.0f,0.1f};
  836.         float color3[3] = {0.1f,0.2f,1.0f};
  837.         float fftSquareAmp1 = FFTAverage(fft,32,10)*fftMult;
  838.         float fftSquareAmp2 = FFTAverage(fft,64,10)*fftMult;
  839.         float fftSquareAmp3 = FFTAverage(fft,128,10)*fftMult;
  840.         int squareManyMaker = fftSquareAmp1 * 50;
  841.         for(int i=0;i<squareManyMaker;i++)
  842.         {
  843.             float loopScale = 1.0f * i/5;
  844.             //Smaller squares
  845.             drawSquare(fftSquareAmp2, 0.95f + loopScale, color3, 20);
  846.             drawSquare(fftSquareAmp2, 0.75f + loopScale, color2, 20);
  847.             drawSquare(fftSquareAmp2, 0.55f + loopScale, color1, 20);
  848.             drawSquare(fftSquareAmp3, 1.05f + loopScale, color3, 20);
  849.             drawSquare(fftSquareAmp3, 0.85f + loopScale, color2, 20);
  850.             drawSquare(fftSquareAmp3, 0.65f + loopScale, color1, 20);
  851.  
  852.             //Bigger squares
  853.             drawSquare(fftSquareAmp1, 1.0f + loopScale, color1, 10);
  854.             drawSquare(fftSquareAmp2, 0.8f + loopScale, color2, 10);
  855.             drawSquare(fftSquareAmp3, 0.6f + loopScale, color3, 10);
  856.         }
  857.     }
  858.  
  859.     glPointSize(20.0f*(FULL_WIDTH/WIDTH)*totalcalc);
  860.  
  861.     glBegin(GL_POINTS);
  862.  
  863.         glColor3f(1.0f-(totalcalc*multGain*4.5),1.0f-(totalcalc*multGain*4.5),1.0f-(totalcalc*multGain*4.5));
  864.         glVertex3f(sinVex((totalcalc+glfwGetTime())*0.01)*0.5,cosVex((totalcalc+glfwGetTime())*0.01)*0.5,0.0f);
  865.     glEnd( );
  866.  
  867.     glBegin(GL_POINTS);
  868.  
  869.         glColor3f(1.0f-(totalcalc*multGain*4.5),1.0f-(totalcalc*multGain*4.5),1.0f-(totalcalc*multGain*4.5));
  870.         glVertex3f(cosVex((totalcalc+glfwGetTime()*0.08)*0.005)*1.2,sinVex((totalcalc+glfwGetTime()*0.008)*0.005)*1.2,0.0f);
  871.     glEnd( );
  872.  
  873.     glBegin(GL_POINTS);
  874.  
  875.         glColor3f(1.0f-(totalcalc*multGain*4.5),1.0f-(totalcalc*multGain*4.5),1.0f-(totalcalc*multGain*4.5));
  876.         glVertex3f(cosVex((totalcalc+glfwGetTime()*0.001)*0.001)*1.8,sinVex((totalcalc+glfwGetTime()*0.001)*0.001)*1.8,0.0f);
  877.     glEnd( );
  878.  
  879.     if(drawMode==GL_LINES)
  880.     {
  881.         drawMode=GL_POINTS;
  882.     }
  883.  
  884.     if(totalcalc>2.0 && (glfwGetTime()-timeDir)>0.5f)
  885.     {
  886.         direction*=-1;
  887.         timeDir=glfwGetTime();
  888.     }
  889.  
  890.     float switchFloat = FFTAverage(fft,32,4)*fftMult;
  891.     //punchUpdateSwitchboard();
  892.     if(totalcalc > 2.0f && totalcalc < 2.5f && (glfwGetTime()-lastForceSwitch)>0.3f)
  893.     {
  894.         //punchForceSwitchboard();
  895.         lastForceSwitch = glfwGetTime();
  896.     }
  897.  
  898.     static float peakFloat = 0.1f;
  899.     float beatFloat = FFTAverage(fft,40,20)*fftMult;
  900.     peakFloat = (peakFloat*0.99) + (beatFloat*0.01);
  901.     if(beatFloat > peakFloat && (glfwGetTime()-lastBeatHit)>(80/60) && (glfwGetTime()-lastBeatHit)<(200/60))
  902.     {
  903.         BeatRegisterHit();
  904.         lastBeatHit = (float)glfwGetTime();
  905.     }
  906.  
  907.     if(totalcalc>5.5 && totalcalc<5.8)
  908.     {
  909.         if(drawMode==GL_POINTS)
  910.         {
  911.             drawMode=GL_LINES;
  912.         }
  913.         else
  914.         {
  915.             drawMode=GL_POINTS;
  916.         }
  917.     }
  918.  
  919.     autoGain = clamp(2.5f-(totalcalc/1.72),0.0f,2.0f);
  920.  
  921.    
  922.  
  923.     float norGain = multGain*autoGain;
  924.  
  925.     CheckGLErrors("smthing1");
  926.  
  927.     glPopAttrib(); // Restore our glEnable and glViewport states
  928.     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
  929.  
  930.     if(windowMode==GLFW_WINDOW)
  931.     {
  932.         glViewport(0, 0, WIDTH, HEIGHT);
  933.     }
  934.     else
  935.     {
  936.         glViewport(0, 0, FULL_WIDTH, FULL_HEIGHT);
  937.     }
  938.  
  939.     glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  940.     glClear(GL_COLOR_BUFFER_BIT);
  941.  
  942.     CheckGLErrors("fb bind & clear");
  943.  
  944.     glBindTexture(GL_TEXTURE_2D, fbo_texture);
  945.  
  946.     glUseProgram(program);
  947.     glActiveTexture(GL_TEXTURE0);
  948.     int texture_location = glGetUniformLocation(program, "RTScene");
  949.     glUniform1i(texture_location, 0);
  950.  
  951.     CheckGLErrors("uniform texture_location ");
  952.  
  953.     float glslDeltaTime = (float)(glfwGetTime() - lastFrameTime);
  954.     int uniform_time_delta = glGetUniformLocation(program, "deltaTime");
  955.     glUniform1f(uniform_time_delta, glslDeltaTime);
  956.  
  957.     CheckGLErrors("uniform uniform_time_delta ");
  958.    
  959.     int ampdata = glGetUniformLocation(program, "inputGain");
  960.     if(bPunchOnlySimpleFFTDisplay)
  961.     {
  962.         glUniform1f(ampdata, 0.5f);
  963.         CheckGLErrors("uniform ampdata 0.5f ");
  964.     }
  965.     else
  966.     {
  967.         glUniform1f(ampdata, totalcalc);
  968.         CheckGLErrors("uniform ampdata totalcalc ");
  969.     }
  970.  
  971.     CheckGLErrors("uniform location3 unknown aftershit ");
  972.  
  973.     //glMatrixMode(GL_PROJECTION); // Switch to the projection matrix so that we can manipulate how our scene is viewed  
  974.     //glLoadIdentity();
  975.  
  976.     glBegin(GL_QUADS);
  977.  
  978.     glTexCoord2f(0.0f, 0.0f);
  979.     glVertex3f(-1.0f, -1.0f, 0.0f); // The bottom left corner
  980.  
  981.     glTexCoord2f(0.0f, 1.0f);
  982.     glVertex3f(-1.0f, 1.0, 0.0f); // The top left corner
  983.  
  984.     glTexCoord2f(1.0f, 1.0f);
  985.     glVertex3f(1.0f, 1.0f, 0.0f); // The top right corner
  986.  
  987.     glTexCoord2f(1.0f, 0.0f);
  988.     glVertex3f(1.0f, -1.0f, 0.0f); // The bottom right corner
  989.  
  990.     glEnd();
  991.  
  992.     glBindTexture(GL_TEXTURE_2D, 0);
  993.     glUseProgram(0);
  994.  
  995.     glViewport(0, 0, fboresx, fboresy);
  996.  
  997.     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); // Bind our frame buffer for rendering
  998.     CheckGLErrors("While binding framebuffer");
  999.     glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT); // Push our glEnable and glViewport states
  1000.  
  1001.     glBindTexture(GL_TEXTURE_2D, fbo_texture);
  1002.  
  1003.    
  1004.     if(bPunchOnlySimpleFFTDisplay)
  1005.     {
  1006.         totalcalc = 0.5f;
  1007.     }
  1008.     glUseProgram(program2);
  1009.     glActiveTexture(GL_TEXTURE0);
  1010.     texture_location = glGetUniformLocation(program2, "RTScene");
  1011.     glUniform1i(texture_location, 0);
  1012.  
  1013.     CheckGLErrors("uniform program2 texture_location ");
  1014.  
  1015.     uniform_time_delta = glGetUniformLocation(program2, "deltaTime");
  1016.     glUniform1f(uniform_time_delta, glslDeltaTime);
  1017.  
  1018.     CheckGLErrors("uniform program2 uniform_time_delta ");
  1019.  
  1020.     ampdata = glGetUniformLocation(program2, "inputGain");
  1021.     glUniform1f(ampdata, totalcalc);
  1022.  
  1023.     CheckGLErrors("uniform program2 ampdata");
  1024.  
  1025.     int multdata = glGetUniformLocation(program2, "multGain");
  1026.     glUniform1f(multdata, norGain);
  1027.  
  1028.     CheckGLErrors("uniform program2 multdata");
  1029.  
  1030.     glBegin(GL_QUADS);
  1031.  
  1032.     glTexCoord2f(0.0f, 0.0f);
  1033.     glVertex3f(-1.0f, -1.0f, 0.0f); // The bottom left corner
  1034.  
  1035.     glTexCoord2f(0.0f, 1.0f);
  1036.     glVertex3f(-1.0f, 1.0, 0.0f); // The top left corner
  1037.  
  1038.     glTexCoord2f(1.0f, 1.0f);
  1039.     glVertex3f(1.0f, 1.0f, 0.0f); // The top right corner
  1040.  
  1041.     glTexCoord2f(1.0f, 0.0f);
  1042.     glVertex3f(1.0f, -1.0f, 0.0f); // The bottom right corner
  1043.  
  1044.     glEnd();
  1045.  
  1046.     glBindTexture(GL_TEXTURE_2D, 0);
  1047.     glUseProgram(0);
  1048.  
  1049.     glPopAttrib(); // Restore our glEnable and glViewport states
  1050.     glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
  1051.  
  1052.     // Swap front and back rendering buffers
  1053.     glfwSwapBuffers();
  1054.  
  1055.     lastFrameTime = glfwGetTime();
  1056. }
  1057.  
  1058. void printError()
  1059. {
  1060.     int err = BASS_ErrorGetCode();
  1061.     if(err==BASS_OK)
  1062.     {
  1063.         printf("BASS is ok\n");
  1064.     }
  1065.     else
  1066.     {
  1067.         printf("BASS troubles %i\n",err);
  1068.     }
  1069. }
  1070.  
  1071. std::string openfilename(char *filter = "All Files (*.*)\0*.*\0", HWND owner = NULL) {
  1072.   OPENFILENAME ofn;
  1073.   char fileName[MAX_PATH] = "";
  1074.   ZeroMemory(&ofn, sizeof(ofn));
  1075.   ofn.lStructSize = sizeof(OPENFILENAME);
  1076.   ofn.hwndOwner = owner;
  1077.   ofn.lpstrFilter = filter;
  1078.   ofn.lpstrFile = fileName;
  1079.   ofn.nMaxFile = MAX_PATH;
  1080.   ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
  1081.   ofn.lpstrDefExt = "";
  1082.   std::string fileNameStr;
  1083.   if ( GetOpenFileName(&ofn) )
  1084.     fileNameStr = fileName;
  1085.   return fileNameStr;
  1086. }
  1087.  
  1088. void GLFWCALL punchResize(int width, int height )
  1089. {
  1090.     WIDTH = width;
  1091.     HEIGHT = height;
  1092. }
  1093.  
  1094. void IncrementStartId(int inputId)
  1095. {
  1096.     startId = inputId + 1;
  1097.     nextId = startId;
  1098. }
  1099.  
  1100. int running = GL_TRUE;
  1101. double lastDeltaTime = 0.0;
  1102. int main(int argc, char *argv[])
  1103. {
  1104.     printf("Run Punch with /help for startup command list.\n");
  1105.     printf("Playlist and args:\n");
  1106.     for(int i=0;i<argc;i++)
  1107.     {
  1108.         printf("%s\n",argv[i]);
  1109.     }
  1110.  
  1111.     //Run commands if any
  1112.     for(int i=0;i<argc;i++)
  1113.     {
  1114.         std::string argString = argv[i];
  1115.         if(argString.compare("/help") == 0)
  1116.         {
  1117.             IncrementStartId(i);
  1118.  
  1119.             printf("Commands:\n");
  1120.             printf("/help : this\n");
  1121.             printf("-debug_simple : simple debug visualisation, just a simple spectrum\n");
  1122.         }
  1123.         if(argString.compare("-debug_simple") == 0)
  1124.         {
  1125.             IncrementStartId(i);
  1126.             bPunchOnlySimpleFFTDisplay = true;
  1127.         }
  1128.     }
  1129.  
  1130.     g_argc = argc;
  1131.     g_argv = argv;
  1132.  
  1133.     if(g_argv[startId]==0)
  1134.     {
  1135.         MessageBox(NULL,"Please drag and drop one or multiple audio files onto the Punch.exe file.\n(*.mp3, *ogg, *wav and others)\nYou can also drag a .txt file containing a Shoutcast URL (not playlist) onto the .exe.","No files to Punch.",0);
  1136.         return 0;
  1137.     }
  1138.    
  1139.     printf("initializing bass.\n");
  1140.  
  1141.     bass_init = BASS_Init(-1, 44100, 0, 0, NULL);
  1142.  
  1143.     printError();
  1144.  
  1145.     printf("Loading bass_fx.\n");
  1146.     if (HIWORD(BASS_FX_GetVersion())!=BASSVERSION) {
  1147.         // incorrect version loaded!
  1148.         printf("could not load bass_fx\n");
  1149.     }
  1150.  
  1151.     printError();
  1152.  
  1153.     printf("Creating stream.\n");
  1154.  
  1155.     glfwOpenWindowHint( GLFW_OPENGL_VERSION_MAJOR, 3 );
  1156.     glfwOpenWindowHint( GLFW_OPENGL_VERSION_MINOR, 2 );
  1157.     glfwOpenWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
  1158.  
  1159.     //glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
  1160.  
  1161.     glfwOpenWindowHint( GLFW_WINDOW_NO_RESIZE, GL_TRUE );
  1162.  
  1163.     //glfwEnable( GLFW_STICKY_KEYS );
  1164.     //glfwEnable( GLFW_KEY_REPEAT );
  1165.  
  1166.     double lastPress = 0.0;
  1167.     bool windowReset = false;
  1168.     bool globalRunning = true;
  1169.  
  1170.     if(glfwInit())
  1171.     {
  1172.         GLFWvidmode dMode;
  1173.         glfwGetDesktopMode(&dMode);
  1174.         FULL_WIDTH = dMode.Width;
  1175.         FULL_HEIGHT = dMode.Height;
  1176.         while(globalRunning)
  1177.         {
  1178.             if(running==false && windowReset==false)
  1179.             {
  1180.                 globalRunning=false;
  1181.                 continue;
  1182.             }
  1183.             if(windowReset)
  1184.             {
  1185.                 running=true;
  1186.                 windowReset=false;
  1187.             }
  1188.             int glfwWidth = WIDTH;
  1189.             int glfwHeight = HEIGHT;
  1190.             if(windowMode==GLFW_FULLSCREEN)
  1191.             {
  1192.                 glfwWidth = FULL_WIDTH;
  1193.                 glfwHeight = FULL_HEIGHT;
  1194.             }
  1195.             if(glfwOpenWindow(glfwWidth,glfwHeight,0,0,0,0,0,0,windowMode))
  1196.             {
  1197.                 GLenum err = glewInit();
  1198.                 if (GLEW_OK != err)
  1199.                 {
  1200.                     // GLEW failed!
  1201.                     printf("GLEW could not be initialized.\n");
  1202.                     fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
  1203.                     system("pause");
  1204.                     exit( EXIT_FAILURE );
  1205.                 }
  1206.  
  1207.                 printf("GLEW has been initialized.\n");
  1208.                 fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
  1209.                 fboresx = FULL_WIDTH;
  1210.                 fboresy = FULL_HEIGHT;
  1211.                 glSettings();
  1212.                 setShaders();
  1213.                 setShaders2();
  1214.  
  1215.                 glfwSetWindowSizeCallback( punchResize );
  1216.                 glfwSetWindowTitle("Punch - Audio Visualisation created by Christiaan Bakker www.anicator.com");
  1217.  
  1218.                 glfwSwapInterval( 0 );
  1219.  
  1220.                 // Main loop
  1221.                 while( running )
  1222.                 {
  1223.                     // OpenGL rendering goes here...
  1224.  
  1225.                     if(glfwGetKey( GLFW_KEY_SPACE ) &&
  1226.                     glfwGetWindowParam( GLFW_OPENED )){
  1227.                         setShaders();
  1228.                         setShaders2();
  1229.                     }
  1230.  
  1231.                     if(glfwGetKey( GLFW_KEY_RIGHT ) == GLFW_PRESS &&
  1232.                     glfwGetWindowParam( GLFW_OPENED ) && (glfwGetTime()-lastPress)>0.3f){
  1233.                         BASS_ChannelStop(inputStream);
  1234.                         lastPress=glfwGetTime();
  1235.                     }
  1236.  
  1237.                     if(glfwGetKey( GLFW_KEY_LEFT ) == GLFW_PRESS &&
  1238.                     glfwGetWindowParam( GLFW_OPENED ) && (glfwGetTime()-lastPress)>0.3f){
  1239.                         nextId-=2;
  1240.                         if(nextId<1) nextId=0;
  1241.                         BASS_ChannelStop(inputStream);
  1242.                         lastPress=glfwGetTime();
  1243.                     }
  1244.  
  1245.                     if(glfwGetKey( GLFW_KEY_KP_SUBTRACT ) == GLFW_PRESS &&
  1246.                     glfwGetWindowParam( GLFW_OPENED ) && (glfwGetTime()-lastPress)>0.3f){
  1247.                         float vol;
  1248.                         BASS_ChannelGetAttribute(inputStream,BASS_ATTRIB_VOL,&vol);
  1249.  
  1250.                         if(vol>0.0)
  1251.                         {
  1252.                             vol-=0.1;
  1253.                             printf("Lowering volume. ( %f )\n",vol);
  1254.                         }
  1255.  
  1256.                         BASS_ChannelSetAttribute(inputStream,BASS_ATTRIB_VOL,vol);
  1257.                         lastPress=glfwGetTime();
  1258.                     }
  1259.  
  1260.                     if(glfwGetKey( GLFW_KEY_KP_ADD ) == GLFW_PRESS &&
  1261.                     glfwGetWindowParam( GLFW_OPENED ) && (glfwGetTime()-lastPress)>0.3f){
  1262.                         float vol;
  1263.                         BASS_ChannelGetAttribute(inputStream,BASS_ATTRIB_VOL,&vol);
  1264.  
  1265.                         if(vol<1.0)
  1266.                         {
  1267.                             vol+=0.1;
  1268.                             printf("Increasing volume. ( %f )\n",vol);
  1269.                         }
  1270.  
  1271.                         BASS_ChannelSetAttribute(inputStream,BASS_ATTRIB_VOL,vol);
  1272.                         lastPress=glfwGetTime();
  1273.                     }
  1274.  
  1275.                     if(glfwGetKey( '-' ) &&
  1276.                     glfwGetWindowParam( GLFW_OPENED )){
  1277.                         if(multGain>0)
  1278.                             multGain-=0.01f;
  1279.                     }
  1280.  
  1281.                     if(glfwGetKey( '=' ) &&
  1282.                     glfwGetWindowParam( GLFW_OPENED )){
  1283.                         if(multGain<1)
  1284.                             multGain+=0.01f;
  1285.                     }
  1286.                
  1287.                
  1288.                     if(glfwGetWindowParam( GLFW_OPENED )){
  1289.                         if((glfwGetTime() - lastDeltaTime) > 0.01)
  1290.                         {
  1291.                             bassFunc();
  1292.                             calculateFFTVars();
  1293.                             lastDeltaTime = glfwGetTime();
  1294.                         }
  1295.                         drawGL();
  1296.                     }
  1297.                
  1298.  
  1299.                     // Check if ESC key was pressed or window was closed
  1300.                     running = !glfwGetKey( GLFW_KEY_ESC ) &&
  1301.                     glfwGetWindowParam( GLFW_OPENED );
  1302.  
  1303.                     if(glfwGetKey( 'F' ) && running &&
  1304.                         glfwGetWindowParam( GLFW_OPENED )){
  1305.                             printf("F tap\n");
  1306.                             if(windowMode==GLFW_WINDOW)
  1307.                             {
  1308.                                 windowMode=GLFW_FULLSCREEN;
  1309.                                 running=false;
  1310.                                 windowReset=true;
  1311.                             }
  1312.                             else
  1313.                             {
  1314.                                 windowMode=GLFW_WINDOW;
  1315.                                 running=false;
  1316.                                 windowReset=true;
  1317.                             }
  1318.                     }
  1319.                 }
  1320.             }
  1321.             // Close window
  1322.             glfwCloseWindow();
  1323.            
  1324.         }
  1325.         //Terminate GLFW
  1326.         glfwTerminate();
  1327.     }
  1328.  
  1329.     BASS_Free();
  1330.     return 0;
  1331. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement