Hi,
this time its some problems with sending vertex attributes using VBO's.
I've created a test shader to keep things simple unitl I find whats wrong. Heres what I have.
Heres the extension initialization:
GLUX_LOAD(GL_ARB_vertex_program);
GLUX_LOAD(GL_ARB_vertex_buffer_object);
GLUX_LOAD(GL_EXT_draw_range_elements);
GLUX_LOAD(GL_ARB_shader_objects);
GLUX_LOAD(GL_ARB_shading_language_100);
GLUX_LOAD(GL_ARB_vertex_shader);
GLUX_LOAD(GL_ARB_fragment_shader);
The variables:
int ShaderColor[4],ShaderIndex,ShaderVertex;
unsigned ShaderVBO,ShaderVertexVBO;
The initialization:
glShaderSourceARB(ProgramObject, 1, (const GLcharARB **)&ShaderSource, &length);
//i know it compiles ok, cos if i dont use the VBOs everything runs fine
glAttachObjectARB(ShaderObject, ProgramObject);
glLinkProgramARB(ShaderObject);
for(int i=0;i<4;i++)
{
char txt[256];
sprintf(txt,"Color[%i]",i);
ShaderColor=glGetUniformLocationARB(ShaderObject, txt);
if(ShaderColor==-1)
MessageBox(NULL,txt,"Cant Get Uniform",MB_OK);
}
glGenBuffersARB(1,&ShaderVBO);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, ShaderVBO);
float TempData[4];
TempData[0]=0.0f;
TempData[1]=1.0f;
TempData[2]=2.0f;
TempData[3]=3.0f;
glBufferDataARB(GL_ARRAY_BUFFER_ARB, 4*sizeof(float),TempData, GL_STATIC_DRAW_ARB);
if( glGetError() != GL_NO_ERROR )
{
MessageBox(NULL,"Error!","VBO",MB_OK);
}
glGenBuffersARB(1,&ShaderVertexVBO);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, ShaderVertexVBO);
float VertData[16];
VertData[0]=0.0f;
VertData[1]=0.0f;
VertData[2]=0.0f;
VertData[3]=1.0f;
VertData[4]=800.0f;
VertData[5]=0.0f;
VertData[6]=0.0f;
VertData[7]=1.0f;
VertData[8]=800.0f;
VertData[9]=600.0f;
VertData[10]=0.0f;
VertData[11]=1.0f;
VertData[12]=0.0f;
VertData[13]=600.0f;
VertData[14]=0.0f;
VertData[15]=1.0f;
glBufferDataARB(GL_ARRAY_BUFFER_ARB, 4*4*sizeof(float),VertData, GL_STATIC_DRAW_ARB);
if( glGetError() != GL_NO_ERROR )
{
MessageBox(NULL,"Error!","VBO",MB_OK);
}
ShaderIndex=myWeaponShader->GetAttribIndexByName("Index");
//allways returns 1, as it should be?
if(ShaderIndex==-1)
{
MessageBox(NULL,"Index","Cant Find Attribute",MB_OK);
}
ShaderVertex=myWeaponShader->GetAttribIndexByName("Vertex");
//allways returns 2, as it should be?
if(ShaderVertex==-1)
{
MessageBox(NULL,"Vertex","Cant Find Attribute",MB_OK);
}
The glsl shader:
uniform vec4 Color[4];
attribute float Index;
attribute vec4 Vertex;
void main(void)
{
gl_FrontColor = Color[int(Index)];
gl_Position = gl_ModelViewProjectionMatrix * Vertex;
}
And heres the rendering:
glUseProgramObjectARB(ShaderObject);
glEnableVertexAttribArrayARB(ShaderIndex);
glEnableVertexAttribArrayARB(ShaderVertex);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, ShaderVBO);
glVertexAttribPointerARB(ShaderIndex, 1 , GL_FLOAT, false, 0, NULL);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, ShaderVertexVBO);
glVertexAttribPointerARB(ShaderVertex, 4 , GL_FLOAT, false, 0, NULL);
float TempColor[4];
TempColor[0]=0.0f;
TempColor[1]=0.0f;
TempColor[2]=0.0f;
glUniform4fvARB(ShaderColor[0], 4, TempColor);
TempColor[0]=1.0f;
TempColor[1]=1.0f;
TempColor[2]=0.0f;
glUniform4fvARB(ShaderColor[1], 4, TempColor);
TempColor[0]=0.0f;
TempColor[1]=1.0f;
TempColor[2]=0.0f;
glUniform4fvARB(ShaderColor[2], 4, TempColor);
TempColor[0]=0.0f;
TempColor[1]=0.0f;
TempColor[2]=1.0f;
glUniform4fvARB(ShaderColor[3], 4, TempColor);
glDrawArrays( GL_QUADS, 0, 4 );
glDisableVertexAttribArrayARB(ShaderIndex);
glDisableVertexAttribArrayARB(ShaderVertex);
glUseProgramObjectARB(0);
As you see what the shader should do is get the vertex color from the array. I cant seem to spot the error, any ideas?
[Edited by - Bouga on January 3, 2005 7:35:47 AM]