I have a question regarding texture usage.
I’m working on an application which incorporates a spectrogram for analyzing audio input. I’m
displaying the FFT (fast Fourier-Transform) data in the columns of my texture matrix (columns->time &
rows->freqeuncy). Everytime I recieve a new FFT frame of my audio input I move all columns but the
oldest (which is the last column) such that my new FFT frame can be inserted in the first column ; then
I can display my spectrogram.
My question is now:
Everytime I get a new FFT frame I move a lot of data around in my texture matrix which seems
like a redundant operation so does there exist a way of getting around this? I’ve been looking for a
method which overcomes this by adding an offset to the texture in the horizontal direction
(the time direction) and when the texture goes out of screen it should then appear in the opposite
side of the screen, but this method I have not stumbled upon - is this possible?
Hope to hear from you and that I made myself clear
Yes, that’s the best way to do it. Textures have clamping modes set to GL_REPEAT by default. Linear filtering between last and first texel also works if you need it.
You update texture row by row and each frame you add 1 texel offset to your texture coordinates.
Note that you should keep this offset in [0…1] range to avoid texture coordinate precision problems.
Can you please help how to apply this offset?
What I currently do which works looks like this:
// ----------- Timer callback function ----------
memmove(&myTexture[texWidth*3], &myTexture, (texHeight-1)*texWidth*3);
int freq_indx = 0;
for (int indx=0; indx<texWidth; indx++)
binColor = int(floor(255.f*mags[currentMag][indx]+1.0));
myTexture[freq_indx] = colorMap[binColor];
myTexture[freq_indx+1] = colorMap[binColor];
myTexture[freq_indx+2] = colorMap[binColor];
freq_indx += 3; // Go to the next position (next row)
// Update texture
// ----------- DrawGLScene Method -----------
glRotatef(0, 1.0f, 1.0f, 1.0f);
float ref = 1.0f;
glTexCoord2f(0.0f, 1.0f); glVertex3f(-ref, -ref, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( ref, -ref, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( ref, ref, 0.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-ref, ref, 0.0f);
I’d expect the offset to be applied in the glTexCoord2f() method but what I’ve tried so far does not work
Sorry if the question is trivial!
i’m a bit curious- what’s the point in glRotatef(0, 1.0f, 1.0f, 1.0f) ?
Ahhh, sorry that one should have been deleted. I’ve just been playing with the different rotations! It shouldn’t do much harm as it is now - or can it?
As k_szczech said: You can offset the texture by exactly one column.
Just add i*(1.0/texWidth) to the t texture coordinates. This scrolls the texture i columns to the right.
Then you only need to update a single column each step.
Hey it now works…simply by doing it this way (as suggested):
glTexCoord2f(0.0f, 1.0f+offset); glVertex3f(-ref, -ref, 0.0f);
glTexCoord2f(1.0f, 1.0f+offset); glVertex3f( ref, -ref, 0.0f);
glTexCoord2f(1.0f, 0.0f+offset); glVertex3f( ref, ref, 0.0f);
glTexCoord2f(0.0f, 0.0f+offset); glVertex3f(-ref, ref, 0.0f);
offset += 1.0f/texHeight;
offset = 0.0f;
Thanks for your patience
cheers and happy new year!