Bug fixes and UI improvements for cmodview:

- Fixed background colors in material editor
- Correctly show opacity in OGL 2 path
- Fixed texturing problems that occurred when switching from OGL 2 to FF path
- Fixed highlight color in OGL 2 path
sensor-dev
Chris Laurel 2010-02-21 00:42:30 +00:00
parent 259477ae22
commit 9f1229c4d3
5 changed files with 67 additions and 14 deletions

View File

@ -72,7 +72,7 @@ INCLUDEPATH += ../../../thirdparty/glew/include
macx {
DEFINES += TARGET_OS_MAC
QMAKE_MAC_SDK = /Developer/SDKs/MacOSX10.5.sdk
CONFIG += x86
CONFIG += x86 ppc
}
win32-g++ {

View File

@ -400,6 +400,13 @@ MainWindow::openModel(const QString& fileName)
return;
}
// Automatically uniquify vertices
for (unsigned int i = 0; model->getMesh(i) != NULL; i++)
{
Mesh* mesh = model->getMesh(i);
UniquifyVertices(*mesh);
}
setModel(fileName, model);
}
else if (info.suffix().toLower() == "cmod")

View File

@ -19,7 +19,7 @@ using namespace cmod;
static QColor toQtColor(const Material::Color& color)
{
return QColor((int) (color.red()) * 255.99f, (int) (color.green() * 255.99f), (int) (color.blue() * 255.99f));
return QColor((int) (color.red() * 255.99f), (int) (color.green() * 255.99f), (int) (color.blue() * 255.99f));
}
static Material::Color fromQtColor(const QColor& color)
@ -184,7 +184,7 @@ MaterialWidget::setMaterial(const Material& material)
void
MaterialWidget::editDiffuse()
{
QColorDialog dialog(this);
QColorDialog dialog(toQtColor(m_material.diffuse), this);
connect(&dialog, SIGNAL(currentColorChanged(QColor)), this, SLOT(setDiffuse(QColor)));
dialog.exec();
}
@ -193,7 +193,7 @@ MaterialWidget::editDiffuse()
void
MaterialWidget::editSpecular()
{
QColorDialog dialog(this);
QColorDialog dialog(toQtColor(m_material.specular), this);
connect(&dialog, SIGNAL(currentColorChanged(QColor)), this, SLOT(setSpecular(QColor)));
dialog.exec();
}
@ -202,7 +202,7 @@ MaterialWidget::editSpecular()
void
MaterialWidget::editEmissive()
{
QColorDialog dialog(this);
QColorDialog dialog(toQtColor(m_material.emissive), this);
connect(&dialog, SIGNAL(currentColorChanged(QColor)), this, SLOT(setEmissive(QColor)));
dialog.exec();
}

View File

