Hello,
I have design an rendering an mesh object and a point. Here is the code I use:
void RenderingEngine::RenderShaded(Model *model, GLenum polyonMode,
bool drawAll, bool use_position_color,
bool need_to_finish) {
glViewport(0, 0, width_, height_);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
if (model->IsInitialized() || drawAll) {
Matx44f pose = model->GetPose();
Matx44f modelViewMatrix = lookAtMatrix_ * pose;
Matx33f normalMatrix = modelViewMatrix.get_minor<3, 3>(0, 0).inv().t();
Matx44f modelViewProjectionMatrix = projectionMatrix_ * modelViewMatrix;
phongblinn_shader_program_->bind();
phongblinn_shader_program_->setUniformValue(
"uMVMatrix", QMatrix4x4(modelViewMatrix.val));
phongblinn_shader_program_->setUniformValue(
"uMVPMatrix", QMatrix4x4(modelViewProjectionMatrix.val));
phongblinn_shader_program_->setUniformValue("uNormalMatrix",
QMatrix3x3(normalMatrix.val));
phongblinn_shader_program_->setUniformValue("uLightPosition1",
QVector3D(10, 10, -20));
phongblinn_shader_program_->setUniformValue("uLightPosition2",
QVector3D(-10, 10, -20));
phongblinn_shader_program_->setUniformValue("uLightPosition3",
QVector3D(0.0, 0.0, 10));
phongblinn_shader_program_->setUniformValue("uShininess", 100.1f);
phongblinn_shader_program_->setUniformValue("uAlpha", 0.1f);
glPolygonMode(GL_FRONT_AND_BACK, polyonMode);
if (polyonMode == GL_POINT) {
glPointSize(2);
model->Draw(phongblinn_shader_program_, use_position_color, GL_POINTS);
} else {
model->Draw(phongblinn_shader_program_, use_position_color);
}
}
if (need_to_finish) glFinish();
}
void RenderingEngine::RenderExternalElementShaded(
cv::Matx44f &pose, GLenum polyonMode, QOpenGLBuffer &vertex_buffer,
QOpenGLBuffer &color_buffer, int element_size, bool need_to_finish) {
Matx44f modelViewMatrix = lookAtMatrix_ * pose;
Matx33f normalMatrix = modelViewMatrix.get_minor<3, 3>(0, 0).inv().t();
Matx44f modelViewProjectionMatrix = projectionMatrix_ * modelViewMatrix;
phongblinn_shader_program_->bind();
phongblinn_shader_program_->setUniformValue("uMVMatrix",
QMatrix4x4(modelViewMatrix.val));
phongblinn_shader_program_->setUniformValue(
"uMVPMatrix", QMatrix4x4(modelViewProjectionMatrix.val));
phongblinn_shader_program_->setUniformValue("uNormalMatrix",
QMatrix3x3(normalMatrix.val));
phongblinn_shader_program_->setUniformValue("uLightPosition1",
QVector3D(10, 10, -20));
phongblinn_shader_program_->setUniformValue("uLightPosition2",
QVector3D(-10, 10, -20));
phongblinn_shader_program_->setUniformValue("uLightPosition3",
QVector3D(0.0, 0.0, 10));
phongblinn_shader_program_->setUniformValue("uShininess", 100.1f);
phongblinn_shader_program_->setUniformValue("uAlpha", 0.1f);
glPolygonMode(GL_FRONT_AND_BACK, polyonMode);
vertex_buffer.bind();
phongblinn_shader_program_->enableAttributeArray("aPosition");
phongblinn_shader_program_->setAttributeBuffer("aPosition", GL_FLOAT, 0, 3,
sizeof(Vec3f));
color_buffer.bind();
phongblinn_shader_program_->enableAttributeArray("aColor");
phongblinn_shader_program_->setAttributeBuffer("aColor", GL_FLOAT, 0, 3,
sizeof(Vec3f));
glPointSize(60);
glDrawElements(GL_POINTS, element_size, GL_UNSIGNED_INT, 0);
if (need_to_finish) {
glFinish();
}
}
Here is the result I have:
First the white element should be a sphere, I don’t understand why the shader generates a square.
Then I want the sphere to be above the mesh, what should I do?