完成主要交互、高性能组件、国际化和A型传感器数据包接收
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
class Shader {
|
||||
public:
|
||||
@@ -13,6 +15,7 @@ public:
|
||||
unsigned int ID;
|
||||
// 构造器读取并构建着色器
|
||||
Shader(const char* vertexPath, const char* fragmentPath) {
|
||||
std::cout << "begin compile [" << vertexPath << "] and [" << fragmentPath << "] !" << std::endl;
|
||||
std::string vertexCode;
|
||||
std::string fragmentCode;
|
||||
std::ifstream vShaderFile;
|
||||
@@ -70,13 +73,18 @@ public:
|
||||
glLinkProgram(ID);
|
||||
glGetProgramiv(ID, GL_LINK_STATUS, &success);
|
||||
if (!success) {
|
||||
glGetShaderInfoLog(ID, 512, NULL, infoLog);
|
||||
glGetProgramInfoLog(ID, 512, NULL, infoLog);
|
||||
std::cout << "ERROR::SHADER::PROGRAM::LINKING_FAILED\n" << infoLog << std::endl;
|
||||
}
|
||||
|
||||
glDeleteShader(vertex);
|
||||
glDeleteShader(fragment);
|
||||
}
|
||||
~Shader() {
|
||||
if (ID) {
|
||||
glDeleteProgram(ID);
|
||||
}
|
||||
}
|
||||
// 使用/激活程序
|
||||
void use() {
|
||||
glUseProgram(ID);
|
||||
@@ -91,4 +99,13 @@ public:
|
||||
void setFloat(const std::string& name, float value) const {
|
||||
glUniform1f(glGetUniformLocation(ID, name.c_str()), value);
|
||||
}
|
||||
void setVec2(const std::string& name, const glm::vec2& value) const {
|
||||
glUniform2fv(glGetUniformLocation(ID, name.c_str()), 1, glm::value_ptr(value));
|
||||
}
|
||||
void setVec3(const std::string& name, const glm::vec3& value) const {
|
||||
glUniform3fv(glGetUniformLocation(ID, name.c_str()), 1, glm::value_ptr(value));
|
||||
}
|
||||
void setMat4(const std::string& name, const glm::mat4& value) const {
|
||||
glUniformMatrix4fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, glm::value_ptr(value));
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user