PageRenderTime 53ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/xbmc/visualizations/XBMCProjectM/libprojectM/Renderer.cpp

http://github.com/xbmc/xbmc
C++ | 2002 lines | 1189 code | 483 blank | 330 comment | 122 complexity | 61512b97320b3caf17fe879fa9eb5326 MD5 | raw file
Possible License(s): GPL-3.0, CC-BY-SA-3.0, LGPL-2.0, 0BSD, Unlicense, GPL-2.0, AGPL-1.0, BSD-3-Clause, LGPL-2.1, LGPL-3.0
  1. #include "Renderer.hpp"
  2. #include "wipemalloc.h"
  3. #include "math.h"
  4. #include "Common.hpp"
  5. #include "CustomShape.hpp"
  6. #include "CustomWave.hpp"
  7. #include "KeyHandler.hpp"
  8. #include "TextureManager.hpp"
  9. #include <iostream>
  10. #include <cassert>
  11. #include "SectionLock.h"
  12. class Preset;
  13. Renderer::Renderer(int width, int height, int gx, int gy, int texsize, BeatDetect *beatDetect, std::string _presetURL, std::string _titlefontURL, std::string _menufontURL, int xpos, int ypos, bool usefbo): title_fontURL(_titlefontURL), menu_fontURL(_menufontURL), presetURL(_presetURL), m_presetName("None"), vw(width), vh(height), gx(gx), gy(gy), texsize(texsize), vx(xpos), vy(ypos), useFBO(usefbo)
  14. {
  15. int x; int y;
  16. // this->gx=gx;
  17. // this->gy=gy;
  18. #ifdef _USE_THREADS
  19. pthread_mutexattr_t attr;
  20. pthread_mutexattr_init(&attr);
  21. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
  22. pthread_mutex_init(&_renderer_lock, &attr);
  23. pthread_mutexattr_destroy(&attr);
  24. #endif
  25. this->totalframes = 1;
  26. this->noSwitch = false;
  27. this->showfps = false;
  28. this->showtitle = false;
  29. this->showpreset = false;
  30. this->showhelp = false;
  31. this->showstats = false;
  32. this->studio = false;
  33. this->realfps=0;
  34. this->drawtitle=0;
  35. this->title = "Unknown";
  36. /** Other stuff... */
  37. this->correction = true;
  38. this->aspect=1.33333333;
  39. this->gridx=(float **)wipemalloc(gx * sizeof(float *));
  40. for(x = 0; x < gx; x++)
  41. {
  42. this->gridx[x] = (float *)wipemalloc(gy * sizeof(float));
  43. }
  44. this->gridy=(float **)wipemalloc(gx * sizeof(float *));
  45. for(x = 0; x < gx; x++)
  46. {
  47. this->gridy[x] = (float *)wipemalloc(gy * sizeof(float));
  48. }
  49. this->origx2=(float **)wipemalloc(gx * sizeof(float *));
  50. for(x = 0; x < gx; x++)
  51. {
  52. this->origx2[x] = (float *)wipemalloc(gy * sizeof(float));
  53. }
  54. this->origy2=(float **)wipemalloc(gx * sizeof(float *));
  55. for(x = 0; x < gx; x++)
  56. {
  57. this->origy2[x] = (float *)wipemalloc(gy * sizeof(float));
  58. }
  59. //initialize reference grid values
  60. for (x=0;x<gx;x++)
  61. {
  62. for(y=0;y<gy;y++)
  63. {
  64. float origx=x/(float)(gx-1);
  65. float origy=-((y/(float)(gy-1))-1);
  66. this->gridx[x][y]=origx;
  67. this->gridy[x][y]=origy;
  68. this->origx2[x][y]=( origx-.5)*2;
  69. this->origy2[x][y]=( origy-.5)*2;
  70. }
  71. }
  72. /// @bug put these on member init list
  73. this->renderTarget = new RenderTarget( texsize, width, height, useFBO );
  74. this->textureManager = new TextureManager(presetURL);
  75. this->beatDetect = beatDetect;
  76. #ifdef USE_FTGL
  77. /**f Load the standard fonts */
  78. title_font = new FTGLPixmapFont(title_fontURL.c_str());
  79. other_font = new FTGLPixmapFont(menu_fontURL.c_str());
  80. other_font->UseDisplayList(true);
  81. title_font->UseDisplayList(true);
  82. poly_font = new FTGLExtrdFont(title_fontURL.c_str());
  83. poly_font->UseDisplayList(true);
  84. poly_font->Depth(20);
  85. poly_font->FaceSize(72);
  86. poly_font->UseDisplayList(true);
  87. #endif /** USE_FTGL */
  88. }
  89. void Renderer::ResetTextures()
  90. {
  91. CSectionLock lock(&_renderer_lock);
  92. textureManager->Clear();
  93. delete(renderTarget);
  94. renderTarget = new RenderTarget(texsize, vw, vh, useFBO);
  95. reset(vw, vh);
  96. textureManager->Preload();
  97. }
  98. void Renderer::RenderFrame(PresetOutputs *presetOutputs, PresetInputs *presetInputs)
  99. {
  100. /** Save original view state */
  101. // TODO: check there is sufficient room on the stack
  102. CSectionLock lock(&_renderer_lock);
  103. glMatrixMode(GL_PROJECTION);
  104. glPushMatrix();
  105. glMatrixMode(GL_MODELVIEW);
  106. glPushMatrix();
  107. GLint viewport[4];
  108. glGetIntegerv(GL_VIEWPORT, viewport);
  109. totalframes++;
  110. //BEGIN PASS 1
  111. //
  112. //This pass is used to render our texture
  113. //the texture is drawn to a FBO or a subsection of the framebuffer
  114. //and then we perform our manipulations on it in pass 2 we
  115. //will copy the image into texture memory and render the final image
  116. //Lock FBO
  117. renderTarget->lock();
  118. glViewport( 0, 0, renderTarget->texsize, renderTarget->texsize );
  119. glEnable( GL_TEXTURE_2D );
  120. //If using FBO, sitch to FBO texture
  121. if(this->renderTarget->useFBO)
  122. {
  123. glBindTexture( GL_TEXTURE_2D, renderTarget->textureID[1] );
  124. }
  125. else
  126. {
  127. glBindTexture( GL_TEXTURE_2D, renderTarget->textureID[0] );
  128. }
  129. glMatrixMode(GL_TEXTURE);
  130. glLoadIdentity();
  131. glMatrixMode( GL_PROJECTION );
  132. glLoadIdentity();
  133. #ifdef USE_GLES1
  134. glOrthof(0.0, 1, 0.0, 1, -40, 40);
  135. #else
  136. glOrtho(0.0, 1, 0.0, 1, -40, 40);
  137. #endif
  138. glMatrixMode( GL_MODELVIEW );
  139. glLoadIdentity();
  140. if(this->renderTarget->useFBO)
  141. {
  142. //draw_motion_vectors(); //draw motion vectors
  143. //unlockPBuffer( this->renderTarget);
  144. //lockPBuffer( this->renderTarget, PBUFFER_PASS1 );
  145. }
  146. Interpolation(presetOutputs, presetInputs);
  147. // if(!this->renderTarget->useFBO)
  148. {
  149. draw_motion_vectors(presetOutputs);
  150. }
  151. draw_shapes(presetOutputs);
  152. draw_custom_waves(presetOutputs);
  153. draw_waveform(presetOutputs);
  154. if(presetOutputs->bDarkenCenter)darken_center();
  155. draw_borders(presetOutputs);
  156. draw_title_to_texture();
  157. /** Restore original view state */
  158. glMatrixMode( GL_MODELVIEW );
  159. glPopMatrix();
  160. glMatrixMode( GL_PROJECTION );
  161. glPopMatrix();
  162. renderTarget->unlock();
  163. #ifdef DEBUG
  164. GLint msd = 0, psd = 0;
  165. glGetIntegerv( GL_MODELVIEW_STACK_DEPTH, &msd );
  166. glGetIntegerv( GL_PROJECTION_STACK_DEPTH, &psd );
  167. DWRITE( "end pass1: modelview matrix depth: %d\tprojection matrix depth: %d\n", msd, psd );
  168. DWRITE( "begin pass2\n" );
  169. #endif
  170. //BEGIN PASS 2
  171. //
  172. //end of texture rendering
  173. //now we copy the texture from the FBO or framebuffer to
  174. //video texture memory and render fullscreen.
  175. /** Reset the viewport size */
  176. #ifdef USE_FBO
  177. if(renderTarget->renderToTexture)
  178. {
  179. glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, this->renderTarget->fbuffer[1]);
  180. glViewport( 0, 0, this->renderTarget->texsize, this->renderTarget->texsize );
  181. }
  182. else
  183. #endif
  184. glViewport( viewport[0], viewport[1], viewport[2], viewport[3] );
  185. glBindTexture( GL_TEXTURE_2D, this->renderTarget->textureID[0] );
  186. glMatrixMode(GL_PROJECTION);
  187. glLoadIdentity();
  188. #ifdef USE_GLES1
  189. glOrthof(-0.5, 0.5, -0.5, 0.5, -40, 40);
  190. #else
  191. glOrtho(-0.5, 0.5, -0.5, 0.5, -40, 40);
  192. #endif
  193. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  194. glLineWidth( this->renderTarget->texsize < 512 ? 1 : this->renderTarget->texsize/512.0);
  195. if(this->studio%2)render_texture_to_studio(presetOutputs, presetInputs);
  196. else render_texture_to_screen(presetOutputs);
  197. glMatrixMode(GL_MODELVIEW);
  198. glTranslatef(-0.5, -0.5, 0);
  199. // When console refreshes, there is a chance the preset has been changed by the user
  200. refreshConsole();
  201. draw_title_to_screen(false);
  202. if(this->showhelp%2) draw_help();
  203. if(this->showtitle%2) draw_title();
  204. if(this->showfps%2) draw_fps(this->realfps);
  205. if(this->showpreset%2) draw_preset();
  206. if(this->showstats%2) draw_stats(presetInputs);
  207. glTranslatef(0.5 , 0.5, 0);
  208. #ifdef USE_FBO
  209. if(renderTarget->renderToTexture)
  210. glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
  211. #endif
  212. }
  213. void Renderer::Interpolation(PresetOutputs *presetOutputs, PresetInputs *presetInputs)
  214. {
  215. CSectionLock lock(&_renderer_lock);
  216. //Texture wrapping( clamp vs. wrap)
  217. if (presetOutputs->bTexWrap==0)
  218. {
  219. #ifdef USE_GLES1
  220. glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  221. glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  222. #else
  223. glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  224. glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  225. #endif
  226. }
  227. else
  228. { glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  229. glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);}
  230. glMatrixMode(GL_TEXTURE);
  231. glLoadIdentity();
  232. glBlendFunc(GL_SRC_ALPHA, GL_ZERO);
  233. glColor4f(1.0, 1.0, 1.0, presetOutputs->decay);
  234. glEnable(GL_TEXTURE_2D);
  235. int size = presetInputs->gy;
  236. #ifdef _WIN32PC
  237. // guessed value. solved in current projectM svn
  238. float p[30*2][2];
  239. float t[30*2][2];
  240. #else
  241. float p[size*2][2];
  242. float t[size*2][2];
  243. #endif
  244. glEnableClientState(GL_VERTEX_ARRAY);
  245. glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  246. glDisableClientState(GL_COLOR_ARRAY);
  247. glVertexPointer(2,GL_FLOAT,0,p);
  248. glTexCoordPointer(2,GL_FLOAT,0,t);
  249. for (int x=0;x<presetInputs->gx - 1;x++)
  250. {
  251. for(int y=0;y<presetInputs->gy;y++)
  252. {
  253. t[y*2][0] = presetOutputs->x_mesh[x][y];
  254. t[y*2][1] = presetOutputs->y_mesh[x][y];
  255. p[y*2][0] = this->gridx[x][y];
  256. p[y*2][1] = this->gridy[x][y];
  257. t[(y*2)+1][0] = presetOutputs->x_mesh[x+1][y];
  258. t[(y*2)+1][1] = presetOutputs->y_mesh[x+1][y];
  259. p[(y*2)+1][0] = this->gridx[x+1][y];
  260. p[(y*2)+1][1] = this->gridy[x+1][y];
  261. }
  262. glDrawArrays(GL_TRIANGLE_STRIP,0,size*2);
  263. }
  264. glDisable(GL_TEXTURE_2D);
  265. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  266. }
  267. Renderer::~Renderer()
  268. {
  269. int x;
  270. if (renderTarget)
  271. delete(renderTarget);
  272. if (textureManager)
  273. delete(textureManager);
  274. assert(gx > 0);
  275. for(x = 0; x < this->gx; x++)
  276. {
  277. free(this->gridx[x]);
  278. free(this->gridy[x]);
  279. free(this->origx2[x]);
  280. free(this->origy2[x]);
  281. }
  282. //std::cerr << "freeing grids" << std::endl;
  283. free(this->origx2);
  284. free(this->origy2);
  285. free(this->gridx);
  286. free(this->gridy);
  287. //std:cerr << "grid assign begin " << std::endl;
  288. this->origx2 = NULL;
  289. this->origy2 = NULL;
  290. this->gridx = NULL;
  291. this->gridy = NULL;
  292. //std::cerr << "grid assign end" << std::endl;
  293. #ifdef USE_FTGL
  294. // std::cerr << "freeing title fonts" << std::endl;
  295. if (title_font)
  296. delete title_font;
  297. if (poly_font)
  298. delete poly_font;
  299. if (other_font)
  300. delete other_font;
  301. // std::cerr << "freeing title fonts finished" << std::endl;
  302. #endif
  303. // std::cerr << "exiting destructor" << std::endl;
  304. #ifdef _USE_THREADS
  305. pthread_mutex_destroy(&_renderer_lock);
  306. #endif
  307. }
  308. void Renderer::PerPixelMath(PresetOutputs * presetOutputs, PresetInputs * presetInputs)
  309. {
  310. int x, y;
  311. float fZoom2, fZoom2Inv;
  312. CSectionLock lock(&_renderer_lock);
  313. for (x=0;x<this->gx;x++)
  314. {
  315. for(y=0;y<this->gy;y++)
  316. {
  317. fZoom2 = powf( presetOutputs->zoom_mesh[x][y], powf( presetOutputs->zoomexp_mesh[x][y], presetInputs->rad_mesh[x][y]*2.0f - 1.0f));
  318. fZoom2Inv = 1.0f/fZoom2;
  319. presetOutputs->x_mesh[x][y]= this->origx2[x][y]*0.5f*fZoom2Inv + 0.5f;
  320. presetOutputs->y_mesh[x][y]= this->origy2[x][y]*0.5f*fZoom2Inv + 0.5f;
  321. }
  322. }
  323. for (x=0;x<this->gx;x++)
  324. {
  325. for(y=0;y<this->gy;y++)
  326. {
  327. presetOutputs->x_mesh[x][y] = ( presetOutputs->x_mesh[x][y] - presetOutputs->cx_mesh[x][y])/presetOutputs->sx_mesh[x][y] + presetOutputs->cx_mesh[x][y];
  328. }
  329. }
  330. for (x=0;x<this->gx;x++)
  331. {
  332. for(y=0;y<this->gy;y++)
  333. {
  334. presetOutputs->y_mesh[x][y] = ( presetOutputs->y_mesh[x][y] - presetOutputs->cy_mesh[x][y])/presetOutputs->sy_mesh[x][y] + presetOutputs->cy_mesh[x][y];
  335. }
  336. }
  337. float fWarpTime = presetInputs->time * presetOutputs->fWarpAnimSpeed;
  338. float fWarpScaleInv = 1.0f / presetOutputs->fWarpScale;
  339. float f[4];
  340. f[0] = 11.68f + 4.0f*cosf(fWarpTime*1.413f + 10);
  341. f[1] = 8.77f + 3.0f*cosf(fWarpTime*1.113f + 7);
  342. f[2] = 10.54f + 3.0f*cosf(fWarpTime*1.233f + 3);
  343. f[3] = 11.49f + 4.0f*cosf(fWarpTime*0.933f + 5);
  344. for (x=0;x<this->gx;x++)
  345. {
  346. for(y=0;y<this->gy;y++)
  347. {
  348. presetOutputs->x_mesh[x][y] += presetOutputs->warp_mesh[x][y]*0.0035f*sinf(fWarpTime*0.333f + fWarpScaleInv*(this->origx2[x][y]*f[0] - this->origy2[x][y]*f[3]));
  349. presetOutputs->y_mesh[x][y] += presetOutputs->warp_mesh[x][y]*0.0035f*cosf(fWarpTime*0.375f - fWarpScaleInv*(this->origx2[x][y]*f[2] + this->origy2[x][y]*f[1]));
  350. presetOutputs->x_mesh[x][y] += presetOutputs->warp_mesh[x][y]*0.0035f*cosf(fWarpTime*0.753f - fWarpScaleInv*(this->origx2[x][y]*f[1] - this->origy2[x][y]*f[2]));
  351. presetOutputs->y_mesh[x][y] += presetOutputs->warp_mesh[x][y]*0.0035f*sinf(fWarpTime*0.825f + fWarpScaleInv*(this->origx2[x][y]*f[0] + this->origy2[x][y]*f[3]));
  352. }
  353. }
  354. for (x=0;x<this->gx;x++)
  355. {
  356. for(y=0;y<this->gy;y++)
  357. {
  358. float u2 = presetOutputs->x_mesh[x][y] - presetOutputs->cx_mesh[x][y];
  359. float v2 = presetOutputs->y_mesh[x][y] - presetOutputs->cy_mesh[x][y];
  360. float cos_rot = cosf(presetOutputs->rot_mesh[x][y]);
  361. float sin_rot = sinf(presetOutputs->rot_mesh[x][y]);
  362. presetOutputs->x_mesh[x][y] = u2*cos_rot - v2*sin_rot + presetOutputs->cx_mesh[x][y];
  363. presetOutputs->y_mesh[x][y] = u2*sin_rot + v2*cos_rot + presetOutputs->cy_mesh[x][y];
  364. }
  365. }
  366. for (x=0;x<this->gx;x++)
  367. {
  368. for(y=0;y<this->gy;y++)
  369. {
  370. presetOutputs->x_mesh[x][y] -= presetOutputs->dx_mesh[x][y];
  371. }
  372. }
  373. for (x=0;x<this->gx;x++)
  374. {
  375. for(y=0;y<this->gy;y++)
  376. {
  377. presetOutputs->y_mesh[x][y] -= presetOutputs->dy_mesh[x][y];
  378. }
  379. }
  380. }
  381. void Renderer::reset(int w, int h)
  382. {
  383. CSectionLock lock(&_renderer_lock);
  384. this->aspect=(float)h / (float)w;
  385. this -> vw = w;
  386. this -> vh = h;
  387. glShadeModel( GL_SMOOTH);
  388. glCullFace( GL_BACK );
  389. //glFrontFace( GL_CCW );
  390. glClearColor( 0, 0, 0, 0 );
  391. glViewport( 0, 0, w, h );
  392. glMatrixMode(GL_TEXTURE);
  393. glLoadIdentity();
  394. glMatrixMode(GL_PROJECTION);
  395. glLoadIdentity();
  396. glMatrixMode(GL_MODELVIEW);
  397. glLoadIdentity();
  398. #ifndef USE_GLES1
  399. glDrawBuffer(GL_BACK);
  400. glReadBuffer(GL_BACK);
  401. #endif
  402. glEnable(GL_BLEND);
  403. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  404. glEnable( GL_LINE_SMOOTH );
  405. // glEnable(GL_POINT_SMOOTH);
  406. glClear(GL_COLOR_BUFFER_BIT);
  407. #ifndef USE_GLES1
  408. glLineStipple(2, 0xAAAA);
  409. #endif
  410. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  411. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  412. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  413. //glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
  414. //glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
  415. //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  416. if (!this->renderTarget->useFBO)
  417. {
  418. this->renderTarget->fallbackRescale(w, h);
  419. }
  420. }
  421. void Renderer::draw_custom_waves(PresetOutputs *presetOutputs)
  422. {
  423. int x;
  424. CSectionLock lock(&_renderer_lock);
  425. glPointSize(this->renderTarget->texsize < 512 ? 1 : this->renderTarget->texsize/512);
  426. for (PresetOutputs::cwave_container::const_iterator pos = presetOutputs->customWaves.begin();
  427. pos != presetOutputs->customWaves.end(); ++pos)
  428. {
  429. if( (*pos)->enabled==1)
  430. {
  431. if ( (*pos)->bAdditive==0) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  432. else glBlendFunc(GL_SRC_ALPHA, GL_ONE);
  433. if ( (*pos)->bDrawThick==1)
  434. { glLineWidth(this->renderTarget->texsize < 512 ? 1 : 2*this->renderTarget->texsize/512);
  435. glPointSize(this->renderTarget->texsize < 512 ? 1 : 2*this->renderTarget->texsize/512);
  436. }
  437. beatDetect->pcm->getPCM( (*pos)->value1, (*pos)->samples, 0, (*pos)->bSpectrum, (*pos)->smoothing, 0);
  438. beatDetect->pcm->getPCM( (*pos)->value2, (*pos)->samples, 1, (*pos)->bSpectrum, (*pos)->smoothing, 0);
  439. // printf("%f\n",pcmL[0]);
  440. float mult= (*pos)->scaling*presetOutputs->fWaveScale*( (*pos)->bSpectrum ? 0.015f :1.0f);
  441. for(x=0;x< (*pos)->samples;x++)
  442. { (*pos)->value1[x]*=mult;}
  443. for(x=0;x< (*pos)->samples;x++)
  444. { (*pos)->value2[x]*=mult;}
  445. for(x=0;x< (*pos)->samples;x++)
  446. { (*pos)->sample_mesh[x]=((float)x)/((float)( (*pos)->samples-1));}
  447. // printf("mid inner loop\n");
  448. (*pos)->evalPerPointEqns();
  449. #ifdef _WIN32PC
  450. char buf[1024];
  451. sprintf(buf, "%s: samples = %d\n", __FUNCTION__,(*pos)->samples);
  452. OutputDebugString( buf );
  453. float colors[1024][4];
  454. float points[1024][2];
  455. #else
  456. float colors[(*pos)->samples][4];
  457. float points[(*pos)->samples][2];
  458. #endif
  459. for(x=0;x< (*pos)->samples;x++)
  460. {
  461. colors[x][0] = (*pos)->r_mesh[x];
  462. colors[x][1] = (*pos)->g_mesh[x];
  463. colors[x][2] = (*pos)->b_mesh[x];
  464. colors[x][3] = (*pos)->a_mesh[x];
  465. points[x][0] = (*pos)->x_mesh[x];
  466. points[x][1] = -( (*pos)->y_mesh[x]-1);
  467. }
  468. glEnableClientState(GL_VERTEX_ARRAY);
  469. glEnableClientState(GL_COLOR_ARRAY);
  470. glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  471. glVertexPointer(2,GL_FLOAT,0,points);
  472. glColorPointer(4,GL_FLOAT,0,colors);
  473. if ( (*pos)->bUseDots==1)
  474. glDrawArrays(GL_POINTS,0,(*pos)->samples);
  475. else glDrawArrays(GL_LINE_STRIP,0,(*pos)->samples);
  476. glPointSize(this->renderTarget->texsize < 512 ? 1 : this->renderTarget->texsize/512);
  477. glLineWidth(this->renderTarget->texsize < 512 ? 1 : this->renderTarget->texsize/512);
  478. #ifndef USE_GLES1
  479. glDisable(GL_LINE_STIPPLE);
  480. #endif
  481. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  482. // glPopMatrix();
  483. }
  484. }
  485. }
  486. void Renderer::draw_shapes(PresetOutputs *presetOutputs)
  487. {
  488. CSectionLock lock(&_renderer_lock);
  489. float radius;
  490. float xval, yval;
  491. float t;
  492. float aspect=this->aspect;
  493. for (PresetOutputs::cshape_container::const_iterator pos = presetOutputs->customShapes.begin();
  494. pos != presetOutputs->customShapes.end(); ++pos)
  495. {
  496. if( (*pos)->enabled==1)
  497. {
  498. // printf("drawing shape %f\n", (*pos)->ang);
  499. (*pos)->y=-(( (*pos)->y)-1);
  500. radius=.5;
  501. (*pos)->radius= (*pos)->radius*(.707*.707*.707*1.04);
  502. //Additive Drawing or Overwrite
  503. if ( (*pos)->additive==0) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  504. else glBlendFunc(GL_SRC_ALPHA, GL_ONE);
  505. xval= (*pos)->x;
  506. yval= (*pos)->y;
  507. if ( (*pos)->textured)
  508. {
  509. if ((*pos)->getImageUrl() !="")
  510. {
  511. GLuint tex = textureManager->getTexture((*pos)->getImageUrl());
  512. if (tex != 0)
  513. {
  514. glBindTexture(GL_TEXTURE_2D, tex);
  515. aspect=1.0;
  516. }
  517. }
  518. glMatrixMode(GL_TEXTURE);
  519. glPushMatrix();
  520. glLoadIdentity();
  521. glEnable(GL_TEXTURE_2D);
  522. glEnableClientState(GL_VERTEX_ARRAY);
  523. glEnableClientState(GL_COLOR_ARRAY);
  524. glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  525. #ifdef _WIN32PC
  526. char buf[1024];
  527. sprintf(buf, "%s: sides = %d\n", __FUNCTION__,(*pos)->sides);
  528. OutputDebugString( buf );
  529. float colors[1024][4];
  530. float tex[1024][2];
  531. float points[1024][2];
  532. #else
  533. float colors[(*pos)->sides+2][4];
  534. float tex[(*pos)->sides+2][2];
  535. float points[(*pos)->sides+2][2];
  536. #endif
  537. //Define the center point of the shape
  538. colors[0][0] = (*pos)->r;
  539. colors[0][1] = (*pos)->g;
  540. colors[0][2] = (*pos)->b;
  541. colors[0][3] = (*pos)->a;
  542. tex[0][0] = 0.5;
  543. tex[0][1] = 0.5;
  544. points[0][0] = xval;
  545. points[0][1] = yval;
  546. for ( int i=1;i< (*pos)->sides+2;i++)
  547. {
  548. colors[i][0]= (*pos)->r2;
  549. colors[i][1]=(*pos)->g2;
  550. colors[i][2]=(*pos)->b2;
  551. colors[i][3]=(*pos)->a2;
  552. t = (i-1)/(float) (*pos)->sides;
  553. tex[i][0] =0.5f + 0.5f*cosf(t*3.1415927f*2 + (*pos)->tex_ang + 3.1415927f*0.25f)*(this->correction ? aspect : 1.0)/ (*pos)->tex_zoom;
  554. tex[i][1] = 0.5f + 0.5f*sinf(t*3.1415927f*2 + (*pos)->tex_ang + 3.1415927f*0.25f)/ (*pos)->tex_zoom;
  555. points[i][0]=(*pos)->radius*cosf(t*3.1415927f*2 + (*pos)->ang + 3.1415927f*0.25f)*(this->correction ? aspect : 1.0)+xval;
  556. points[i][1]=(*pos)->radius*sinf(t*3.1415927f*2 + (*pos)->ang + 3.1415927f*0.25f)+yval;
  557. }
  558. glVertexPointer(2,GL_FLOAT,0,points);
  559. glColorPointer(4,GL_FLOAT,0,colors);
  560. glTexCoordPointer(2,GL_FLOAT,0,tex);
  561. glDrawArrays(GL_TRIANGLE_FAN,0,(*pos)->sides+2);
  562. glDisable(GL_TEXTURE_2D);
  563. glPopMatrix();
  564. glMatrixMode(GL_MODELVIEW);
  565. //Reset Texture state since we might have changed it
  566. if(this->renderTarget->useFBO)
  567. {
  568. glBindTexture( GL_TEXTURE_2D, renderTarget->textureID[1] );
  569. }
  570. else
  571. {
  572. glBindTexture( GL_TEXTURE_2D, renderTarget->textureID[0] );
  573. }
  574. }
  575. else
  576. {//Untextured (use color values)
  577. glEnableClientState(GL_VERTEX_ARRAY);
  578. glEnableClientState(GL_COLOR_ARRAY);
  579. glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  580. #ifdef _WIN32PC
  581. char buf[1024];
  582. sprintf(buf, "%s: sides = %d\n", __FUNCTION__,(*pos)->sides+2);
  583. OutputDebugString( buf );
  584. float colors[1024][4];
  585. float points[1024][2];
  586. #else
  587. float colors[(*pos)->sides+2][4];
  588. float points[(*pos)->sides+2][2];
  589. #endif
  590. //Define the center point of the shape
  591. colors[0][0]=(*pos)->r;
  592. colors[0][1]=(*pos)->g;
  593. colors[0][2]=(*pos)->b;
  594. colors[0][3]=(*pos)->a;
  595. points[0][0]=xval;
  596. points[0][1]=yval;
  597. for ( int i=1;i< (*pos)->sides+2;i++)
  598. {
  599. colors[i][0]=(*pos)->r2;
  600. colors[i][1]=(*pos)->g2;
  601. colors[i][2]=(*pos)->b2;
  602. colors[i][3]=(*pos)->a2;
  603. t = (i-1)/(float) (*pos)->sides;
  604. points[i][0]=(*pos)->radius*cosf(t*3.1415927f*2 + (*pos)->ang + 3.1415927f*0.25f)*(this->correction ? aspect : 1.0)+xval;
  605. points[i][1]=(*pos)->radius*sinf(t*3.1415927f*2 + (*pos)->ang + 3.1415927f*0.25f)+yval;
  606. }
  607. glVertexPointer(2,GL_FLOAT,0,points);
  608. glColorPointer(4,GL_FLOAT,0,colors);
  609. glDrawArrays(GL_TRIANGLE_FAN,0,(*pos)->sides+2);
  610. //draw first n-1 triangular pieces
  611. }
  612. if (presetOutputs->bWaveThick==1) glLineWidth(this->renderTarget->texsize < 512 ? 1 : 2*this->renderTarget->texsize/512);
  613. glEnableClientState(GL_VERTEX_ARRAY);
  614. glDisableClientState(GL_COLOR_ARRAY);
  615. #ifdef _WIN32PC
  616. char buf[1024];
  617. sprintf(buf, "%s: sides = %d\n", __FUNCTION__,(*pos)->sides+1);
  618. OutputDebugString( buf );
  619. float points[1024][2];
  620. #else
  621. float points[(*pos)->sides+1][2];
  622. #endif
  623. glColor4f( (*pos)->border_r, (*pos)->border_g, (*pos)->border_b, (*pos)->border_a);
  624. for ( int i=0;i< (*pos)->sides;i++)
  625. {
  626. t = (i-1)/(float) (*pos)->sides;
  627. points[i][0]= (*pos)->radius*cosf(t*3.1415927f*2 + (*pos)->ang + 3.1415927f*0.25f)*(this->correction ? aspect : 1.0)+xval;
  628. points[i][1]= (*pos)->radius*sinf(t*3.1415927f*2 + (*pos)->ang + 3.1415927f*0.25f)+yval;
  629. }
  630. glVertexPointer(2,GL_FLOAT,0,points);
  631. glDrawArrays(GL_LINE_LOOP,0,(*pos)->sides);
  632. if (presetOutputs->bWaveThick==1) glLineWidth(this->renderTarget->texsize < 512 ? 1 : this->renderTarget->texsize/512);
  633. }
  634. }
  635. }
  636. void Renderer::WaveformMath(PresetOutputs *presetOutputs, PresetInputs *presetInputs, bool isSmoothing)
  637. {
  638. int x;
  639. float r, theta;
  640. float offset, scale;
  641. float wave_x_temp=0;
  642. float wave_y_temp=0;
  643. float cos_rot;
  644. float sin_rot;
  645. CSectionLock lock(&_renderer_lock);
  646. offset=presetOutputs->wave_x-.5;
  647. scale=505.0/512.0;
  648. presetOutputs->two_waves = false;
  649. presetOutputs->draw_wave_as_loop = false;
  650. switch(presetOutputs->nWaveMode)
  651. {
  652. case 0:
  653. {
  654. presetOutputs->draw_wave_as_loop = true;
  655. presetOutputs->wave_rot = 0;
  656. presetOutputs->wave_scale =1.0;
  657. presetOutputs->wave_y=-1*(presetOutputs->wave_y-1.0);
  658. presetOutputs->wave_samples = isSmoothing ? 512-32 : beatDetect->pcm->numsamples;
  659. float inv_nverts_minus_one = 1.0f/(float)(presetOutputs->wave_samples);
  660. float last_value = beatDetect->pcm->pcmdataR[presetOutputs->wave_samples-1]+beatDetect->pcm->pcmdataL[presetOutputs->wave_samples-1];
  661. float first_value = beatDetect->pcm->pcmdataR[0]+beatDetect->pcm->pcmdataL[0];
  662. float offset = first_value-last_value;
  663. for ( x=0;x<presetOutputs->wave_samples;x++)
  664. {
  665. float value = beatDetect->pcm->pcmdataR[x]+beatDetect->pcm->pcmdataL[x];
  666. value += offset * (x/(float)presetOutputs->wave_samples);
  667. r=(0.5 + 0.4f*.12*value*presetOutputs->fWaveScale + presetOutputs->wave_mystery)*.5;
  668. theta=(x)*inv_nverts_minus_one*6.28f + presetInputs->time*0.2f;
  669. presetOutputs->wavearray[x][0]=(r*cos(theta)*(this->correction ? this->aspect : 1.0)+presetOutputs->wave_x);
  670. presetOutputs->wavearray[x][1]=(r*sin(theta)+presetOutputs->wave_y);
  671. }
  672. }
  673. break;
  674. case 1://circularly moving waveform
  675. presetOutputs->wave_rot = 0;
  676. presetOutputs->wave_scale = this->vh/(float)this->vw;
  677. presetOutputs->wave_y=-1*(presetOutputs->wave_y-1.0);
  678. presetOutputs->wave_samples = 512-32;
  679. for ( x=0;x<(512-32);x++)
  680. {
  681. theta=beatDetect->pcm->pcmdataL[x+32]*0.06*presetOutputs->fWaveScale * 1.57 + presetInputs->time*2.3;
  682. r=(0.53 + 0.43*beatDetect->pcm->pcmdataR[x]*0.12*presetOutputs->fWaveScale+ presetOutputs->wave_mystery)*.5;
  683. presetOutputs->wavearray[x][0]=(r*cos(theta)*(this->correction ? this->aspect : 1.0)+presetOutputs->wave_x);
  684. presetOutputs->wavearray[x][1]=(r*sin(theta)+presetOutputs->wave_y);
  685. }
  686. break;
  687. case 2://EXPERIMENTAL
  688. presetOutputs->wave_y=-1*(presetOutputs->wave_y-1.0);
  689. presetOutputs->wave_rot = 0;
  690. presetOutputs->wave_scale =1.0;
  691. presetOutputs->wave_samples = 512-32;
  692. for (x=0; x<512-32; x++)
  693. {
  694. presetOutputs->wavearray[x][0]=(beatDetect->pcm->pcmdataR[x]*presetOutputs->fWaveScale*0.5*(this->correction ? this->aspect : 1.0) + presetOutputs->wave_x);
  695. presetOutputs->wavearray[x][1]=(beatDetect->pcm->pcmdataL[x+32]*presetOutputs->fWaveScale*0.5 + presetOutputs->wave_y);
  696. }
  697. break;
  698. case 3://EXPERIMENTAL
  699. presetOutputs->wave_y=-1*(presetOutputs->wave_y-1.0);
  700. presetOutputs->wave_rot = 0;
  701. presetOutputs->wave_scale =1.0;
  702. presetOutputs->wave_samples = 512-32;
  703. for (x=0; x<512-32; x++)
  704. {
  705. presetOutputs->wavearray[x][0]=(beatDetect->pcm->pcmdataR[x] * presetOutputs->fWaveScale*0.5 + presetOutputs->wave_x);
  706. presetOutputs->wavearray[x][1]=( (beatDetect->pcm->pcmdataL[x+32]*presetOutputs->fWaveScale*0.5 + presetOutputs->wave_y));
  707. }
  708. break;
  709. case 4://single x-axis derivative waveform
  710. {
  711. presetOutputs->wave_rot =-presetOutputs->wave_mystery*90;
  712. presetOutputs->wave_scale=1.0;
  713. presetOutputs->wave_y=-1*(presetOutputs->wave_y-1.0);
  714. float w1 = 0.45f + 0.5f*(presetOutputs->wave_mystery*0.5f + 0.5f);
  715. float w2 = 1.0f - w1;
  716. float xx[512], yy[512];
  717. presetOutputs->wave_samples = 512-32;
  718. for (int i=0; i<512-32; i++)
  719. {
  720. xx[i] = -1.0f + 2.0f*(i/(512.0-32.0)) + presetOutputs->wave_x;
  721. yy[i] =0.4* beatDetect->pcm->pcmdataL[i]*0.47f*presetOutputs->fWaveScale + presetOutputs->wave_y;
  722. xx[i] += 0.4*beatDetect->pcm->pcmdataR[i]*0.44f*presetOutputs->fWaveScale;
  723. if (i>1)
  724. {
  725. xx[i] = xx[i]*w2 + w1*(xx[i-1]*2.0f - xx[i-2]);
  726. yy[i] = yy[i]*w2 + w1*(yy[i-1]*2.0f - yy[i-2]);
  727. }
  728. presetOutputs->wavearray[i][0]=xx[i];
  729. presetOutputs->wavearray[i][1]=yy[i];
  730. } }
  731. break;
  732. case 5://EXPERIMENTAL
  733. presetOutputs->wave_rot = 0;
  734. presetOutputs->wave_scale =1.0;
  735. presetOutputs->wave_y=-1*(presetOutputs->wave_y-1.0);
  736. cos_rot = cosf(presetInputs->time*0.3f);
  737. sin_rot = sinf(presetInputs->time*0.3f);
  738. presetOutputs->wave_samples = 512-32;
  739. for (x=0; x<512-32; x++)
  740. {
  741. float x0 = (beatDetect->pcm->pcmdataR[x]*beatDetect->pcm->pcmdataL[x+32] + beatDetect->pcm->pcmdataL[x+32]*beatDetect->pcm->pcmdataR[x]);
  742. float y0 = (beatDetect->pcm->pcmdataR[x]*beatDetect->pcm->pcmdataR[x] - beatDetect->pcm->pcmdataL[x+32]*beatDetect->pcm->pcmdataL[x+32]);
  743. presetOutputs->wavearray[x][0]=((x0*cos_rot - y0*sin_rot)*presetOutputs->fWaveScale*0.5*(this->correction ? this->aspect : 1.0) + presetOutputs->wave_x);
  744. presetOutputs->wavearray[x][1]=( (x0*sin_rot + y0*cos_rot)*presetOutputs->fWaveScale*0.5 + presetOutputs->wave_y);
  745. }
  746. break;
  747. case 6://single waveform
  748. wave_x_temp=-2*0.4142*(fabs(fabs(presetOutputs->wave_mystery)-.5)-.5);
  749. presetOutputs->wave_rot = -presetOutputs->wave_mystery*90;
  750. presetOutputs->wave_scale =1.0+wave_x_temp;
  751. wave_x_temp=-1*(presetOutputs->wave_x-1.0);
  752. presetOutputs->wave_samples = isSmoothing ? 512-32 : beatDetect->pcm->numsamples;
  753. for ( x=0;x< presetOutputs->wave_samples;x++)
  754. {
  755. presetOutputs->wavearray[x][0]=x/(float) presetOutputs->wave_samples;
  756. presetOutputs->wavearray[x][1]=beatDetect->pcm->pcmdataR[x]*.04*presetOutputs->fWaveScale+wave_x_temp;
  757. }
  758. // printf("%f %f\n",renderTarget->texsize*wave_y_temp,wave_y_temp);
  759. break;
  760. case 7://dual waveforms
  761. wave_x_temp=-2*0.4142*(fabs(fabs(presetOutputs->wave_mystery)-.5)-.5);
  762. presetOutputs->wave_rot = -presetOutputs->wave_mystery*90;
  763. presetOutputs->wave_scale =1.0+wave_x_temp;
  764. presetOutputs->wave_samples = isSmoothing ? 512-32 : beatDetect->pcm->numsamples;
  765. presetOutputs->two_waves = true;
  766. double y_adj = presetOutputs->wave_y*presetOutputs->wave_y*.5;
  767. wave_y_temp=-1*(presetOutputs->wave_x-1);
  768. for ( x=0;x< presetOutputs->wave_samples ;x++)
  769. {
  770. presetOutputs->wavearray[x][0]=x/((float) presetOutputs->wave_samples);
  771. presetOutputs->wavearray[x][1]= beatDetect->pcm->pcmdataL[x]*.04*presetOutputs->fWaveScale+(wave_y_temp+y_adj);
  772. }
  773. for ( x=0;x< presetOutputs->wave_samples;x++)
  774. {
  775. presetOutputs->wavearray2[x][0]=x/((float) presetOutputs->wave_samples);
  776. presetOutputs->wavearray2[x][1]=beatDetect->pcm->pcmdataR[x]*.04*presetOutputs->fWaveScale+(wave_y_temp-y_adj);
  777. }
  778. break;
  779. }
  780. }
  781. void Renderer::draw_waveform(PresetOutputs * presetOutputs)
  782. {
  783. CSectionLock lock(&_renderer_lock);
  784. glMatrixMode( GL_MODELVIEW );
  785. glPushMatrix();
  786. glLoadIdentity();
  787. modulate_opacity_by_volume(presetOutputs);
  788. maximize_colors(presetOutputs);
  789. #ifndef USE_GLES1
  790. if(presetOutputs->bWaveDots==1) glEnable(GL_LINE_STIPPLE);
  791. #endif
  792. //Thick wave drawing
  793. if (presetOutputs->bWaveThick==1) glLineWidth( (this->renderTarget->texsize < 512 ) ? 2 : 2*this->renderTarget->texsize/512);
  794. else glLineWidth( (this->renderTarget->texsize < 512 ) ? 1 : this->renderTarget->texsize/512);
  795. //Additive wave drawing (vice overwrite)
  796. if (presetOutputs->bAdditiveWaves==0) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  797. else glBlendFunc(GL_SRC_ALPHA, GL_ONE);
  798. glTranslatef(.5, .5, 0);
  799. glRotatef(presetOutputs->wave_rot, 0, 0, 1);
  800. glScalef(presetOutputs->wave_scale, 1.0, 1.0);
  801. glTranslatef(-.5, -.5, 0);
  802. glEnableClientState(GL_VERTEX_ARRAY);
  803. glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  804. glDisableClientState(GL_COLOR_ARRAY);
  805. glVertexPointer(2,GL_FLOAT,0,presetOutputs->wavearray);
  806. if (presetOutputs->draw_wave_as_loop)
  807. glDrawArrays(GL_LINE_LOOP,0,presetOutputs->wave_samples);
  808. else
  809. glDrawArrays(GL_LINE_STRIP,0,presetOutputs->wave_samples);
  810. if (presetOutputs->two_waves)
  811. {
  812. glVertexPointer(2,GL_FLOAT,0,presetOutputs->wavearray2);
  813. if (presetOutputs->draw_wave_as_loop)
  814. glDrawArrays(GL_LINE_LOOP,0,presetOutputs->wave_samples);
  815. else
  816. glDrawArrays(GL_LINE_STRIP,0,presetOutputs->wave_samples);
  817. }
  818. #ifndef USE_GLES1
  819. if(presetOutputs->bWaveDots==1) glDisable(GL_LINE_STIPPLE);
  820. #endif
  821. glPopMatrix();
  822. }
  823. void Renderer::maximize_colors(PresetOutputs *presetOutputs)
  824. {
  825. float wave_r_switch=0, wave_g_switch=0, wave_b_switch=0;
  826. CSectionLock lock(&_renderer_lock);
  827. //wave color brightening
  828. //
  829. //forces max color value to 1.0 and scales
  830. // the rest accordingly
  831. if(presetOutputs->nWaveMode==2 || presetOutputs->nWaveMode==5)
  832. {
  833. switch(this->renderTarget->texsize)
  834. {
  835. case 256: presetOutputs->wave_o *= 0.07f; break;
  836. case 512: presetOutputs->wave_o *= 0.09f; break;
  837. case 1024: presetOutputs->wave_o *= 0.11f; break;
  838. case 2048: presetOutputs->wave_o *= 0.13f; break;
  839. }
  840. }
  841. else if(presetOutputs->nWaveMode==3)
  842. {
  843. switch(this->renderTarget->texsize)
  844. {
  845. case 256: presetOutputs->wave_o *= 0.075f; break;
  846. case 512: presetOutputs->wave_o *= 0.15f; break;
  847. case 1024: presetOutputs->wave_o *= 0.22f; break;
  848. case 2048: presetOutputs->wave_o *= 0.33f; break;
  849. }
  850. presetOutputs->wave_o*=1.3f;
  851. presetOutputs->wave_o*=powf(beatDetect->treb , 2.0f);
  852. }
  853. if (presetOutputs->bMaximizeWaveColor==1)
  854. {
  855. if(presetOutputs->wave_r>=presetOutputs->wave_g && presetOutputs->wave_r>=presetOutputs->wave_b) //red brightest
  856. {
  857. wave_b_switch=presetOutputs->wave_b*(1/presetOutputs->wave_r);
  858. wave_g_switch=presetOutputs->wave_g*(1/presetOutputs->wave_r);
  859. wave_r_switch=1.0;
  860. }
  861. else if (presetOutputs->wave_b>=presetOutputs->wave_g && presetOutputs->wave_b>=presetOutputs->wave_r) //blue brightest
  862. {
  863. wave_r_switch=presetOutputs->wave_r*(1/presetOutputs->wave_b);
  864. wave_g_switch=presetOutputs->wave_g*(1/presetOutputs->wave_b);
  865. wave_b_switch=1.0;
  866. }
  867. else if (presetOutputs->wave_g>=presetOutputs->wave_b && presetOutputs->wave_g>=presetOutputs->wave_r) //green brightest
  868. {
  869. wave_b_switch=presetOutputs->wave_b*(1/presetOutputs->wave_g);
  870. wave_r_switch=presetOutputs->wave_r*(1/presetOutputs->wave_g);
  871. wave_g_switch=1.0;
  872. }
  873. glColor4f(wave_r_switch, wave_g_switch, wave_b_switch, presetOutputs->wave_o);
  874. }
  875. else
  876. {
  877. glColor4f(presetOutputs->wave_r, presetOutputs->wave_g, presetOutputs->wave_b, presetOutputs->wave_o);
  878. }
  879. }
  880. void Renderer::darken_center()
  881. {
  882. CSectionLock lock(&_renderer_lock);
  883. float unit=0.05f;
  884. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  885. float colors[6][4] = {{0, 0, 0, 3.0f/32.0f},
  886. {0, 0, 0, 0},
  887. {0, 0, 0, 0},
  888. {0, 0, 0, 0},
  889. {0, 0, 0, 0},
  890. {0, 0, 0, 0}};
  891. float points[6][2] = {{ 0.5, 0.5},
  892. { 0.45, 0.5},
  893. { 0.5, 0.45},
  894. { 0.55, 0.5},
  895. { 0.5, 0.55},
  896. { 0.45, 0.5}};
  897. glEnableClientState(GL_VERTEX_ARRAY);
  898. glEnableClientState(GL_COLOR_ARRAY);
  899. glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  900. glVertexPointer(2,GL_FLOAT,0,points);
  901. glColorPointer(4,GL_FLOAT,0,colors);
  902. glDrawArrays(GL_TRIANGLE_FAN,0,6);
  903. }
  904. void Renderer::modulate_opacity_by_volume(PresetOutputs *presetOutputs)
  905. {
  906. //modulate volume by opacity
  907. //
  908. //set an upper and lower bound and linearly
  909. //calculate the opacity from 0=lower to 1=upper
  910. //based on current volume
  911. CSectionLock lock(&_renderer_lock);
  912. if (presetOutputs->bModWaveAlphaByVolume==1)
  913. {if (beatDetect->vol<=presetOutputs->fModWaveAlphaStart) presetOutputs->wave_o=0.0;
  914. else if (beatDetect->vol>=presetOutputs->fModWaveAlphaEnd) presetOutputs->wave_o=presetOutputs->fWaveAlpha;
  915. else presetOutputs->wave_o=presetOutputs->fWaveAlpha*((beatDetect->vol-presetOutputs->fModWaveAlphaStart)/(presetOutputs->fModWaveAlphaEnd-presetOutputs->fModWaveAlphaStart));}
  916. else presetOutputs->wave_o=presetOutputs->fWaveAlpha;
  917. }
  918. void Renderer::draw_motion_vectors(PresetOutputs *presetOutputs)
  919. {
  920. CSectionLock lock(&_renderer_lock);
  921. glEnableClientState(GL_VERTEX_ARRAY);
  922. glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  923. glDisableClientState(GL_COLOR_ARRAY);
  924. float offsetx=presetOutputs->mv_dx, intervalx=1.0/(float)presetOutputs->mv_x;
  925. float offsety=presetOutputs->mv_dy, intervaly=1.0/(float)presetOutputs->mv_y;
  926. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  927. glPointSize(presetOutputs->mv_l);
  928. glColor4f(presetOutputs->mv_r, presetOutputs->mv_g, presetOutputs->mv_b, presetOutputs->mv_a);
  929. int numx = static_cast<int>(presetOutputs->mv_x);
  930. int numy = static_cast<int>(presetOutputs->mv_y);
  931. if (numx + numy < 600)
  932. {
  933. int size = numx * numy;
  934. #ifdef _WIN32PC
  935. // guessed value. solved in current projectM svn
  936. char buf[1024];
  937. sprintf(buf, "%s: size = %d\n", __FUNCTION__,size);
  938. OutputDebugString( buf );
  939. float points[1024][2];
  940. #else
  941. float points[size][2];
  942. #endif
  943. for (int x=0;x<numx;x++)
  944. {
  945. for(int y=0;y<numy;y++)
  946. {
  947. float lx, ly, lz;
  948. lx = offsetx+x*intervalx;
  949. ly = offsety+y*intervaly;
  950. points[(x * numy) + y][0] = lx;
  951. points[(x * numy) + y][1] = ly;
  952. }
  953. }
  954. glVertexPointer(2,GL_FLOAT,0,points);
  955. glDrawArrays(GL_POINTS,0,size);
  956. }
  957. }
  958. GLuint Renderer::initRenderToTexture()
  959. {
  960. return renderTarget->initRenderToTexture();
  961. }
  962. void Renderer::draw_borders(PresetOutputs *presetOutputs)
  963. {
  964. CSectionLock lock(&_renderer_lock);
  965. glEnableClientState(GL_VERTEX_ARRAY);
  966. glDisableClientState(GL_COLOR_ARRAY);
  967. glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  968. //Draw Borders
  969. float of=presetOutputs->ob_size*.5;
  970. float iff=presetOutputs->ib_size*.5;
  971. float texof=1.0-of;
  972. //no additive drawing for borders
  973. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  974. glColor4f(presetOutputs->ob_r, presetOutputs->ob_g, presetOutputs->ob_b, presetOutputs->ob_a);
  975. float pointsA[4][2] = {{0,0},{0,1},{of,0},{of,1}};
  976. glVertexPointer(2,GL_FLOAT,0,pointsA);
  977. glDrawArrays(GL_TRIANGLE_STRIP,0,4);
  978. float pointsB[4][2] = {{of,0},{of,of},{texof,0},{texof,of}};
  979. glVertexPointer(2,GL_FLOAT,0,pointsB);
  980. glDrawArrays(GL_TRIANGLE_STRIP,0,4);
  981. float pointsC[4][2] = {{texof,0},{texof,1},{1,0},{1,1}};
  982. glVertexPointer(2,GL_FLOAT,0,pointsC);
  983. glDrawArrays(GL_TRIANGLE_STRIP,0,4);
  984. float pointsD[4][2] = {{of,1},{of,texof},{texof,1},{texof,texof}};
  985. glVertexPointer(2,GL_FLOAT,0,pointsD);
  986. glDrawArrays(GL_TRIANGLE_STRIP,0,4);
  987. glColor4f(presetOutputs->ib_r, presetOutputs->ib_g, presetOutputs->ib_b, presetOutputs->ib_a);
  988. glRectd(of, of, of+iff, texof);
  989. glRectd(of+iff, of, texof-iff, of+iff);
  990. glRectd(texof-iff, of, texof, texof);
  991. glRectd(of+iff, texof, texof-iff, texof-iff);
  992. float pointsE[4][2] = {{of,of},{of,texof},{of+iff,of},{of+iff,texof}};
  993. glVertexPointer(2,GL_FLOAT,0,pointsE);
  994. glDrawArrays(GL_TRIANGLE_STRIP,0,4);
  995. float pointsF[4][2] = {{of+iff,of},{of+iff,of+iff},{texof-iff,of},{texof-iff,of+iff}};
  996. glVertexPointer(2,GL_FLOAT,0,pointsF);
  997. glDrawArrays(GL_TRIANGLE_STRIP,0,4);
  998. float pointsG[4][2] = {{texof-iff,of},{texof-iff,texof},{texof,of},{texof,texof}};
  999. glVertexPointer(2,GL_FLOAT,0,pointsG);
  1000. glDrawArrays(GL_TRIANGLE_STRIP,0,4);
  1001. float pointsH[4][2] = {{of+iff,texof},{of+iff,texof-iff},{texof-iff,texof},{texof-iff,texof-iff}};
  1002. glVertexPointer(2,GL_FLOAT,0,pointsH);
  1003. glDrawArrays(GL_TRIANGLE_STRIP,0,4);
  1004. }
  1005. void Renderer::draw_title_to_texture()
  1006. {
  1007. CSectionLock lock(&_renderer_lock);
  1008. #ifdef USE_FTGL
  1009. if (this->drawtitle>100)
  1010. {
  1011. draw_title_to_screen(true);
  1012. this->drawtitle=0;
  1013. }
  1014. #endif /** USE_FTGL */
  1015. }
  1016. /*
  1017. void setUpLighting()
  1018. {
  1019. CSectionLock lock(&_renderer_lock);
  1020. // Set up lighting.
  1021. float light1_ambient[4] = { 1.0, 1.0, 1.0, 1.0 };
  1022. float light1_diffuse[4] = { 1.0, 0.9, 0.9, 1.0 };
  1023. float light1_specular[4] = { 1.0, 0.7, 0.7, 1.0 };
  1024. float light1_position[4] = { -1.0, 1.0, 1.0, 0.0 };
  1025. glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient);
  1026. glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse);
  1027. glLightfv(GL_LIGHT1, GL_SPECULAR, light1_specular);
  1028. glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
  1029. //glEnable(GL_LIGHT1);
  1030. float light2_ambient[4] = { 0.2, 0.2, 0.2, 1.0 };
  1031. float light2_diffuse[4] = { 0.9, 0.9, 0.9, 1.0 };
  1032. float light2_specular[4] = { 0.7, 0.7, 0.7, 1.0 };
  1033. float light2_position[4] = { 0.0, -1.0, 1.0, 0.0 };
  1034. glLightfv(GL_LIGHT2, GL_AMBIENT, light2_ambient);
  1035. glLightfv(GL_LIGHT2, GL_DIFFUSE, light2_diffuse);
  1036. glLightfv(GL_LIGHT2, GL_SPECULAR, light2_specular);
  1037. glLightfv(GL_LIGHT2, GL_POSITION, light2_position);
  1038. glEnable(GL_LIGHT2);
  1039. float front_emission[4] = { 0.3, 0.2, 0.1, 0.0 };
  1040. float front_ambient[4] = { 0.2, 0.2, 0.2, 0.0 };
  1041. float front_diffuse[4] = { 0.95, 0.95, 0.8, 0.0 };
  1042. float front_specular[4] = { 0.6, 0.6, 0.6, 0.0 };
  1043. glMaterialfv(GL_FRONT, GL_EMISSION, front_emission);
  1044. glMaterialfv(GL_FRONT, GL_AMBIENT, front_ambient);
  1045. glMaterialfv(GL_FRONT, GL_DIFFUSE, front_diffuse);
  1046. glMaterialfv(GL_FRONT, GL_SPECULAR, front_specular);
  1047. glMaterialf(GL_FRONT, GL_SHININESS, 16.0);
  1048. glColor4fv(front_diffuse);
  1049. glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
  1050. glColorMaterial(GL_FRONT, GL_DIFFUSE);
  1051. glEnable(GL_COLOR_MATERIAL);
  1052. glEnable(GL_LIGHTING);
  1053. }
  1054. */
  1055. float title_y;
  1056. void Renderer::draw_title_to_screen(bool flip)
  1057. {
  1058. CSectionLock lock(&_renderer_lock);
  1059. #ifdef USE_FTGL
  1060. if(this->drawtitle>0)
  1061. {
  1062. //setUpLighting();
  1063. //glEnable(GL_POLYGON_SMOOTH);
  1064. //glEnable( GL_CULL_FACE);
  1065. glEnable(GL_DEPTH_TEST);
  1066. glClear(GL_DEPTH_BUFFER_BIT);
  1067. int draw;
  1068. if (drawtitle>=80) draw = 80;
  1069. else draw = drawtitle;
  1070. float easein = ((80-draw)*.0125);
  1071. float easein2 = easein * easein;
  1072. if(drawtitle==1)
  1073. {
  1074. title_y = (float)rand()/RAND_MAX;
  1075. title_y *= 2;
  1076. title_y -= 1;
  1077. title_y *= .6;
  1078. }
  1079. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1080. //glBlendFunc(GL_SRC_ALPHA_SATURATE,GL_ONE);
  1081. glColor4f(1.0, 1.0, 1.0, 1.0);
  1082. glMatrixMode(GL_PROJECTION);
  1083. glPushMatrix();
  1084. glLoadIdentity();
  1085. glFrustum(-1, 1, -1 * (float)vh/(float)vw, 1 *(float)vh/(float)vw, 1, 1000);
  1086. if (flip) glScalef(1, -1, 1);
  1087. glMatrixMode(GL_MODELVIEW);
  1088. glPushMatrix();
  1089. glLoadIdentity();
  1090. glTranslatef(-850, title_y * 850 *vh/vw , easein2*900-900);
  1091. glRotatef(easein2*360, 1, 0, 0);
  1092. poly_font->Render(this->title.c_str() );
  1093. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1094. this->drawtitle++;
  1095. glPopMatrix();
  1096. glMatrixMode(GL_PROJECTION);
  1097. glPopMatrix();
  1098. glMatrixMode(GL_MODELVIEW);
  1099. glDisable( GL_CULL_FACE);
  1100. glDisable( GL_DEPTH_TEST);
  1101. glDisable(GL_COLOR_MATERIAL);
  1102. glDisable(GL_LIGHTING);
  1103. glDisable(GL_POLYGON_SMOOTH);
  1104. }
  1105. #endif /** USE_FTGL */
  1106. }
  1107. void Renderer::draw_title()
  1108. {
  1109. #ifdef USE_FTGL
  1110. CSectionLock lock(&_renderer_lock);
  1111. //glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
  1112. glColor4f(1.0, 1.0, 1.0, 1.0);
  1113. // glPushMatrix();
  1114. // glTranslatef(this->vw*.001,this->vh*.03, -1);
  1115. // glScalef(this->vw*.015,this->vh*.025,0);
  1116. glRasterPos2f(0.01, 0.05);
  1117. title_font->FaceSize( (unsigned)(20*(this->vh/512.0)));
  1118. title_font->Render(this->title.c_str() );
  1119. // glPopMatrix();
  1120. //glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  1121. #endif /** USE_FTGL */
  1122. }
  1123. void Renderer::draw_preset()
  1124. {
  1125. #ifdef USE_FTGL
  1126. CSectionLock lock(&_renderer_lock);
  1127. //glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
  1128. glColor4f(1.0, 1.0, 1.0, 1.0);
  1129. // glPushMatrix();
  1130. //glTranslatef(this->vw*.001,this->vh*-.01, -1);
  1131. //glScalef(this->vw*.003,this->vh*.004,0);
  1132. glRasterPos2f(0.01, 0.01);
  1133. title_font->FaceSize((unsigned)(12*(this->vh/512.0)));
  1134. if(this->noSwitch) title_font->Render("[LOCKED] " );
  1135. title_font->FaceSize((unsigned)(20*(this->vh/512.0)));
  1136. title_font->Render(this->presetName().c_str() );
  1137. //glPopMatrix();
  1138. // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  1139. #endif /** USE_FTGL */
  1140. }
  1141. void Renderer::draw_help( )
  1142. {
  1143. #ifdef USE_FTGL
  1144. CSectionLock lock(&_renderer_lock);
  1145. //glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
  1146. glColor4f(1.0, 1.0, 1.0, 1.0);
  1147. glPushMatrix();
  1148. glTranslatef(0, 1, 0);
  1149. //glScalef(this->vw*.02,this->vh*.02 ,0);
  1150. title_font->FaceSize((unsigned)( 18*(this->vh/512.0)));
  1151. glRasterPos2f(0.01, -0.05);
  1152. title_font->Render("Help");
  1153. glRasterPos2f(0.01, -0.09);
  1154. title_font->Render("----------------------------");
  1155. glRasterPos2f(0.01, -0.13);
  1156. title_font->Render("F1: This help menu");
  1157. glRasterPos2f(0.01, -0.17);
  1158. title_font->Render("F2: Show song title");
  1159. glRasterPos2f(0.01, -0.21);
  1160. title_font->Render("F3: Show preset name");
  1161. glRasterPos2f(0.01, -0.25);
  1162. title_font->Render("F4: Show Rendering Settings");
  1163. glRasterPos2f(0.01, -0.29);
  1164. title_font->Render("F5: Show FPS");
  1165. glRasterPos2f(0.01, -0.35);
  1166. title_font->Render("F: Fullscreen");
  1167. glRasterPos2f(0.01, -0.39);
  1168. title_font->Render("L: Lock/Unlock Preset");
  1169. glRasterPos2f(0.01, -0.43);
  1170. title_font->Render("M: Show Menu");
  1171. glRasterPos2f(0.01, -0.49);
  1172. title_font->Render("R: Random preset");
  1173. glRasterPos2f(0.01, -0.53);
  1174. title_font->Render("N: Next preset");
  1175. glRasterPos2f(0.01, -0.57);
  1176. title_font->Render("P: Previous preset");
  1177. glPopMatrix();
  1178. // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  1179. #endif /** USE_FTGL */
  1180. }
  1181. void Renderer::draw_stats(PresetInputs *presetInputs)
  1182. {
  1183. #ifdef USE_FTGL
  1184. CSectionLock lock(&_renderer_lock);
  1185. char buffer[128];
  1186. float offset= (this->showfps%2 ? -0.05 : 0.0);
  1187. // glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
  1188. glColor4f(1.0, 1.0, 1.0, 1.0);
  1189. glPushMatrix();
  1190. glTranslatef(0.01, 1, 0);
  1191. glRasterPos2f(0, -.05+offset);
  1192. other_font->Render(this->correction ? " aspect: corrected" : " aspect: stretched");
  1193. sprintf( buffer, " (%f)", this->aspect);
  1194. other_font->Render(buffer);
  1195. glRasterPos2f(0, -.09+offset);
  1196. other_font->FaceSize((unsigned)(18*(this->vh/512.0)));
  1197. sprintf( buffer, " texsize: %d", this->renderTarget->texsize);
  1198. other_font->Render(buffer);
  1199. glRasterPos2f(0, -.13+offset);
  1200. sprintf( buffer, "viewport: %d x %d", this->vw, this->vh);
  1201. other_font->Render(buffer);
  1202. glRasterPos2f(0, -.17+offset);
  1203. other_font->Render((this->renderTarget->useFBO ? " FBO: on" : " FBO: off"));
  1204. glRasterPos2f(0, -.21+offset);
  1205. sprintf( buffer, " mesh: %d x %d", presetInputs->gx, presetInputs->gy);
  1206. other_font->Render(buffer);
  1207. glRasterPos2f(0, -.25+offset);
  1208. sprintf( buffer, "textures: %.1fkB", textureManager->getTextureMemorySize() /1000.0f);
  1209. other_font->Render(buffer);
  1210. glPopMatrix();
  1211. // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  1212. #endif /** USE_FTGL */
  1213. }
  1214. void Renderer::draw_fps( float realfps )
  1215. {
  1216. #ifdef USE_FTGL
  1217. CSectionLock lock(&_renderer_lock);
  1218. char bufferfps[20];
  1219. sprintf( bufferfps, "%.1f fps", realfps);
  1220. // glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
  1221. glColor4f(1.0, 1.0, 1.0, 1.0);
  1222. glPushMatrix();
  1223. glTranslatef(0.01, 1, 0);
  1224. glRasterPos2f(0, -0.05);
  1225. title_font->FaceSize((unsigned)(20*(this->vh/512.0)));
  1226. title_font->Render(bufferfps);
  1227. glPopMatrix();
  1228. // glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  1229. #endif /** USE_FTGL */
  1230. }
  1231. //Actually draws the texture to the screen
  1232. //
  1233. //The Video Echo effect is also applied here
  1234. void Renderer::render_texture_to_screen(PresetOutputs *presetOutputs)
  1235. {
  1236. CSectionLock lock(&_renderer_lock);
  1237. int flipx=1, flipy=1;
  1238. glMatrixMode(GL_TEXTURE);
  1239. glLoadIdentity();
  1240. glMatrixMode(GL_MODELVIEW);
  1241. glLoadIdentity();
  1242. //Overwrite anything on the screen
  1243. glBlendFunc(GL_ONE, GL_ZERO);
  1244. glColor4f(1.0, 1.0, 1.0, 1.0f);
  1245. glEnable(GL_TEXTURE_2D);
  1246. float tex[4][2] = {{0, 1},
  1247. {0, 0},
  1248. {1, 0},
  1249. {1, 1}};
  1250. float points[4][2] = {{-0.5, -0.5},
  1251. {-0.5, 0.5},
  1252. { 0.5, 0.5},
  1253. { 0.5, -0.5}};
  1254. glEnableClientState(GL_VERTEX_ARRAY);
  1255. glDisableClientState(GL_COLOR_ARRAY);
  1256. glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  1257. glVertexPointer(2,GL_FLOAT,0,points);
  1258. glTexCoordPointer(2,GL_FLOAT,0,tex);
  1259. glDrawArrays(GL_TRIANGLE_FAN,0,4);
  1260. //Noe Blend the Video Echo
  1261. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1262. glMatrixMode(GL_TEXTURE);
  1263. //draw video echo
  1264. glColor4f(1.0, 1.0, 1.0, presetOutputs->fVideoEchoAlpha);
  1265. glTranslatef(.5, .5, 0);
  1266. glScalef(1.0/presetOutputs->fVideoEchoZoom, 1.0/presetOutputs->fVideoEchoZoom, 1);
  1267. glTranslatef(-.5, -.5, 0);
  1268. switch (((int)presetOutputs->nVideoEchoOrientation))
  1269. {
  1270. case 0: flipx=1;flipy=1;break;
  1271. case 1: flipx=-1;flipy=1;break;
  1272. case 2: flipx=1;flipy=-1;break;
  1273. case 3: flipx=-1;flipy=-1;break;
  1274. default: flipx=1;flipy=1; break;
  1275. }
  1276. float pointsFlip[4][2] = {{-0.5*flipx, -0.5*flipy},
  1277. {-0.5*flipx, 0.5*flipy},
  1278. { 0.5*flipx, 0.5*flipy},
  1279. { 0.5*flipx, -0.5*flipy}};
  1280. glVertexPointer(2,GL_FLOAT,0,pointsFlip);
  1281. glDrawArrays(GL_TRIANGLE_FAN,0,4);
  1282. glDisable(GL_TEXTURE_2D);
  1283. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1284. glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  1285. if (presetOutputs->bBrighten==1)
  1286. {
  1287. glColor4f(1.0, 1.0, 1.0, 1.0);
  1288. glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
  1289. glDrawArrays(GL_TRIANGLE_FAN,0,4);
  1290. glBlendFunc(GL_ZERO, GL_DST_COLOR);
  1291. glDrawArrays(GL_TRIANGLE_FAN,0,4);
  1292. glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
  1293. glDrawArrays(GL_TRIANGLE_FAN,0,4);
  1294. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1295. }
  1296. if (presetOutputs->bDarken==1)
  1297. {
  1298. glColor4f(1.0, 1.0, 1.0, 1.0);
  1299. glBlendFunc(GL_ZERO, GL_DST_COLOR);
  1300. glDrawArrays(GL_TRIANGLE_FAN,0,4);
  1301. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1302. }
  1303. if (presetOutputs->bSolarize)
  1304. {
  1305. glColor4f(1.0, 1.0, 1.0, 1.0);
  1306. glBlendFunc(GL_ZERO, GL_ONE_MINUS_DST_COLOR);
  1307. glDrawArrays(GL_TRIANGLE_FAN,0,4);
  1308. glBlendFunc(GL_DST_COLOR, GL_ONE);
  1309. glDrawArrays(GL_TRIANGLE_FAN,0,4);
  1310. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1311. }
  1312. if (presetOutputs->bInvert)
  1313. {
  1314. glColor4f(1.0, 1.0, 1.0, 1.0);
  1315. glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
  1316. glDrawArrays(GL_TRIANGLE_FAN,0,4);
  1317. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1318. }
  1319. }
  1320. void Renderer::render_texture_to_studio(PresetOutputs *presetOutputs, PresetInputs *presetInputs)
  1321. {
  1322. /*
  1323. CSectionLock lock(&_renderer_lock);
  1324. int x, y;
  1325. int flipx=1, flipy=1;
  1326. glMatrixMode(GL_TEXTURE);
  1327. glLoadIdentity();
  1328. glMatrixMode(GL_MODELVIEW);
  1329. glLoadIdentity();
  1330. glColor4f(0.0, 0.0, 0.0, 0.04);
  1331. glBegin(GL_QUADS);
  1332. glVertex4d(-0.5, -0.5, -1, 1);
  1333. glVertex4d(-0.5, 0.5, -1, 1);
  1334. glVertex4d(0.5, 0.5, -1, 1);
  1335. glVertex4d(0.5, -0.5, -1, 1);
  1336. glEnd();
  1337. glColor4f(0.0, 0.0, 0.0, 1.0);
  1338. glBegin(GL_QUADS);
  1339. glVertex4d(-0.5, 0, -1, 1);
  1340. glVertex4d(-0.5, 0.5, -1, 1);
  1341. glVertex4d(0.5, 0.5, -1, 1);
  1342. glVertex4d(0.5, 0, -1, 1);
  1343. glEnd();
  1344. glBegin(GL_QUADS);
  1345. glVertex4d(0, -0.5, -1, 1);
  1346. glVertex4d(0, 0.5, -1, 1);
  1347. glVertex4d(0.5, 0.5, -1, 1);
  1348. glVertex4d(0.5, -0.5, -1, 1);
  1349. glEnd();
  1350. glPushMatrix();
  1351. glTranslatef(.25, .25, 0);
  1352. glScalef(.5, .5, 1);
  1353. glEnable(GL_TEXTURE_2D);
  1354. glBlendFunc(GL_ONE, GL_ZERO);
  1355. glColor4f(1.0, 1.0, 1.0, 1.0);
  1356. //Draw giant rectangle and texture it with our texture!
  1357. glBegin(GL_QUADS);
  1358. glTexCoord4d(0, 1, 0, 1); glVertex4d(-0.5, -0.5, -1, 1);
  1359. glTexCoord4d(0, 0, 0, 1); glVertex4d(-0.5, 0.5, -1, 1);
  1360. glTexCoord4d(1, 0, 0, 1); glVertex4d(0.5, 0.5, -1, 1);
  1361. glTexCoord4d(1, 1, 0, 1); glVertex4d(0.5, -0.5, -1, 1);
  1362. glEnd();
  1363. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1364. glMatrixMode(GL_TEXTURE);
  1365. //draw video echo
  1366. glColor4f(1.0, 1.0, 1.0, presetOutputs->fVideoEchoAlpha);
  1367. glTranslatef(.5, .5, 0);
  1368. glScalef(1/presetOutputs->fVideoEchoZoom, 1/presetOutputs->fVideoEchoZoom, 1);
  1369. glTranslatef(-.5, -.5, 0);
  1370. switch (((int)presetOutputs->nVideoEchoOrientation))
  1371. {
  1372. case 0: flipx=1;flipy=1;break;
  1373. case 1: flipx=-1;flipy=1;break;
  1374. case 2: flipx=1;flipy=-1;break;
  1375. case 3: flipx=-1;flipy=-1;break;
  1376. default: flipx=1;flipy=1; break;
  1377. }
  1378. glBegin(GL_QUADS);
  1379. glTexCoord4d(0, 1, 0, 1); glVertex4f(-0.5*flipx, -0.5*flipy, -1, 1);
  1380. glTexCoord4d(0, 0, 0, 1); glVertex4f(-0.5*flipx, 0.5*flipy, -1, 1);
  1381. glTexCoord4d(1, 0, 0, 1); glVertex4f(0.5*flipx, 0.5*flipy, -1, 1);
  1382. glTexCoord4d(1, 1, 0, 1); glVertex4f(0.5*flipx, -0.5*flipy, -1, 1);
  1383. glEnd();
  1384. glDisable(GL_TEXTURE_2D);
  1385. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1386. if (presetOutputs->bInvert)
  1387. {
  1388. glColor4f(1.0, 1.0, 1.0, 1.0);
  1389. glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
  1390. glBegin(GL_QUADS);
  1391. glVertex4f(-0.5*flipx, -0.5*flipy, -1, 1);
  1392. glVertex4f(-0.5*flipx, 0.5*flipy, -1, 1);
  1393. glVertex4f(0.5*flipx, 0.5*flipy, -1, 1);
  1394. glVertex4f(0.5*flipx, -0.5*flipy, -1, 1);
  1395. glEnd();
  1396. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1397. }
  1398. // glTranslated(.5,.5,0);
  1399. // glScaled(1/fVideoEchoZoom,1/fVideoEchoZoom,1);
  1400. // glTranslated(-.5,-.5,0);
  1401. //glTranslatef(0,.5*vh,0);
  1402. //glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ZERO);
  1403. glDisable(GL_TEXTURE_2D);
  1404. glMatrixMode(GL_MODELVIEW);
  1405. glPopMatrix();
  1406. glPushMatrix();
  1407. glTranslatef(.25, -.25, 0);
  1408. glScalef(.5, .5, 1);
  1409. glColor4f(1.0, 1.0, 1.0, 1.0);
  1410. for (x=0;x<presetInputs->gx;x++)
  1411. {
  1412. glBegin(GL_LINE_STRIP);
  1413. for(y=0;y<presetInputs->gy;y++)
  1414. {
  1415. glVertex4f((presetOutputs->x_mesh[x][y]-.5), (presetOutputs->y_mesh[x][y]-.5), -1, 1);
  1416. //glVertex4f((origx[x+1][y]-.5) * vw, (origy[x+1][y]-.5) *vh ,-1,1);
  1417. }
  1418. glEnd();
  1419. }
  1420. for (y=0;y<presetInputs->gy;y++)
  1421. {
  1422. glBegin(GL_LINE_STRIP);
  1423. for(x=0;x<presetInputs->gx;x++)
  1424. {
  1425. glVertex4f((presetOutputs->x_mesh[x][y]-.5), (presetOutputs->y_mesh[x][y]-.5), -1, 1);
  1426. //glVertex4f((origx[x+1][y]-.5) * vw, (origy[x+1][y]-.5) *vh ,-1,1);
  1427. }
  1428. glEnd();
  1429. }
  1430. glEnable( GL_TEXTURE_2D );
  1431. // glTranslated(-.5,-.5,0); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  1432. // Waveform display -- bottom-left
  1433. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  1434. glMatrixMode(GL_MODELVIEW);
  1435. glPushMatrix();
  1436. glTranslatef(-.5, 0, 0);
  1437. glTranslatef(0, -0.10, 0);
  1438. glBegin(GL_LINE_STRIP);
  1439. glColor4f(0, 1.0, 1.0, 1.0);
  1440. glVertex3f((((this->totalframes%256)/551.0)), beatDetect->treb_att*-7, -1);
  1441. glColor4f(1.0, 1.0, 1.0, 1.0);
  1442. glVertex3f((((this->totalframes%256)/551.0)), 0 , -1);
  1443. glColor4f(.5, 1.0, 1.0, 1.0);
  1444. glVertex3f((((this->totalframes%256)/551.0)), beatDetect->treb*7, -1);
  1445. glEnd();
  1446. glTranslatef(0, -0.13, 0);
  1447. glBegin(GL_LINE_STRIP);
  1448. glColor4f(0, 1.0, 0.0, 1.0);
  1449. glVertex3f((((this->totalframes%256)/551.0)), beatDetect->mid_att*-7, -1);
  1450. glColor4f(1.0, 1.0, 1.0, 1.0);
  1451. glVertex3f((((this->totalframes%256)/551.0)), 0 , -1);
  1452. glColor4f(.5, 1.0, 0.0, 0.5);
  1453. glVertex3f((((this->totalframes%256)/551.0)), beatDetect->mid*7, -1);
  1454. glEnd();
  1455. glTranslatef(0, -0.13, 0);
  1456. glBegin(GL_LINE_STRIP);
  1457. glColor4f(1.0, 0.0, 0.0, 1.0);
  1458. glVertex3f((((this->totalframes%256)/551.0)), beatDetect->bass_att*-7, -1);
  1459. glColor4f(1.0, 1.0, 1.0, 1.0);
  1460. glVertex3f((((this->totalframes%256)/551.0)), 0 , -1);
  1461. glColor4f(.7, 0.2, 0.2, 1.0);
  1462. glVertex3f((((this->totalframes%256)/551.0)), beatDetect->bass*7, -1);
  1463. glEnd();
  1464. glTranslatef(0, -0.13, 0);
  1465. glBegin(GL_LINES);
  1466. glColor4f(1.0, 1.0, 1.0, 1.0);
  1467. glVertex3f((((this->totalframes%256)/551.0)), 0 , -1);
  1468. glColor4f(1.0, 0.6, 1.0, 1.0);
  1469. glVertex3f((((this->totalframes%256)/551.0)), beatDetect->vol*7, -1);
  1470. glEnd();
  1471. glPopMatrix();
  1472. glDisable(GL_TEXTURE_2D);
  1473. */
  1474. }