fixed backface culling bug,
todo: connect headligh
This commit is contained in:
parent
538453c1db
commit
fbb51563c9
@ -530,9 +530,6 @@
|
||||
<property name="text">
|
||||
<string>Backface Culling</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -36,7 +36,7 @@ private:
|
||||
void clearData();
|
||||
|
||||
public:
|
||||
void drawGeometry(QOpenGLShaderProgram *program, bool wireframe);
|
||||
void drawGeometry(QOpenGLShaderProgram *program);
|
||||
void loadFile(QString filePath);
|
||||
|
||||
// signals
|
||||
|
@ -27,6 +27,7 @@ private:
|
||||
|
||||
bool m_wireframe = false;
|
||||
bool m_lightOn = false;
|
||||
bool m_backfaceCulling = false;
|
||||
|
||||
struct {
|
||||
QVector4D position = { 1,1,1,0 };
|
||||
|
@ -51,7 +51,7 @@ void GeometryEngine::clearData()
|
||||
m_drawList.clear();
|
||||
}
|
||||
|
||||
void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program, bool wireframe)
|
||||
void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
|
||||
{
|
||||
if (!m_arrayBuf.isCreated() || !m_indexBuf.isCreated())
|
||||
return;
|
||||
@ -133,12 +133,8 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program, bool wireframe)
|
||||
program->setUniformValue("materialSpecularColor", specularColor);
|
||||
|
||||
// Draw cube geometry using indices from VBO 1
|
||||
if (wireframe)
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, it.size, GL_UNSIGNED_INT, (void*)(it.offset * sizeof(GLuint)));
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ void OglViewerWidget::initializeGL()
|
||||
|
||||
//TODO: does not work
|
||||
// Enable back face culling
|
||||
glEnable(GL_CULL_FACE);
|
||||
//glEnable(GL_CULL_FACE);
|
||||
|
||||
// Enable transparency
|
||||
glEnable(GL_BLEND);
|
||||
@ -164,7 +164,16 @@ void OglViewerWidget::paintGL()
|
||||
m_program.setUniformValue("cameraPosition", rotateBack * (-m_translation));
|
||||
|
||||
// Draw cube geometry
|
||||
m_dataEngine->drawGeometry(&m_program, m_wireframe);
|
||||
if (m_backfaceCulling)
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
if (m_wireframe)
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
|
||||
m_dataEngine->drawGeometry(&m_program);
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
}
|
||||
|
||||
// Inputs ///////////////////////////////////////////////////////////////
|
||||
@ -410,11 +419,7 @@ void OglViewerWidget::setAmbCoef(double value)
|
||||
|
||||
void OglViewerWidget::setBackfaceCulling(bool value)
|
||||
{
|
||||
if (value)
|
||||
glCullFace(GL_FRONT_AND_BACK);
|
||||
else if(!value)
|
||||
glCullFace(GL_FRONT);
|
||||
|
||||
m_backfaceCulling = value;
|
||||
update();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user