aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Classes/UVisualizer.pas
diff options
context:
space:
mode:
authortobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2007-12-06 10:40:15 +0000
committertobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c>2007-12-06 10:40:15 +0000
commit27ca028ea19879bb3b109c58bae86b61e60b3370 (patch)
treeaa06cdb49e22c70f00d7b2da8242d408df7518ff /Game/Code/Classes/UVisualizer.pas
parent486ad8796acc5883ef83f3a78cd615f6711d77f0 (diff)
downloadusdx-27ca028ea19879bb3b109c58bae86b61e60b3370.tar.gz
usdx-27ca028ea19879bb3b109c58bae86b61e60b3370.tar.xz
usdx-27ca028ea19879bb3b109c58bae86b61e60b3370.zip
Visualizer changes (audio connection, some opengl fixes)
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@679 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to '')
-rw-r--r--Game/Code/Classes/UVisualizer.pas96
1 files changed, 56 insertions, 40 deletions
diff --git a/Game/Code/Classes/UVisualizer.pas b/Game/Code/Classes/UVisualizer.pas
index 1905358f..0f2334ba 100644
--- a/Game/Code/Classes/UVisualizer.pas
+++ b/Game/Code/Classes/UVisualizer.pas
@@ -30,16 +30,19 @@ uses SDL,
implementation
+uses
+ UGraphic;
+
var
singleton_VideoProjectM : IVideoPlayback;
const
- VisualWidth = 800; // 640
- VisualHeight = 600; // 480
gx = 32;
gy = 24;
fps = 30;
texsize = 512;
+ visuals_Dir = 'Visuals'; // TODO: move this to a place common for all visualizers
+ projectM_Dir = visuals_Dir+'/projectM';
type
TVideoPlayback_ProjectM = class( TInterfacedObject, IVideoPlayback )
@@ -50,7 +53,7 @@ type
VisualizerPaused : Boolean;
VisualTex : glUint;
- pcm_data : TPCM16;
+ PCMData : TPCMData;
hRC : Integer;
hDC : Integer;
@@ -140,7 +143,6 @@ end;
procedure TVideoPlayback_ProjectM.VisualizerStart;
begin
-//exit;
VisualizerStarted := True;
New(pm);
@@ -153,8 +155,8 @@ begin
pm^.fps := fps;
pm^.renderTarget^.usePbuffers := 0;
- pm^.fontURL := PChar('Visuals\fonts');
- pm^.presetURL := PChar('Visuals\presets');
+ pm^.fontURL := PChar(projectM_Dir+'/fonts');
+ pm^.presetURL := PChar(projectM_Dir+'/presets');
glPushAttrib(GL_ALL_ATTRIB_BITS);
projectM_init(pm);
@@ -164,7 +166,9 @@ begin
glPushMatrix();
glMatrixMode(GL_TEXTURE);
glPushMatrix();
- projectM_resetGL(pm, VisualWidth, VisualHeight);
+
+ projectM_resetGL(pm, ScreenW, ScreenH);
+
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
@@ -191,21 +195,16 @@ end;
procedure TVideoPlayback_ProjectM.GetFrame(Time: Extended);
var
i: integer;
+ nSamples: cardinal;
begin
-// exit;
-
if not VisualizerStarted then Exit;
if VisualizerPaused then Exit;
- Randomize();
-
- for i := 0 to 511 do
- begin
- pcm_data[0][i] := RandomRange(High(Smallint), Low(Smallint));
- pcm_data[1][i] := pcm_data[0][i];
- end;
- addPCM16(pcm_data);
+ // get audio data
+ nSamples := AudioPlayback.GetPCMData(PcmData);
+ addPCM16Data(PSmallInt(@PcmData), nSamples);
+ // store OpenGL state (might be messed up otherwise)
glPushAttrib(GL_ALL_ATTRIB_BITS);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
@@ -213,12 +212,17 @@ begin
glPushMatrix();
glMatrixMode(GL_TEXTURE);
glPushMatrix();
+
+ // let projectM render a frame
renderFrame(pm);
glFlush();
- {
+
+ {$IFDEF UseTexture}
glBindTexture(GL_TEXTURE_2D, VisualTex);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, VisualWidth, VisualHeight, 0);
- }
+ {$ENDIF}
+
+ // restore USDX OpenGL state
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
@@ -227,41 +231,45 @@ begin
glPopMatrix();
glPopAttrib();
+ // discard projectM's depth buffer information (avoid overlay)
glClear(GL_DEPTH_BUFFER_BIT);
-
- {
- glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
-
- glEnable(GL_TEXTURE_2D);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
- glBindTexture(GL_TEXTURE_2D, VisualTex);
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0); glVertex2f(-1, -1);
- glTexCoord2f(1, 0); glVertex2f( 1, -1);
- glTexCoord2f(1, 1); glVertex2f( 1, 1);
- glTexCoord2f(0, 1); glVertex2f(-1, 1);
- glEnd();
- glDisable(GL_TEXTURE_2D);
- }
end;
procedure TVideoPlayback_ProjectM.DrawGL(Screen: integer);
begin
-
- exit;
-
+ {$IFDEF UseTexture}
// have a nice black background to draw on (even if there were errors opening the vid)
if Screen=1 then begin
- glClearColor(0,0,0,0);
+ glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
end;
// exit if there's nothing to draw
if not VisualizerStarted then Exit;
- glEnable(GL_TEXTURE_2D);
+ // setup display
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadIdentity();
+ gluOrtho2D(0, 1, 0, 1);
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+
glEnable(GL_BLEND);
- glColor4f(1, 1, 1, 1);
+ glEnable(GL_TEXTURE_2D);
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBindTexture(GL_TEXTURE_2D, VisualTex);
+ glColor4f(1, 1, 1, 1);
+
+ // draw projectM frame
+ glBegin(GL_QUADS);
+ glTexCoord2f(0, 0); glVertex2f(0, 0);
+ glTexCoord2f(1, 0); glVertex2f(1, 0);
+ glTexCoord2f(1, 1); glVertex2f(1, 1);
+ glTexCoord2f(0, 1); glVertex2f(0, 1);
+ glEnd();
+
+ {
glbegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(400-VisualWidth/2, 300-VisualHeight/2);
@@ -272,9 +280,17 @@ begin
glTexCoord2f(1, 0);
glVertex2f(400+VisualWidth/2, 300-VisualHeight/2);
glEnd;
+ }
+
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
+ // restore state
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+ {$ENDIF}
end;