c_cpp 设置GLSL制服

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 设置GLSL制服相关的知识,希望对你有一定的参考价值。

#include <glad/glad.h>
#include <glm/glm.hpp>

// Get the location of a uniform with name and shader id.
glGetUniformLocation(GLuint id, char *name);

// Prototypes for setting uniforms.
glUniform1i(GLuint location, GLint value);                      
glUniform1f(GLuint location, GLfloat value);                  
glUniform2f(GLuint location, GLfloat x, GLfloat y);           
glUniform3f(GLuint location, GLfloat x, GLfloat y, GLfloat z); 
glUniform4f(GLuint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
glUniformMatrix4fv(GLuint location, 1, GL_FALSE, glm::value_ptr(matrix));
#include <glad/glad.h>

GLuint id; // Shader ID set somewhere else.

void setInteger(const GLchar *name, GLint value, GLboolean useShader)
{
    if (useShader)
        glUseProgram(id);
    glUniform1i(glGetUniformLocation(id, name), value);
}

以上是关于c_cpp 设置GLSL制服的主要内容,如果未能解决你的问题,请参考以下文章

创建一个 GLSL 制服数组?

GLSL:无法获取制服位置

ThreeJS 预定义着色器属性/制服

c_cpp 加载GLSL着色器

GLSL统一布局绑定和纹理

如何绕过 glsl 统一数组大小限制? [复制]