Ok, now with the help of some other forums & online material, I’ve got a bit further. Now the actual problem is sending the attributes as arrays from a VBO. I’ve written a little test shader to keep things simple until I solve this problem. Heres what I have so far for the test:
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
//that is if i use just plain old glVertex3f & glColor to pass the index
glAttachObjectARB(ShaderObject, ProgramObject);
glLinkProgramARB(ShaderObject);
for(int i=0;i<4;i++)
{
char txt[256];
sprintf(txt,"Color[%i]",i);
ShaderColor[i]=glGetUniformLocationARB(ShaderObject, txt);
if(ShaderColor[i]==-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);
Can You spot what am I missing here? As You can see, it should just draw a quad all over the screen using the atrribute Vertex as the vertex position, and the attribyte Index to get a color from the uniform array. Which does work if rewrite to use glVertex for position and glColor for passing the index, but i cant get it to work with VBO (or arrays, for that matter).