Is there a simpler way of handling texturing!

Hi,

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

Cheers
Thomas

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.

Hi again,

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[0], (texHeight-1)*texWidth*3);
int freq_indx = 0;
int binColor;
for (int indx=0; indx<texWidth; indx++)
{ 
	binColor = int(floor(255.f*mags[currentMag][indx]+1.0));
	myTexture[freq_indx]   = colorMap[binColor][0];
	myTexture[freq_indx+1] = colorMap[binColor][1];
	myTexture[freq_indx+2] = colorMap[binColor][2];
	freq_indx += 3;	// Go to the next position (next row)
}
// Update texture
glTexSubImage2D(GL_TEXTURE_2D,0,0,0,texWidth,texHeight,GL_RGB,GL_UNSIGNED_BYTE, myTexture);

...
...
...

// ----------- DrawGLScene Method -----------
glRotatef(0, 1.0f, 1.0f, 1.0f);
float ref = 1.0f;
glBegin(GL_QUADS);
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);
glEnd();

I’d expect the offset to be applied in the glTexCoord2f() method but what I’ve tried so far does not work :frowning:

Sorry if the question is trivial!

Cheers

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):

glBegin(GL_QUADS);
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);
glEnd();

offset += 1.0f/texHeight;

if(offset>=1.0f)
offset = 0.0f;

Thanks for your patience :slight_smile:

cheers and happy new year!