Quantcast
Viewing all articles
Browse latest Browse all 40524

How to send an array to a shader frag on oF0.9.0

Hi, forum.

I'm trying to understand how to send an array to a shader frag.

I want to send float array to frag. but i couldn't.
I wrote follows In the ofApp:

void ofApp::draw(){

    myArray[0] = 1.0;
    myArray[1] = 0.0;
    myArray[2] = 0.0;

    printf("%f \n", myArray[0]); //  1.0

    shader.load("","shader.frag");
    shader.begin();
    shader.setUniform1fv("uniArray", myArray, 3);
    ofRect(0,0,ofGetWidth(), ofGetHeight());
    shader.end();
}

in the frag.

uniform float uniArray[3];

void main() {
    gl_FragColor = vec4(uniArray[0], uniArray[1], uniArray[2], 1.0); // uniArray[0] seems not to be 1.0; 
}

I expected red rect is drawn. but it was black.

When I use setUniform3f and an vec3 instead of an array, A red rect is drawn.

What went wrong?

thanks.


Viewing all articles
Browse latest Browse all 40524

Trending Articles