Sign in to follow this  

weird problem with vertexalpha, blending [solved]

This topic is 4869 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys! I've a very weird problem.. I'm searching the problem for hours now, so I thought I could ask you experts: What I have: My little terrain-engine is blending 2 texures based on their vertex alpha values:
				glClientActiveTextureARB(GL_TEXTURE0_ARB);
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_TexCoVBO);
glTexCoordPointer( 2, GL_FLOAT, 0, (char *)NULL);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glClientActiveTextureARB(GL_TEXTURE1_ARB);				
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_TexCoVBO);
glTexCoordPointer( 2, GL_FLOAT, 0, (char *)NULL);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[1]);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_PRIMARY_COLOR_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_ALPHA);
		
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);




All the vertex data is held in a vbo, same for the texture coordinates. The data is drawn with index-buffers (one for each lod). Ok, that works fine, all vertizes are blended EXCEPT the last one. Example: example As you can see on the image, the two textures on the left are blended, except the last vertex (the upper right corner). For debuging, I even mapped the buffers to check all values.. I'm really help- and hopeless :/ Does anybody have an idea what the problem could be? If you need additional code, just ask me.. Thanks a lot! misto [Edited by - misto on August 16, 2004 8:22:43 AM]

Share this post


Link to post
Share on other sites
Hi!

Yes sure, here the code to initialize the vbos:



glGenBuffersARB( 1, &m_VBOVertex );
m_Data = new Vertex[1089];
for( int iY = 0; iY <= 32; iY++)
for( int iX = 0; iX <= 32; iX++)
{
m_Data[iV].fX = iX;
m_Data[iV].fY = iY;
m_Data[iV].fZ = 0;
m_Data[iV].fA = 0.5;
iV++;
}

glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_VBOVertex );
glBufferDataARB( GL_ARRAY_BUFFER_ARB, iV * sizeof(Vertex),
m_Data, GL_STATIC_DRAW_ARB);



the code for the texture-coordinates buffer is very similar, I think it should be correct, because the texture is applied correct.

the index buffer:

patches = 32;
int step = 8;

int anzIndices = patches/step * (patches*2/step + 2);
GLushort* data = new GLushort[anzIndices];
int iI = 0;

for( int iY = 0; iY < patches; iY+=step)
{
for( int iX = 0; iX <= patches; iX+=step)
{
if(iY%(2*step) == 0)
{
data[iI] = (patches+1) * (iY+step) + iX;
iI++;
data[iI] = (patches+1) * (iY+0) + iX;
iI++;
}
else
{
data[iI] = (patches+1) * (iY+0) + patches - iX;
iI++;
data[iI] = (patches+1) * (iY+step) + patches - iX;
iI++;
}
}
}
m_IndexBufferCount[i] = anzIndices;

glGenBuffersARB(1, &m_IndexBuffer[i]);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_IndexBuffer[i]);
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, anzIndices*sizeof(GLushort), data, GL_STATIC_DRAW_ARB);


Hmm.. the code might look a bit confusing, but it seems to work so far, at least for the geometry :)

and now the rendering:


glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_Patches[iX][iY]->getVBO() );
glVertexPointer( 3, GL_FLOAT, sizeof(Vertex), (char *)NULL);
glColorPointer ( 4, GL_FLOAT, sizeof(Vertex), (char *)NULL + 96);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_IndexBuffer[m_Patches[iX][iY]->getLOD()]);
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_TexCoVBO);
glTexCoordPointer( 2, GL_FLOAT, 0, (char *)NULL);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glClientActiveTextureARB(GL_TEXTURE1_ARB);
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_TexCoVBO);
glTexCoordPointer( 2, GL_FLOAT, 0, (char *)NULL);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[1]);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_PRIMARY_COLOR_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_ALPHA);
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

glDrawElements(GL_TRIANGLE_STRIP, m_IndexBufferCount[m_Patches[iX][iY]->getLOD()], GL_UNSIGNED_SHORT, (GLushort*)NULL);



Hmm.. yes, that should be all :) If somebody needs the whole code, I could send it per email.. (runs under linux only)

Thanks a lot!

Share this post


Link to post
Share on other sites
That is because of my vertex-structure:


class Vertex
{
public:

float fX,
fY,
fZ,
fR,
fG,
fB,
fA;
};



94 is the offset in bits from the beginning of the class 8bit/byte * 3 vertizes * 4byte/float, isn't it like that?

Share this post


Link to post
Share on other sites
Yes, that was the bug! Uff.. thanks a lot TomasH.. I don't now why i thought it were in bit.. hmm.. but now it's clear, I alyways "jumped" over the correct alpha value..

Share this post


Link to post
Share on other sites

This topic is 4869 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this