PDA

View Full Version : Combining different coord-array (eg. x[n] & y[n])



andyGL
07-03-2009, 08:38 AM
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

DmitryM
07-07-2009, 10:02 AM
You can always use both arrays as vertex attributes and compute gl_Position (in GLSL) easily in vertex shader using them.

Dark Photon
07-08-2009, 05:13 AM
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?
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.

andyGL
10-23-2009, 01:39 AM
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

DmitryM
10-23-2009, 07:41 AM
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);
}

andyGL
10-25-2009, 03:52 PM
Thanks a lot for the hint, i will dive now in the glsl..