我正在尝试通过顶点而不是统一发送矩阵,以便程序更快一些。问题是我的对象没有出现,我不明白为什么。对于顶点和颜色,我总是这样做,它始终有效。
这是代码:
GLuint _mbo[4];
_camera->getMatricies(projection, view, model);
glm::vec4 column0 = glm::column(view, 0);
glm::vec4 column1 = glm::column(view, 1);
glm::vec4 column2 = glm::column(view, 2);
glm::vec4 column3 = glm::column(view, 3);
std::cerr << glm::to_string(column0) << std::endl;
glGenBuffers(1, &_mbo[0]);
glBindBuffer(GL_ARRAY_BUFFER, _mbo[0]);
glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(GLfloat), &column0[0], GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
std::cerr << glm::to_string(column1) << std::endl;
glGenBuffers(1, &_mbo[1]);
glBindBuffer(GL_ARRAY_BUFFER, _mbo[1]);
glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(GLfloat), &column1[0], GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
std::cerr << glm::to_string(column2) << std::endl;
glGenBuffers(1, &_mbo[2]);
glBindBuffer(GL_ARRAY_BUFFER, _mbo[2]);
glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(GLfloat), &column2[0], GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
std::cerr << glm::to_string(column3) << std::endl;
glGenBuffers(1, &_mbo[3]);
glBindBuffer(GL_ARRAY_BUFFER, _mbo[3]);
glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(GLfloat), &column3[0], GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
.....
glBindBuffer(GL_ARRAY_BUFFER, _mbo[0]);
glEnableVertexAttribArray(matId);
glVertexAttribPointer(matId, 4, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, _mbo[1]);
glEnableVertexAttribArray(matId + 1);
glVertexAttribPointer(matId + 1, 4, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, _mbo[2]);
glEnableVertexAttribArray(matId + 2);
glVertexAttribPointer(matId + 2, 4, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, _mbo[3]);
glEnableVertexAttribArray(matId + 3);
glVertexAttribPointer(matId + 3, 4, GL_FLOAT, GL_FALSE, 0, 0);
顶点着色器:
#version 100
attribute vec3 position;
attribute vec3 color;
attribute vec2 texcoord;
attribute mat4 view;
varying vec3 vColor;
varying vec2 vTex;
uniform mat4 projection;
//uniform mat4 view;
uniform mat4 model;
varying vec2 v_uv;
void main(){
// mat4 test;
// test[0] = vec4(1.0, 0.0, 0.0, 0.0);
// test[1] = vec4(0.0, 1.0, 0.0, 0.0);
// test[2] = vec4(0.0, 0.0, 1.0, 0.0);
// test[3] = vec4(0.0, 0.0, 0.0, 1.0);
gl_Position = projection * view * model * vec4(position, 1.0);
vColor = color;
vTex = texcoord;
}
我无法确定问题是否出现在着色器中......这对我来说非常令人沮丧。