Problem with multi-texturing [SOLVED]

Started by
17 comments, last by aevanthony 15 years, 11 months ago
According to what I've just read, gl_TexCoord; i = texture unit.

It's not reflected above, but I currently have my vert and frag shader referencing gl_TexCoord[2], and in the vert shader I assign 'gl_TexCoord[2] = gl_MultiTexCoord2;'.

Still not getting information from the GL_TEXTURE2 (data) texture in the output.
Advertisement
That's because that is wrong and if a source told you that it is wrong and crap.

There is no connection between that 'i' and texture units at all.
The only connection is between supplied vertex data and how it is aliased to internal attributes which mimic the fixed function.

In fact, I typo'd on my earlier post as I should have said; glTexCoord2f sends data to gl_MultiTexCoord0, as such because you don't provide it gl_MultiTexCoord1's data.

You are not supplying data to gl_MultiTexCoord1, 2, 3 or any other number; just gl_MultiTexCoord0.

As such the values you are reading are 'undefined' and the texture sampling is working, it just isn't doing what you expect.

Oh, and don't go back and edit posts like you have been doing, it is very annoying and makes it bothersome to follow thread flow.
The source was the often cited Lighthouse3d website. But I understand what you're saying. Gotcha.

With all the considerations in your reply I've made some more necessary adjustments. Except one...

So what I need to do is render the audio data to some off screen quad and just never display it? Or is there some better way of "rendering" the data so it goes to the GPU? I'm not sure how to go about this ...

How do I get the data to the gpu, exactly? :)

I understand why the line with glTexSubImage2D was incorrect as well, I've taken that out. It doesn't copy from system memory to the shader.
I tried a few things different, but none of it seemed to work.

At first I used the rendering sequence below on just FBO to Texture, then just to the window, and both... I figured you meant I had to do something like this to get the other texture to the GPU...

But... like I said... the only thing this did was give me some choppy flickering. And only in the one color I was looping, regardless of what appeared since none of the color channels with the audio data came through in the image.

So what's wrong with what I did, and what do I do?

glBegin(GL_QUADS);	glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0.0, 0.0);	glMultiTexCoord2fARB(GL_TEXTURE0_ARB + TexRenderRead, 0.0, 0.0);	glVertex3f(-1.0, -1.0,  0.0);	glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0.0, 1.0);	glMultiTexCoord2fARB(GL_TEXTURE0_ARB + TexRenderRead, 0.0, 1.0);	glVertex3f(-1.0,  1.0,  0.0);	glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 1.0, 1.0);	glMultiTexCoord2fARB(GL_TEXTURE0_ARB + TexRenderRead, 1.0, 1.0);	glVertex3f( 1.0,  1.0,  0.0);	glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 1.0, 0.0);	glMultiTexCoord2fARB(GL_TEXTURE0_ARB + TexRenderRead, 1.0, 0.0);	glVertex3f( 1.0, -1.0,  0.0);glEnd();
Why would the results of;
'glTexCoord2f(...)'

differ from;
'glMultiTexCoord2fARB(GL_TEXTURE0_ARB + i,...)' ?

It seems to be the case for me... I can't get the correct output with glMulti..., it looks like the two diagonal halves of the screen just flicker back and forth.

Am I missing something with that?
Sort of have it working.

Instead of each texel representing it's own color value per audio data, I get a solid flickering image (flickering to the beat of the music, so at lease *one value is being sent....), any idea why? I'm clearly stating that for a texture of dimensions SDxSD (256x256 in this case) to assign a unique value from the audio buffer. Why would it render as if only one value is being sent, and if that's the case... what should I do?


(in the vert shader: 'gl_TexCoord[1] = gl_MultiTexCoord2;')

a portion of the RENDER sequence:
//...for (int x=0; x<SD; ++x)for (int y=0; y<SD; ++y){	TexAudio[x][y][0] = GLubyte (int(fmLBuf[x] * 128) + 127);	TexAudio[x][y][1] = GLubyte (int(fmRBuf[y] * 128) + 127);	TexAudio[x][y][2] = 0;	TexAudio[x][y][3] = 255;}	glActiveTextureARB(GL_TEXTURE2_ARB);glBindTexture(GL_TEXTURE_2D, FBOTex[TexAudioData]);glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, SD, SD, 0, GL_RGBA, GL_UNSIGNED_BYTE, TexAudio);// ... fbo stuff/quad/etc
Quote:Original post by aevanthony
Why would the results of;
'glTexCoord2f(...)'

