4

I'm currently playing around with glsl. For that purpose i need to pass an array from the opengl code to the gsls, which then in return calculates a new color out of the array. But somehow this doesn't work for me. Instead of getting the whole array I'm always stuck with only the first entry. Could you help me by saying what I'm doing wrong?

import numpy as np
\\...
array = np.array([1.2,2.5,3.8,4.3,5.6, #....])
location = glGetUniformLocation(program,"arrayInShader")
glUniform1fv(location,1,array)

and in the shader:

uniform float arrayInShader[5];
varying vec3 color;
void main()
{
    color.r=arrayInShader[0]+arrayInShader[1];
    color.g=arrayInShader[2];
    color.b=arrayInShader[3]+arrayInShader[4];
}

Thanks a lot guys!

Donny
  • 549
  • 2
  • 10
  • 24

1 Answers1

6

The second parameter of glUniform*v is the count. The number of elements to upload. You say that you're only loading 1 float into the array, so OpenGL only loads one float into the array.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • As far as I have understood that count, it specifies how many arrays/vectors you are passing to the shader at the same time, isn't it? – Donny Aug 16 '11 at 08:49
  • I tried that out, and actually it works. I'm sorry for that silly question then, but I was quite sure i read that this is a major mistake many people do. So i literally never tried to change that! – Donny Aug 16 '11 at 08:57
  • 1
    @Donny You are partly right about the count. It says how many basic elements you upload. In this case these elements are single floats and you want 5 of them. If you would have used glUniform4fv and a vec4 uniform, then you would have uploaded 20 floats with a count parameter of 5. – Christian Rau Aug 16 '11 at 13:04