在OpenGL和GLSL之间传递变量

 假设一个shader中使用了如下变量:

uniform float specIntensity;  
uniform vec4 specColor;  
uniform float t[2];  
uniform vec4 colors[3];  

 

在OpenGL程序中可以使用下面的代码设置这些变量:

GLint loc1,loc2,loc3,loc4;  
float specIntensity = 0.98;  
float sc[4] = {0.8,0.8,0.8,1.0};  
float threshold[2] = {0.5,0.25};  
float colors[12] = {0.4,0.4,0.8,1.0,  
                0.2,0.2,0.4,1.0,  
                0.1,0.1,0.1,1.0};  
  
loc1 = glGetUniformLocation(p,"specIntensity");  
glUniform1f(loc1,specIntensity);  
  
loc2 = glGetUniformLocation(p,"specColor");  
glUniform4fv(loc2,1,sc);  
  
loc3 = glGetUniformLocation(p,"t");  
glUniform1fv(loc3,2,threshold);  
  
loc4 = glGetUniformLocation(p,"colors");  
glUniform4fv(loc4,3,colors);  


 

你可能感兴趣的:(float,shader,colors)