poistettu valot
This commit is contained in:
97
src/main.cpp
97
src/main.cpp
@ -16,11 +16,6 @@
|
||||
#define USE_AUDIO 1
|
||||
#define NO_UNIFORMS 0
|
||||
|
||||
#define SHAPES 16
|
||||
#define SHAPES_TEX_SIZE (SHAPES * SHAPES * 4)
|
||||
#define SHAPES_TOTAL (SHAPES * SHAPES)
|
||||
#define MAX_DISTANCE 100.f
|
||||
|
||||
#include "definitions.h"
|
||||
#if OPENGL_DEBUG
|
||||
#include "debug.h"
|
||||
@ -47,9 +42,7 @@ static int pidPost;
|
||||
// FFT buffers
|
||||
static Complex signal[FFT_SIZE];
|
||||
static Complex buffer[3 * FFT_SIZE];
|
||||
|
||||
static float fft_uniform[FFT_SIZE / 4];
|
||||
static float shapesData[SHAPES_TEX_SIZE];
|
||||
|
||||
void entrypoint(void)
|
||||
#else
|
||||
@ -130,19 +123,6 @@ int __cdecl main(int argc, char* argv[])
|
||||
// Play sound
|
||||
direct_sound_buffer->Play(0, 0, 0);
|
||||
|
||||
// main note effect
|
||||
boolean beenPlaying = false;
|
||||
const int SHAPES_SIZE = 15;
|
||||
float shapeIncrement = 0.15f;
|
||||
|
||||
int currentShape = 0; // mark location which shape we are currently building
|
||||
|
||||
boolean isPlaying = false;
|
||||
|
||||
float lastPlayPos = 0;
|
||||
float lastNote = 0.0f;
|
||||
|
||||
|
||||
struct Vec3 {
|
||||
float x, y, z;
|
||||
};
|
||||
@ -152,18 +132,6 @@ int __cdecl main(int argc, char* argv[])
|
||||
PFNGLUNIFORM1IPROC glUniform1i = ((PFNGLUNIFORM1IPROC)wglGetProcAddress("glUniform1i"));
|
||||
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = ((PFNGLGETUNIFORMLOCATIONPROC)wglGetProcAddress("glGetUniformLocation"));
|
||||
|
||||
GLuint ShapesTex;
|
||||
|
||||
glGenTextures(1, &ShapesTex);
|
||||
glBindTexture(GL_TEXTURE_2D, ShapesTex);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, SHAPES, SHAPES, 0, GL_RGBA, GL_FLOAT, nullptr);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
const ULONGLONG targetIntervalMs = 1000 / 60; // For 60 FPS FFT updates
|
||||
|
||||
do
|
||||
@ -248,71 +216,6 @@ int __cdecl main(int argc, char* argv[])
|
||||
{
|
||||
syncs[i + 1] = syncBuf[(playCursor / (2 * sizeof(SUsample)) >> 8) * SU_NUMSYNCS + i];
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Shape builder
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
// if sound is playing, start a shape, if shape is already started - add length
|
||||
// if sound has stopped, end shape
|
||||
// if shape is finished, move shape forward
|
||||
float captureSync = syncs[5];
|
||||
|
||||
bool shapeJustFinished = false;
|
||||
bool shapeJustStarted = false;
|
||||
|
||||
// Detect note change to start a new shape
|
||||
bool noteChanged = (captureSync != lastNote) ? TRUE : FALSE;
|
||||
lastNote = captureSync;
|
||||
|
||||
// If note changed and value is significant, start new shape
|
||||
if (noteChanged) {
|
||||
int index = currentShape * 4;
|
||||
|
||||
// Reset and activate current shape
|
||||
shapesData[index + 0] = 0.0f; // x start
|
||||
shapesData[index + 1] = captureSync; // y from audio
|
||||
shapesData[index + 2] = 1.0f; // z (unused or length)
|
||||
shapesData[index + 3] = 1.0f; // active
|
||||
|
||||
// Advance to next shape slot (circular)
|
||||
currentShape = (currentShape + 1) % SHAPES_TOTAL;
|
||||
}
|
||||
|
||||
// Move active shapes
|
||||
for (int i = 0; i < SHAPES_TOTAL; ++i) {
|
||||
int index = i * 4;
|
||||
|
||||
// Check if shape is active
|
||||
if (shapesData[index + 3] > 0.5f) {
|
||||
// Move shape right
|
||||
shapesData[index + 0] += shapeIncrement;
|
||||
|
||||
// Update y (optional, reflect live audio)
|
||||
//shapesData[index + 1] = captureSync;
|
||||
|
||||
// Optional: grow z value to show duration
|
||||
//shapesData[index + 2] += shapeIncrement * 0.2f;
|
||||
|
||||
// If x exceeds max distance, deactivate and reset
|
||||
if (shapesData[index + 0] > MAX_DISTANCE) {
|
||||
shapesData[index + 0] = 0.0f;
|
||||
shapesData[index + 1] = 0.0f;
|
||||
shapesData[index + 2] = 0.0f;
|
||||
shapesData[index + 3] = 0.0f; // inactive
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Bind and update u_ShapesTex
|
||||
glUniform1i(glGetUniformLocation(pidMain, "u_ShapesTex"), 0);
|
||||
glActiveTexture(GL_TEXTURE0 + 0);
|
||||
glBindTexture(GL_TEXTURE_2D, ShapesTex);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, SHAPES, SHAPES, GL_RGBA, GL_FLOAT, shapesData);
|
||||
|
||||
|
||||
glUniform1fvProc(0, SU_NUMSYNCS + 1, syncs);
|
||||
glUniform1fvProc(20, FFT_SIZE / 4, fft_uniform);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user