void ModelViewGadgetWidget::resizeGL(int width, int height) { m_GlView.setWinGLSize(width, height); // Compute window aspect ratio // OpenGL error handler { GLenum error = glGetError(); if (error != GL_NO_ERROR) { GLC_OpenGlException OpenGlException("ModelViewGadgetWidget::resizeGL() ", error); throw(OpenGlException); } } }
void ExtFrameBuffer::check_status() const { GLuint status; status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { EL_THROW_EXCEPTION(OpenGlException() << errinfo_message(get_status_str(status)) << errinfo_opengl_error(status)); } }
void GLC_Line::glDraw(const GLC_RenderProperties&) { // Point Display glBegin(GL_LINES); glVertex3dv(m_Point1.data()); glVertex3dv(m_Point2.data()); glEnd(); // OpenGL error handler GLenum error= glGetError(); if (error != GL_NO_ERROR) { GLC_OpenGlException OpenGlException("GLC_Line::GlDraw ", error); throw(OpenGlException); } }
void ModelViewGadgetWidget::paintGL() { try { // Clear screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // OpenGL error handler { GLenum error = glGetError(); if (error != GL_NO_ERROR) { GLC_OpenGlException OpenGlException("ModelViewGadgetWidget::paintGL() ", error); throw(OpenGlException); } } // Load identity matrix glLoadIdentity(); // Enable antialiasing glEnable(GL_MULTISAMPLE); // Calculate camera depth of view m_GlView.setDistMinAndMax(m_World.boundingBox()); // define view matrix m_Light.glExecute(); m_GlView.glExecuteCam(); // Display the collection of GLC_Object m_World.render(0, glc::ShadingFlag); m_World.render(0, glc::TransparentRenderFlag); // Display UI Info (orbit circle) m_MoverController.drawActiveMoverRep(); } catch(GLC_Exception &e) { qDebug() << e.what(); } }
// Geometry display void GLC_Geometry::render(const GLC_RenderProperties& renderProperties) { Q_ASSERT(!m_IsWire || (m_IsWire && m_MaterialHash.isEmpty())); bool renderWire= (renderProperties.renderingFlag() == glc::TransparentRenderFlag) && isTransparent(); renderWire= renderWire || ((renderProperties.renderingFlag() != glc::TransparentRenderFlag) && !isTransparent()); if (!m_IsWire || renderWire) { if (m_MaterialHash.isEmpty() && !m_IsWire) { GLC_Material* pMaterial= new GLC_Material(); pMaterial->setName(name()); addMaterial(pMaterial); } m_IsSelected= renderProperties.isSelected(); // Define Geometry's property if(!GLC_State::isInSelectionMode()) { glPropGeom(renderProperties); } glDraw(renderProperties); m_IsSelected= false; m_GeometryIsValid= true; // OpenGL error handler GLenum error= glGetError(); if (error != GL_NO_ERROR) { GLC_OpenGlException OpenGlException("GLC_Geometry::glExecute " + name(), error); throw(OpenGlException); } } }
void GLC_Light::glExecute() { GLC_Context* pCurrentContext= GLC_ContextManager::instance()->currentContext(); Q_ASSERT(NULL != pCurrentContext); if (NULL == m_pContext) { m_pContext= pCurrentContext; addNewLight(); } pCurrentContext->glcEnableLighting(true); pCurrentContext->glcEnableLight(m_LightID); if (m_pContext != pCurrentContext) { Q_ASSERT(QOpenGLContext::areSharing(m_pContext->contextHandle(), pCurrentContext->contextHandle())); } Q_ASSERT(m_pContext->contextHandle()->isValid()); GLfloat setArray[4]; // Position setArray[0]= static_cast<GLfloat>(m_Position.x()); setArray[1]= static_cast<GLfloat>(m_Position.y()); setArray[2]= static_cast<GLfloat>(m_Position.z()); if (LightDirection == m_LightType) { setArray[3]= 0.0f; glLightfv(m_LightID, GL_POSITION, setArray); // Direction of the Light } else { setArray[3]= 1.0f; glLightfv(m_LightID, GL_POSITION, setArray); // Position of the Light } // Set the lighting model pCurrentContext->glcSetTwoSidedLight(m_TwoSided); // Color setArray[0]= static_cast<GLfloat>(m_AmbientColor.redF()); setArray[1]= static_cast<GLfloat>(m_AmbientColor.greenF()); setArray[2]= static_cast<GLfloat>(m_AmbientColor.blueF()); setArray[3]= static_cast<GLfloat>(m_AmbientColor.alphaF()); glLightfv(m_LightID, GL_AMBIENT, setArray); // Setup The Ambient Light setArray[0]= static_cast<GLfloat>(m_DiffuseColor.redF()); setArray[1]= static_cast<GLfloat>(m_DiffuseColor.greenF()); setArray[2]= static_cast<GLfloat>(m_DiffuseColor.blueF()); setArray[3]= static_cast<GLfloat>(m_DiffuseColor.alphaF()); glLightfv(m_LightID, GL_DIFFUSE, setArray); // Setup The Diffuse Light setArray[0]= static_cast<GLfloat>(m_SpecularColor.redF()); setArray[1]= static_cast<GLfloat>(m_SpecularColor.greenF()); setArray[2]= static_cast<GLfloat>(m_SpecularColor.blueF()); setArray[3]= static_cast<GLfloat>(m_SpecularColor.alphaF()); glLightfv(m_LightID, GL_SPECULAR, setArray); // Setup The specular Light if (LightDirection != m_LightType) glLightf(m_LightID, GL_CONSTANT_ATTENUATION, m_ConstantAttenuation); glLightf(m_LightID, GL_LINEAR_ATTENUATION, m_LinearAttenuation); glLightf(m_LightID, GL_QUADRATIC_ATTENUATION, m_QuadraticAttenuation); // Spot light parameters if (LightSpot == m_LightType) { // Spot Direction setArray[0]= static_cast<GLfloat>(m_SpotDirection.x()); setArray[1]= static_cast<GLfloat>(m_SpotDirection.y()); setArray[2]= static_cast<GLfloat>(m_SpotDirection.z()); glLightfv(m_LightID, GL_SPOT_DIRECTION, setArray); glLightf(m_LightID, GL_SPOT_EXPONENT, m_SpotExponent); glLightf(m_LightID, GL_SPOT_CUTOFF, m_SpotCutoffAngle); } // OpenGL error handler GLenum error= glGetError(); if (error != GL_NO_ERROR) { qDebug() << "GLC_Light::glExecute Exception, id= " << m_LightID; GLC_OpenGlException OpenGlException("GLC_Light::glExecute ", error); throw(OpenGlException); } }
// Execute OpenGL Material void GLC_Material::glExecute(float overwriteTransparency) { GLfloat pAmbientColor[4]= {ambientColor().redF(), ambientColor().greenF(), ambientColor().blueF(), overwriteTransparency}; GLfloat pDiffuseColor[4]= {diffuseColor().redF(), diffuseColor().greenF(), diffuseColor().blueF(), overwriteTransparency}; GLfloat pSpecularColor[4]= {specularColor().redF(), specularColor().greenF(), specularColor().blueF(), overwriteTransparency}; GLfloat pLightEmission[4]= {emissiveColor().redF(), emissiveColor().greenF(), emissiveColor().blueF(), overwriteTransparency}; const bool textureIsEnable= glIsEnabled(GL_TEXTURE_2D); if (m_pTexture != NULL) { if (!textureIsEnable) glEnable(GL_TEXTURE_2D); m_pTexture->glcBindTexture(); if (GLC_State::glslUsed()) { if (GLC_Shader::hasActiveShader()) { GLC_Shader::currentShaderHandle()->programShaderHandle()->setUniformValue("tex", GLint(0)); GLC_Shader::currentShaderHandle()->programShaderHandle()->setUniformValue("useTexture", true); } } } else { if (textureIsEnable) glDisable(GL_TEXTURE_2D); if (GLC_State::glslUsed()) { if (GLC_Shader::hasActiveShader()) { GLC_Shader::currentShaderHandle()->programShaderHandle()->setUniformValue("tex", GLint(0)); GLC_Shader::currentShaderHandle()->programShaderHandle()->setUniformValue("useTexture", false); } } } glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, pAmbientColor); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pDiffuseColor); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, pSpecularColor); glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, pLightEmission); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &m_Shininess); glColor4fv(pDiffuseColor); // OpenGL Error handler GLenum error= glGetError(); if (error != GL_NO_ERROR) { GLC_OpenGlException OpenGlException("GLC_Material::glExecute(float overwriteTransparency) ", error); throw(OpenGlException); } }