Passing ofVec2 array to fragment Shader


#1

Hello everybody !

Im trying to use the function ofShader::setAttribute2fv , of the ofShader class to pass an ofvec2f array to the fragment shader.

but when I put :

shaders[drogaActiva].setUniform2fv("manoder", &manoder_pos);

or

shaders[drogaActiva].setUniform2fv("manoder", manoder_pos);

where manoder_pos is my vec2f array, I get an error. Can someone give me an example on how to correctly use the function?


#2

Hello Julian, what is manoder_pos? which error are you having?
if you simply want to pass a 2D position (a glm::vec2, or a vec2f, or x and y coord), you can:

shader.setUniform2f("position", manoder_pos.x, manoder_pos.y);

If manoder_pos is an array of positions, then you have to pass the data to the shaders using a texture.


#3

&manoder[0]


#4

Yes. It is actually an array.

But the array holds the X and Y of hand position of different people taken by the kinect.

Using a texture to pass de data is way to complicated for only passing a few values. In any case, would you have a simple tutorial on how to pass the data as a texture ?

I´ve been trying to accoplish passing the values over a texture a fail to do it. And the codes that i´ve found are way to difficult for me to understand it. I don´t understand how to acces to each value in the fragment shader, and how to use each value of the texture.


#5

That´s works when i have to use one dimensional array.

When I pass the values using "setUniform1fv " it works, but only for one dimensional array.

but when i want to pass the array holding the vectors (Each one with X and Y positions) using the function .
“setUniform2fV” it won´t work. I get :

Severity	Code	Description	Project	File	Line	Suppression State
Error (active)	E0167	argument of type "ofVec2f *" is incompatible with parameter of type "const float *"	RatParkV1	c:\WORKSPACE\of_v0.9.8_vs_release\apps\myApps\RatParkV1\src\ofApp.cpp	531	

This is the line of code that Im using for passing the array of ofVec2f to the shader :

shaders[drogaActiva].setUniform2fv("manoderA", &manoder_pos[0]);

Im going to try to pass each coordinate in one separate array (one for the x, and one for the Y) using
setUniform1fV.

But anyway I still don´t know how to use the function "setUniform2fv " , it is supposed to recibe an array of vectors or what is it for?


#6

using setUniform2fv you can effectively pass an array of vectors:

shader.setUniform3fv("manoderA", &manoder_pos[0].x, manoder.size() * 2);

and in your shader:

uniform float manoderA[MANODER_SIZE];

take into account that MANODER_SIZE has to be a constant and the same size as what you pass using setUniform2fv.

In general most gl calls in low level objects like ofShader or ofVao are equivalent to their gl counterparts. just remove the set and add gl as in glUniform2fv:

https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glUniform.xhtml