differ from;
'glMultiTexCoord2fARB(GL_TEXTURE0_ARB + i,...)' ?

It seems to be the case for me... I can't get the correct output with glMulti..., it looks like the two diagonal halves of the screen just flicker back and forth.

Am I missing something with that?


If in glMultiTexCoord2fARB(GL_TEXTURE0_ARB + i,...)
the i is 0, then it could be a driver bug.
glTexCoord2f(x, y) and glMultiTexCoord2fARB(GL_TEXTURE0_ARB, x, t) are suppose to be the same thing.
In this case, I would just avoid the bug by moving to VBO.

[Edited by - V-man on April 30, 2008 4:39:14 PM]
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
It seems I actually don't need to use 'glMultiTexCoord2fARB' at the moment, so I'm fine on that front. In my last post I should have mentioned I went back to just using 'glTexCoord2f' since 'glTexImage2D' seems to toss the pixel data up to the GPU (sort of it seems.), so I'm not rendering two textures, just one.

But I've still been struggling with finding ways of getting all the pixel data I need to the GPU.

/long-sigh I can't wait to get this over with, then I can finally focus on algorithms, my last bump in this learning curve is a damn CPU->GPU transfer for some audio data.
After a lot of searching I found some thread on this forum that made a reference to the necessity to call 'glPixelStorei()' before 'glTexSubImage2D()'. So I looked in to consideration and included as below.

I also went with 'glTexSubImage2D()' instead of 'glTexImage2D()'

I'm not sure if it was a combination of those, or some other small adjustments but 'glMultiTexCoord2fARB()' also works as expected.

Here is only the updated portion of my render loop:

// ...fmresult = FMOD_Channel_GetWaveData(fmchannel, fmLBuf, SAMPLESIZE, 0);fmresult = FMOD_Channel_GetWaveData(fmchannel, fmRBuf, SAMPLESIZE, 1);t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;for (int x=0; x<SD; ++x)for (int y=0; y<SD; ++y){	TexAudio[x][y][0] = fmLBuf[x];	TexAudio[x][y][1] = fmRBuf[y];	TexAudio[x][y][2] = GLfloat (0.0);	TexAudio[x][y][3] = GLfloat (1.0);}	glActiveTextureARB(GL_TEXTURE2_ARB);glBindTexture(GL_TEXTURE_2D, FBOTex[TexAudioData]);glPixelStorei(GL_UNPACK_ALIGNMENT, 1);  // <---glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, SD, SD, GL_RGBA, GL_FLOAT, TexAudio);  // <---glUseProgramObjectARB(p);glActiveTextureARB(GL_TEXTURE0_ARB);vLoc = glGetUniformLocationARB(p, "dtex"); glUniform1iARB(vLoc, 0);glActiveTextureARB(GL_TEXTURE2_ARB);vLoc = glGetUniformLocationARB(p, "atex"); glUniform1iARB(vLoc, 2);	vLoc = glGetUniformLocationARB(p, "aDi"); glUniform1fARB(vLoc, (float)SD);vLoc = glGetUniformLocationARB(p, "time"); glUniform1fARB(vLoc, t);glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBO);glPushAttrib(GL_VIEWPORT_BIT | GL_COLOR_BUFFER_BIT);glViewport(0, 0, SD, SD);glDrawBuffer(AttchPoint[TexRenderRead]);glActiveTextureARB(GL_TEXTURE0_ARB + TexRenderRead);glPushMatrix();glBegin(GL_QUADS); // <--- MultiTex instead of TexCoord...	glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0.0, 0.0);	glMultiTexCoord2fARB(GL_TEXTURE0_ARB + TexRenderRead, 0.0, 0.0);	glVertex2f(-1.0, -1.0);			glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 0.0, 1.0);	glMultiTexCoord2fARB(GL_TEXTURE0_ARB + TexRenderRead, 0.0, 1.0);	glVertex2f(-1.0,  1.0);	glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 1.0, 1.0);	glMultiTexCoord2fARB(GL_TEXTURE0_ARB + TexRenderRead, 1.0, 1.0);	glVertex2f( 1.0,  1.0);	glMultiTexCoord2fARB(GL_TEXTURE2_ARB, 1.0, 0.0);	glMultiTexCoord2fARB(GL_TEXTURE0_ARB + TexRenderRead, 1.0, 0.0);	glVertex2f( 1.0, -1.0);glEnd();glPopMatrix();// ...

This topic is closed to new replies.

Advertisement