vbos and GLSL

Anyone know offhand if anything special is needed to set up vbos for sending to a vertex shader? I’ve got the following code:

void test()
{
//	glUseProgramObjectARB(NodeProgram);
	glEnableClientState(GL_VERTEX_ARRAY);
	glDrawElements(GL_LINES, ELEMENTS*24, GL_UNSIGNED_INT, BUFFER_OFFSET(0));
	glDisableClientState(GL_VERTEX_ARRAY);
}

Runs fine, but if I try to use the vertex shader instead, I get a black screen. The vertex shader in question is just:

void main()
{
	gl_Position = ftransform();
}

So nothing special. The vertex shader is set up correctly - I have fairly robust setup code for that. I suspect there is some state I’m not setting that lets the shader know that I’m sending in vbo data, but I couldn’t find it in the 1.5 or 2.0 spec, or the extension registry. Anyone know?

Thanks in advance.

No, you don´t have to do anything special, to use VBOs with vertex-shaders.

However, in your code, you use glDrawElements wrong. The last parameter should be a pointer to an array, which holds indices to the vertices you want to draw. The BUFFER_OFFSET shouldn´t be used there, it is used to setup the vertex-arrays.
Take another look into the VBO spec to check out how to use it properly.

Jan.

The indices are in a buffer object too. The BUFFER_OFFSET(0) refers to the indices. Like the “Vertex arrays using a mapped buffer object for array data and an unmapped buffer object for indices” example in the vbo spec except I’m using unmapped buffer objects for both vertices and indices. Anyway, like I said it works fine like that without the shader (with buffer object indices). Thanks, though.

GLSL does not care where the vertex arrays are defined -> there is no special call to be done when using vbos.
so your (shown)code is absolutely correct, but:

what are you actually trying to draw ? you maybe allready drawing it, but can’t see it.
make your background non-black. to see if you draw anything…(back objects on a black screen are hardly visible :wink: )
when you are using shaders, the official opengl-pipeline gets replaced by the vertexprogram or/and fragmentprogram specified in the shader.
if you don’t specifiy any vertex color, you’ll get “undefined colors”.
just try setting the vertexcolor in your shader.
(or simply passthrou the current color…)

your shader should be:

void main(void)
{ gl_Position = ftransform;
gl_FrontColor = gl_Color;
}

I’m an idiot. Thanks AdrianD. I’ve done that before and completely forgot. I spent an hour or so on that yesterday - no errors anywhere and I couldn’t figure out what was wrong. :rolleyes: There’s something to be said for glClearColor(0.0f, 0.0f, 1.0f, 1.0f).