openGL wrapper , vbo and shader location

Hi,

I’d like to use attributes to send other parameters than the more current one (normal, color, positions…) to send datas for a geometry shader. ex : Id like the give an info about velocity that could be different for each vertex.
So I’d like to used openGL the ways it is meant to be used in openGL 3 (my mac supports GL 2.1). I read the web page of openGL tutorial.

By reading the OF documentation, I found these usefull things to send custom attributes.
My question is :

What does the “int location” and “GLint location” refers to

vbo.setAttributeData(int location, const float *vert0x, int numCoords, int total, int usage);
shader.setAttribute1d(GLint location, double v1);

Normally, each type of attribute are stored in a GL buffer, and I can manipulate them using their buffer ID. if “location” refers to the bufferID, how can I have access to it knowing that ofVbo is a collection of the buffers I will use?
I didn’t found a method to get the specific buffer in the ofVbo Object.

Hope I’m clear enough :smiley:

I know that ofvbo is not so documented because it is meant to be used by people who have experience with openGL. But it makes things hard for those who have little knolage about it and what to do something with it.

cheers

Nico

you usually will use the vbo method, the location can be set before linking the shader using bindAttribute, like:

shader.setupShaderFromFile(GL_VERTEX_SHADER, "vertex.glsl");
shader.setupShaderFromFile(GL_FRAGMENT_SHADER, "frag.glsl");
shader.bindDefaults();
shader.bindAttribute("myCustomAttribute", 4);
shader.linkProgram();

bindDefaults, will bind the following default attributes that OF will send internally if the vbo has them:

0: position
1: color
2: normal
3: texcoord

so from 4 on (or less if you don’t have some of those) you can bind your own attributes.

if you are using openGL 3.3 with glsl 330 or more you can also do this directly in the vertex shader:

layout(location = 0) in vec3 position;
layout(location = 1) in vec4 texcoord;
layout(location = 2) in float pointsize;

and then when you want to upload the pointsize for example:

vbo.setAttributeData(2, data, 1, total, GL_STATIC_DRAW);

or:

vbo.setAttributeData(shader.getAttributeLocation("pointsize"), data, 1, total, GL_STATIC_DRAW);

you can also allocate an ofBufferObject and upload the data to it then bind it to the vbo in a similar way using setAttributeBuffer instead of setAttributeData

1 Like

In my case I’m limited to opengl2.1

So it will be something like :

setup(){
shader.load("verts.c", "frag.c");
shader.bindDefaults();
shader.bindAttribute("myCustomAttribute", 4);
shader.linkProgram();
vbo.setAttributeData(shader.getAttributeLocation("myCustomAttribute"), data, 1, total, GL_STATIC_DRAW);
}

draw(){

shader.begin();
vbo.draw(GL_LINES, 0, total);
shader.end();

}

and if I use a dynamic buffer :

      setup(){
            shader.load("verts.c", "frag.c");
            shader.bindDefaults();
            shader.bindAttribute("myCustomAttribute", 4);
            shader.linkProgram();
       }

    draw(){
       vbo.setAttributeData(shader.getAttributeLocation("myCustomAttribute"), data, 1, total, GL_DYNAMIC_DRAW);
       shader.begin();
       vbo.draw(GL_LINES, 0, total);
       shader.end();
    }

and the shader will begin with

#version 120

attribute float myCustomAttribute

main(){
_//do things with gl_position, myCustomAttribute ..._
}

I do really have problems with openGLs methodology, It’s even worse because my openGL version is to 2.1, and this is the methodologie of 3.3 :frowning:

what OS are you using? it’s really strange that you’d only have support for 2.1 even really old macs should support at least 3.3

The last OSX on a 2 years old computer.
I’ve just made a test, apparently its GL 4.something.
Curiously, last year I made a test in order to use an addon, and OF warned me I was limited to GL 2.1. Since this day I do everything in GL2.1.

I’ll try what you’ve told me concerning the use of attributes. I’ll see if it works.

in any case what you posted should work in 2.1 too

Thanks a lot ! :slight_smile:
By the way, most of my posts concerns parts of the documentation that are not very documented, or subjets that might interess many beginners in GL and DSP. I wish I could improve them myself but I do not feel experimented enought to pretend having the best methodology.
Is there something that the “OF team” can do about it ?

ex :


there’s a lot of effort put in making the docs better but it’s really a lot of work and it never seems complete. the best is to look at the examples or search the forum and if you can’t find the exact thing don’t be afraid to ask.

also if you think you have understood some part any contribution to the docs is always welcome