Combining different coord-array (eg. x[n] & y[n])

Hi,

i am now looking for following solution regarding a 2D application:

there is one array of doubles:
x[n]
and another array of doubles
y[n]

is there any posibility to combine these two pointers, so that glDrawArray(…) can draw the combined vertex information?

Thanks,

andy

PS.: this could be a better workaround for my last post:
Decreasing precision of increasing vertex ranges

You can always use both arrays as vertex attributes and compute gl_Position (in GLSL) easily in vertex shader using them.

Sure. You can send this as separate vertex attribute arrays, interleaved vertex attribute arrays, or combine these into a 2-element vector to send as a single vertex attribute array.

Hi Photon, i am searching again for a solution.

the posibilitys you wrote reffering, as far as i understood, to the glVertexAttribPointer function of the shader language.

But it seems that the glVertexAttribPointer is operatting for each vertex component (position, color, tex …) it selfe, but not for the single components of them (x,y,z, r,g,b,a …).

Maybe you can give me an hint or a small code snippet that I can start.

Thanks

andy

First, glVertexAttribPointer is GL function (not ‘of the shader language’).

It allows you to say what attributes you use and where are they stored. OpenGL doesn’t care about their meaning at all.

So, based on that, you can tell GL the following:
Attrib-0: name=‘pos_x’, data=x
Attrib-1: name=‘pos_y’, data=y

In the vertex shader:


in float pos_x;
in float pos_y;

void main() {
   gl_Position = vec4(pos_x,pos_y,0.0,1.0);
}

Thanks a lot for the hint, i will dive now in the glsl…