@ -156,7 +156,8 @@ ModelViewWidget::ModelViewWidget(QWidget *parent) :
m_renderStyle(NormalStyle),
m_renderPath(FixedFunctionPath),
m_materialLibrary(NULL),
m_lightOrientation(Quaterniond::Identity())
m_lightOrientation(Quaterniond::Identity()),
m_lightingEnabled(true)
{
setupDefaultLightSources();
}
@ -646,6 +647,21 @@ getGLMode(Mesh::PrimitiveGroupType primitive)
static bool gl2Fail = false;
void
ModelViewWidget::setLighting(bool enable)
{
m_lightingEnabled = enable;
if (m_lightingEnabled)
{
glEnable(GL_LIGHTING);
}
else
{
glDisable(GL_LIGHTING);
}
}
void
ModelViewWidget::bindMaterial(const Material* material)
{
@ -654,11 +670,13 @@ ModelViewWidget::bindMaterial(const Material* material)
if (renderPath() == OpenGL2Path && !gl2Fail)
{
// Lookup the shader in the shader cache
unsigned int shaderKey = computeShaderKey(material, m_lightSources.size());
unsigned lightSourceCount = m_lightingEnabled ? m_lightSources.size() : 0;
unsigned int shaderKey = computeShaderKey(material, lightSourceCount);
shader = m_shaderCache.value(shaderKey);
if (!shader)
{
shader = createShader(material, m_lightSources.size());
shader = createShader(material, lightSourceCount);
if (shader)
{
m_shaderCache.insert(shaderKey, shader);
@ -821,6 +839,15 @@ ModelViewWidget::renderModel(Model* model)
glPolygonMode(GL_FRONT, GL_FILL);
}
// Disable all texture units
for (unsigned int i = 0; i < 8; ++i)
{
glActiveTexture(GL_TEXTURE0 + i);
glDisable(GL_TEXTURE_2D);
}
glActiveTexture(GL_TEXTURE0);
// Render all meshes
for (unsigned int meshIndex = 0; meshIndex < model->getMeshCount(); ++meshIndex)
{
const Mesh* mesh = model->getMesh(meshIndex);
@ -828,11 +855,11 @@ ModelViewWidget::renderModel(Model* model)
setVertexArrays(mesh->getVertexDescription(), mesh->getVertexData());
if (mesh->getVertexDescription().getAttribute(Mesh::Normal).format == Mesh::Float3)
{
glEnable(GL_LIGHTING);
setLighting(true);
}
else
{
glDisable(GL_LIGHTING);
setLighting(false);
}
for (unsigned int groupIndex = 0; groupIndex < mesh->getGroupCount(); ++groupIndex)
@ -849,6 +876,8 @@ ModelViewWidget::renderModel(Model* model)
glDrawElements(primitiveMode, group->nIndices, GL_UNSIGNED_INT, group->indices);
}
}
bindMaterial(&defaultMaterial);
}
@ -857,13 +886,21 @@ ModelViewWidget::renderSelection(Model* model)
{
glEnable(GL_CULL_FACE);
glPolygonMode(GL_FRONT, GL_LINE);
glDisable(GL_LIGHTING);
setLighting(false);
glDisable(GL_TEXTURE_2D);
glColor4f(0.0f, 1.0f, 0.0f, 0.5f);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDepthMask(GL_FALSE);
if (renderPath() == OpenGL2Path)
{
Material selectionMaterial;
selectionMaterial.diffuse = Material::Color(0.0f, 1.0f, 0.0f);
selectionMaterial.opacity = 0.5f;
bindMaterial(&selectionMaterial);
}
for (unsigned int meshIndex = 0; meshIndex < model->getMeshCount(); ++meshIndex)
{
Mesh* mesh = model->getMesh(meshIndex);
@ -934,10 +971,11 @@ ModelViewWidget::createShader(const Material* material, unsigned int lightSource
/*** Fragment shader ***/
fout << "uniform vec3 diffuseColor;\n";
fout << "uniform float opacity;\n";
fout << "void main(void)\n";
fout << "{\n";
fout << " vec3 baseColor(0.0, 1.0, 0.0);\n";
fout << " gl_FragColor = vec4(baseColor, 1.0);\n";
fout << " gl_FragColor = vec4(diffuseColor, opacity);\n";
fout << "}\n";
/*** End fragment shader ***/
}
@ -1070,7 +1108,7 @@ ModelViewWidget::createShader(const Material* material, unsigned int lightSource
fout << " color += texture2D(emissiveMap, texCoord).xyz;\n";
}
fout << " gl_FragColor = vec4(color, 1.0);\n";
fout << " gl_FragColor = vec4(color, opacity);\n";
fout << "}\n";
/*** End fragment shader ***/

View File

@ -88,6 +88,11 @@ public:
float intensity;
};
bool isLightingEnabled() const
{
return m_lightingEnabled;
}
signals:
void selectionChanged();
@ -95,6 +100,7 @@ public slots:
void setBackgroundColor(const QColor& color);
void setRenderPath(RenderPath path);
void setRenderStyle(RenderStyle style);
void setLighting(bool enable);
protected:
void initializeGL();
@ -128,6 +134,8 @@ private:
QList<LightSource> m_lightSources;
Eigen::Quaterniond m_lightOrientation;
bool m_lightingEnabled;
};
#endif // _CMODVIEW_MODEL_VIEW_WIDGET_H_