nuotti-triggeri ja useampi tekstuuri käytössä
This commit is contained in:
152
src/main.cpp
152
src/main.cpp
@ -171,6 +171,38 @@ int __cdecl main(int argc, char* argv[])
|
||||
#define GRID 32
|
||||
#define HEX_TEX_SIZE (GRID * GRID * 4) // RGBA: 4 floats per texel
|
||||
|
||||
#define SHAPES 16
|
||||
#define SHAPES_TEX_SIZE (SHAPES * SHAPES * 4)
|
||||
#define SHAPES_TOTAL (SHAPES * SHAPES)
|
||||
#define MAX_DISTANCE 100.f
|
||||
|
||||
PFNGLUNIFORM1FVPROC glUniform1fvProc = ((PFNGLUNIFORM1FVPROC)wglGetProcAddress("glUniform1fv"));
|
||||
PFNGLACTIVETEXTUREPROC glActiveTexture = ((PFNGLACTIVETEXTUREPROC)wglGetProcAddress("glActiveTexture"));
|
||||
PFNGLUNIFORM1IPROC glUniform1i = ((PFNGLUNIFORM1IPROC)wglGetProcAddress("glUniform1i"));
|
||||
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = ((PFNGLGETUNIFORMLOCATIONPROC)wglGetProcAddress("glGetUniformLocation"));
|
||||
|
||||
GLuint hexGridTex, ShapesTex;
|
||||
glGenTextures(1, &hexGridTex);
|
||||
glBindTexture(GL_TEXTURE_2D, hexGridTex);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, GRID, GRID, 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);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
do
|
||||
{
|
||||
direct_sound_buffer->GetCurrentPosition((DWORD*)&playCursor, NULL);
|
||||
@ -246,6 +278,8 @@ int __cdecl main(int argc, char* argv[])
|
||||
syncs[i + 1] = syncBuf[(playCursor / (2 * sizeof(SUsample)) >> 8) * SU_NUMSYNCS + i];
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Shape builder
|
||||
//////////////////////////////////////////////////////
|
||||
@ -253,50 +287,64 @@ int __cdecl main(int argc, char* argv[])
|
||||
// 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
|
||||
|
||||
static float shapesData[SHAPES_TEX_SIZE];
|
||||
float captureSync = syncs[5];
|
||||
|
||||
if (captureSync >= 0.001f) {
|
||||
isPlaying = true;
|
||||
bool shapeJustFinished = false;
|
||||
bool shapeJustStarted = false;
|
||||
|
||||
// Detect note change to start a new shape
|
||||
bool noteChanged = (captureSync - lastNote) * (captureSync - lastNote) > 0.0001f;
|
||||
lastNote = captureSync;
|
||||
|
||||
|
||||
// If note changed and value is significant, start new shape
|
||||
if (captureSync > 0.001f && 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;
|
||||
}
|
||||
|
||||
if (isPlaying) {
|
||||
// vec3ShapeArray[currentShape][1] = captureSync;
|
||||
// vec3ShapeArray[currentShape][2] = vec3ShapeArray[currentShape][2] + shapeIncrement;
|
||||
// Move active shapes
|
||||
for (int i = 0; i < SHAPES_TOTAL; ++i) {
|
||||
int index = i * 4;
|
||||
|
||||
test[0] = test[0] + shapeIncrement; // x position
|
||||
test[1] = captureSync; // y position
|
||||
test[2] = 0.3f; // length
|
||||
}
|
||||
// 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;
|
||||
|
||||
// when note changes -- reset
|
||||
if (lastNote != captureSync) {
|
||||
test[0] = 0.0f;
|
||||
test[1] = 0.1f;
|
||||
lastNote = captureSync;
|
||||
}
|
||||
// Optional: grow z value to show duration
|
||||
//shapesData[index + 2] += shapeIncrement * 0.2f;
|
||||
|
||||
// shape mover, if the shape isnt the current one - move it
|
||||
|
||||
for (int i = 0; i < SHAPES_SIZE; ++i) {
|
||||
if (i != currentShape) {
|
||||
vec3ShapeArray[i][0] = vec3ShapeArray[i][0] + shapeIncrement;
|
||||
// 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
beenPlaying = isPlaying;
|
||||
// Bind and update u_ShapesTex
|
||||
glActiveTexture(GL_TEXTURE0 + 2);
|
||||
glBindTexture(GL_TEXTURE_2D, ShapesTex);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, SHAPES, SHAPES, GL_RGBA, GL_FLOAT, shapesData);
|
||||
glUniform1i(glGetUniformLocation(pidMain, "u_ShapesTex"), 2);
|
||||
|
||||
// go through the array and start from the first when all shapes have been used
|
||||
if (beenPlaying) {
|
||||
if (currentShape <= SHAPES_SIZE) {
|
||||
++currentShape;
|
||||
}
|
||||
else {
|
||||
currentShape = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
float flatShapes[15] = {
|
||||
vec3ShapeArray[0][0], vec3ShapeArray[0][1], vec3ShapeArray[0][2],
|
||||
vec3ShapeArray[1][0], vec3ShapeArray[1][1], vec3ShapeArray[1][2],
|
||||
@ -304,21 +352,25 @@ int __cdecl main(int argc, char* argv[])
|
||||
vec3ShapeArray[3][0], vec3ShapeArray[3][1], vec3ShapeArray[3][2],
|
||||
vec3ShapeArray[4][0], vec3ShapeArray[4][1], vec3ShapeArray[4][2]
|
||||
};
|
||||
*/
|
||||
|
||||
PFNGLUNIFORM3FVPROC glUniform3fvProc = ((PFNGLUNIFORM3FVPROC)wglGetProcAddress("glUniform3fv"));
|
||||
glUniform3fvProc(600, 1, flatShapes); // array of shapes
|
||||
glUniform3fvProc(700, 1, test); // test shape
|
||||
|
||||
|
||||
//PFNGLUNIFORM3FVPROC glUniform3fvProc = ((PFNGLUNIFORM3FVPROC)wglGetProcAddress("glUniform3fv"));
|
||||
//glUniform3fvProc(600, 1, flatShapes); // array of shapes
|
||||
//glUniform3fvProc(700, 1, test); // test shape
|
||||
|
||||
PFNGLUNIFORM1FVPROC glUniform1fvProc = ((PFNGLUNIFORM1FVPROC)wglGetProcAddress("glUniform1fv"));
|
||||
|
||||
glUniform1fvProc(0, SU_NUMSYNCS + 1, syncs);
|
||||
glUniform1fvProc(20, FFT_SIZE / 4, fft_uniform);
|
||||
|
||||
glRects(-1, -1, 1, 1);
|
||||
|
||||
PFNGLACTIVETEXTUREPROC glActiveTexture = ((PFNGLACTIVETEXTUREPROC)wglGetProcAddress("glActiveTexture"));
|
||||
PFNGLUNIFORM1IPROC glUniform1i = ((PFNGLUNIFORM1IPROC)wglGetProcAddress("glUniform1i"));
|
||||
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation = ((PFNGLGETUNIFORMLOCATIONPROC)wglGetProcAddress("glGetUniformLocation"));
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Hex Grid Builder
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
static float hexGridData[HEX_TEX_SIZE];
|
||||
|
||||
|
||||
@ -357,22 +409,14 @@ int __cdecl main(int argc, char* argv[])
|
||||
hexGridData[idx + 3] = hexDist;
|
||||
}
|
||||
}
|
||||
|
||||
GLuint hexGridTex;
|
||||
glGenTextures(1, &hexGridTex);
|
||||
|
||||
// Bind and update u_hexGridTex
|
||||
glActiveTexture(GL_TEXTURE0 + 1);
|
||||
glBindTexture(GL_TEXTURE_2D, hexGridTex);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, GRID, GRID, GL_RGBA, GL_FLOAT, hexGridData);
|
||||
glUniform1i(glGetUniformLocation(pidMain, "u_hexGridTex"), 1);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, GRID, GRID, 0, GL_RGBA, GL_FLOAT, hexGridData);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + 2);
|
||||
glUniform1i(glGetUniformLocation(pidMain, "u_hexGridTex"), 2);
|
||||
|
||||
glRects(-1, -1, 1, 1);
|
||||
|
||||
// render "post process" using the opengl backbuffer
|
||||
#if POST_PASS
|
||||
|
||||
Reference in New Issue
Block a user