void CPUSkinningAlgorithm::drawPrimitives( SkinnedGeometry *skinGeo, CPUSkinningDataAttachment* data, DrawEnv *pEnv) { // store glColor. Color4f color; #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY) if(skinGeo->getColors() != NULL) glGetFloatv(GL_CURRENT_COLOR, color.getValuesRGBA()); #endif GeoPumpGroup::PropertyCharacteristics prop = GeoPumpGroup::characterizeGeometry(skinGeo); GeoPumpGroup::GeoPump pump = GeoPumpGroup::findGeoPump(pEnv, prop); if(pump != NULL) { pump(pEnv, skinGeo->getLengths(), skinGeo->getTypes(), data ->getMFProperties(), skinGeo->getMFPropIndices()); } else { SWARNING << "CPUSkinningAlgorithm::drawPrimitives: no GeoPump found " << "for SkinnedGeometry " << skinGeo << std::endl; } #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY) // restore glColor. if(skinGeo->getColors() != NULL) glColor4fv(color.getValuesRGBA()); #endif }
void Graphics3DExtrude::drawText(const Pnt2f& Position, const std::string& Text, const UIFontUnrecPtr TheFont, const Color4f& Color, const Real32& Opacity) const { TextLayoutParam layoutParam; layoutParam.spacing = 1.1; layoutParam.majorAlignment = TextLayoutParam::ALIGN_BEGIN; layoutParam.minorAlignment = TextLayoutParam::ALIGN_BEGIN; TextLayoutResult layoutResult; TheFont->layout(Text, layoutParam, layoutResult); TheFont->getTexture()->activate(getDrawEnv()); Real32 Alpha(Color.alpha() * Opacity * getOpacity()); //Setup the blending equations properly glPushAttrib(GL_COLOR_BUFFER_BIT); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glColor4f(Color.red(), Color.green(), Color.blue(), Alpha ); glPushMatrix(); glTranslatef(Position.x(), Position.y(), 0.0); glScalef(TheFont->getSize(), TheFont->getSize(), 1); drawCharacters(layoutResult, TheFont); glPopMatrix(); TheFont->getTexture()->deactivate(getDrawEnv()); glDisable(GL_BLEND); glPopAttrib(); }
void Graphics3DExtrude::drawArc(const Pnt2f& Center, const Real32& Width, const Real32& Height, const Real32& StartAngleRad, const Real32& EndAngleRad, const Real32& LineWidth, const UInt16& SubDivisions, const Color4f& Color, const Real32& Opacity) const { GLfloat previousLineWidth; glGetFloatv(GL_LINE_WIDTH, &previousLineWidth); Real32 angleNow = StartAngleRad; Real32 angleDiff = (EndAngleRad-StartAngleRad)/(static_cast<Real32>(SubDivisions)); //If andle difference is bigger to a circle, set it to equal to a circle if(EndAngleRad-StartAngleRad > 2*3.1415926535) angleDiff = 2*3.1415926535/static_cast<Real32>(SubDivisions); Real32 Alpha(Color.alpha() * Opacity * getOpacity()); if(Alpha < 1.0) { //Setup the blending equations properly glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); } glLineWidth(LineWidth); glBegin(GL_LINE_STRIP); glColor4f(Color.red(), Color.green(), Color.blue(), Alpha ); //draw vertex lines for(UInt16 i = 0 ; i<SubDivisions+1 ; ++i) { glVertex2f( static_cast<Real32>(Center.x()) + static_cast<Real32>(Width)*osgCos(angleNow ),static_cast<Real32>(Center.y()) +static_cast<Real32>(Height)*osgSin(angleNow)); //glVertex2f(Center.x() + Width*osgCos(angleNow + angleDiff), Center.y() + Height*osgSin(angleNow+angleDiff)); angleNow += angleDiff; } glEnd(); if(Alpha < 1.0) { glDisable(GL_BLEND); } glLineWidth(previousLineWidth); }
bool ImageDiffer::Diff(const Image& ref, const Image& target) { SAFE_DELETE(m_diffData); SAFE_DELETE(m_displayData); if (ref.GetWidth() != target.GetWidth() || ref.GetHeight() != target.GetHeight()) { ApolloException::NotYetImplemented(); } m_ref = &ref; m_target = ⌖ m_diffData = new Image(ref.GetWidth(), ref.GetHeight()); m_displayData = new Image(ref.GetWidth(), ref.GetHeight()); bool identical = true; for (UINT32 row = 0; row < ref.GetHeight(); row++) { for (UINT32 col = 0; col < ref.GetWidth(); col++) { Color4f diff = ref.GetPixel(row, col) - target.GetPixel(row, col); diff.Abs(); m_diffData->SetPixel(diff, row, col); diff *= m_magnify; if (diff.MaxChannel() > m_threshold) { Color4f c1 = ref.GetPixel(row, col); Color4f c2 = target.GetPixel(row, col); identical = false; } } } m_displayDirty = true; return identical; }
Color4b::Color4b (const Color4f& rhs) { r = rhs.r_as_byte(); g = rhs.g_as_byte(); b = rhs.b_as_byte(); a = rhs.a_as_byte(); }
void GlobalAccumulationFramebuffer::develop_to_tile( Tile& tile, const size_t origin_x, const size_t origin_y, const size_t tile_x, const size_t tile_y, const float scale) const { const size_t tile_width = tile.get_width(); const size_t tile_height = tile.get_height(); for (size_t y = 0; y < tile_height; ++y) { for (size_t x = 0; x < tile_width; ++x) { Color4f color; color.rgb() = get_pixel( origin_x + x, origin_y + y); color.rgb() *= scale; color.a = 1.0f; tile.set_pixel(x, y, color); } } }
void VanDerWaalsGLRenderer::drawAtoms( const BioStruct3DColorScheme* colorScheme ) { static float tolerance = 0.45f; int numSlices = 10 * settings->detailLevel; GLUquadricObj *pObj = gluNewQuadric(); gluQuadricNormals(pObj, GLU_SMOOTH); // Draw atoms as spheres foreach (const SharedMolecule mol, bioStruct.moleculeMap) { foreach (int index, shownModels) { const Molecule3DModel& model = mol->models.value(index); foreach(const SharedAtom atom, model.atoms) { float radius = AtomConstants::getAtomCovalentRadius(atom->atomicNumber); Vector3D pos = atom->coord3d; Color4f atomColor = colorScheme->getAtomColor(atom); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, atomColor.getConstData()); glPushMatrix(); glTranslatef(pos.x, pos.y, pos.z); gluSphere(pObj, radius + tolerance, numSlices, numSlices); glPopMatrix(); } } } gluDeleteQuadric(pObj); }
auto_ptr<Image> compare(const Image& lhs, const Image& rhs, const IPixelOp& op) { const CanvasProperties& lhs_props = lhs.properties(); const CanvasProperties& rhs_props = rhs.properties(); if (lhs_props.m_canvas_width != rhs_props.m_canvas_width || lhs_props.m_canvas_height != rhs_props.m_canvas_height || lhs_props.m_channel_count != rhs_props.m_channel_count) throw ExceptionNonMatchingImageCharacteristics(); if (lhs_props.m_channel_count != 4) throw ExceptionUnsupportedChannelCount(); auto_ptr<Image> output(new Image(lhs)); for (size_t y = 0; y < lhs_props.m_canvas_height; ++y) { for (size_t x = 0; x < lhs_props.m_canvas_width; ++x) { Color4f lhs_color; lhs.get_pixel(x, y, lhs_color); Color4f rhs_color; rhs.get_pixel(x, y, rhs_color); Color4f result; result.rgb() = op(lhs_color.rgb(), rhs_color.rgb()); result.a = 1.0f; output->set_pixel(x, y, saturate(result)); } } return output; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- Color4ub::Color4ub(const Color4f& other) { m_rgba[0] = static_cast<ubyte>(other.r()*255.0f); m_rgba[1] = static_cast<ubyte>(other.g()*255.0f); m_rgba[2] = static_cast<ubyte>(other.b()*255.0f); m_rgba[3] = static_cast<ubyte>(other.a()*255.0f); }
void ImageDiffer::ComputePercentDiff() { for (UINT32 row = 0; row < m_diffData->GetHeight(); row++) { for (UINT32 col = 0; col < m_diffData->GetWidth(); col++) { Color4f color = m_diffData->GetPixel(row, col); color.r = fabs(color.r); color.g = fabs(color.g); color.b = fabs(color.b); color.a = fabs(color.a); FLOAT diffLuminance = color.ToLuminance(); FLOAT refLuminance = MAX( m_ref->GetPixel(row, col).ToLuminance(), m_target->GetPixel(row, col).ToLuminance()); Color4f displayColor; FLOAT diff = 0; if (diffLuminance > EPSILON) { diff = diffLuminance / refLuminance; diff *= m_magnify; if (diff <= m_threshold) diff = 0; } displayColor = UIHelper::GetColorIntensity(diff); m_displayData->SetPixel(displayColor, row, col); } } }
//-------------------------------------------------------------------------------------------------- /// Draw a background rectangle using OGL 1.1 compatibility //-------------------------------------------------------------------------------------------------- void InternalLegendRenderTools::renderBackgroundImmediateMode(OpenGLContext* oglContext, const Vec2f& size, const Color4f& backgroundColor, const Color4f& backgroundFrameColor) { RenderStateDepth depth(false); depth.applyOpenGL(oglContext); RenderStateLighting_FF lighting(false); lighting.applyOpenGL(oglContext); RenderStateBlending blend; blend.configureTransparencyBlending(); blend.applyOpenGL(oglContext); // Frame vertices std::array<Vec3f, 4> vertexArray = { Vec3f(1 , 1, 0.0f), Vec3f(size.x(), 1, 0.0f), Vec3f(size.x(), size.y(), 0.0f), Vec3f(1 , size.y(), 0.0f), }; glColor4fv(backgroundColor.ptr()); glBegin(GL_TRIANGLE_FAN); glVertex3fv(vertexArray[0].ptr()); glVertex3fv(vertexArray[1].ptr()); glVertex3fv(vertexArray[2].ptr()); glVertex3fv(vertexArray[3].ptr()); glEnd(); // Render Line around { glColor4fv(backgroundFrameColor.ptr()); glBegin(GL_LINES); glVertex3fv(vertexArray[0].ptr()); glVertex3fv(vertexArray[1].ptr()); glVertex3fv(vertexArray[1].ptr()); glVertex3fv(vertexArray[2].ptr()); glVertex3fv(vertexArray[2].ptr()); glVertex3fv(vertexArray[3].ptr()); glVertex3fv(vertexArray[3].ptr()); glVertex3fv(vertexArray[0].ptr()); glEnd(); } // Reset render states RenderStateLighting_FF resetLighting; resetLighting.applyOpenGL(oglContext); RenderStateDepth resetDepth; resetDepth.applyOpenGL(oglContext); RenderStateBlending resetblend; resetblend.applyOpenGL(oglContext); CVF_CHECK_OGL(oglContext); }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void UniformFloat::set(const Color4f& value) { m_type = FLOAT_VEC4; m_data.resize(4); m_data[0] = value.r(); m_data[1] = value.g(); m_data[2] = value.b(); m_data[3] = value.a(); }
void FrozenDisplayRenderer::capture() { SamplingContext::RNGType rng; SamplingContext sampling_context( rng, m_sampling_mode, 2, // number of dimensions 0, // number of samples -- unknown 0); // initial instance number size_t point_index = 0; for (size_t ty = 0; ty < m_frame_props.m_tile_count_y; ++ty) { for (size_t tx = 0; tx < m_frame_props.m_tile_count_x; ++tx) { const Tile& color_tile = m_color_image.tile(tx, ty); const Tile& depth_tile = m_depth_image.tile(tx, ty); const size_t tile_width = color_tile.get_width(); const size_t tile_height = color_tile.get_height(); for (size_t py = 0; py < tile_height; ++py) { for (size_t px = 0; px < tile_width; ++px) { // Compute film point in NDC. const Vector2d ndc = m_frame.get_sample_position( tx, ty, px, py, 0.5, 0.5); // Retrieve pixel depth. const float depth = depth_tile.get_component<float>(px, py, 0); if (depth >= 0.0f) { // Generate a world space ray going through that film point. ShadingRay ray; m_camera.spawn_ray(sampling_context, Dual2d(ndc), ray); // Retrieve pixel color. Color4f pixel; color_tile.get_pixel(px, py, pixel); // Compute and store world space point and color. RenderPoint point; point.m_position = Vector3f(ray.point_at(depth)); point.m_color = pixel.rgb(); m_points[point_index++] = point; } } } } } }
void Triangle::draw(const Color4f& _color) const { glColor4f(_color.r(),_color.g(),_color.b(),_color.a()); glBegin(GL_TRIANGLES); glNormal3f(COORDS(n_)); glVertex3f(COORDS(v0())); glVertex3f(COORDS(v1())); glVertex3f(COORDS(v2())); glEnd(); }
void VRGeometry::setRandomColors() { GeoPnt3fPropertyRecPtr pos = dynamic_cast<GeoPnt3fProperty*>(mesh->getPositions()); int N = pos->size(); GeoVec4fPropertyRecPtr cols = GeoVec4fProperty::create(); for (int i=0; i<N; i++) { Color4f c; c.setRandom(); cols->addValue( c ); } setColors(cols); }
void EdLevelPropertyColorField::doReadParams(void) { blockSignals(true); keyButton()->disconnect(); // Has Key if (_data->plug()) { keyButton()->setIcon(QIcon(":/images/key.png")); connect( keyButton(), SIGNAL(pressed()), this, SLOT(doKeyframePressed()) ); } else { keyButton()->setIcon(QIcon(":/images/blank.png")); } // Has Input if (_data->plug() && _data->plug()->has_incoming_connection()) { hasInputButton()->setIcon(QIcon(":/images/has_input.png")); } else { hasInputButton()->setIcon(QIcon(":/images/blank.png")); } // Has Output if (_data->plug() && _data->plug()->has_outgoing_connection()) { hasOutputButton()->setIcon(QIcon(":/images/has_output.png")); } else { hasOutputButton()->setIcon(QIcon(":/images/blank.png")); } TextBufferStream stream; _data->value(stream); Color4f val; stream >> val; Color4b val_b(val); _r->setValue(val_b.r_as_byte()); _g->setValue(val_b.g_as_byte()); _b->setValue(val_b.b_as_byte()); _a->setValue(val_b.a_as_byte()); _r2->setText( MoreStrings::cast_to_string(val.r_as_float()).c_str() ); _g2->setText( MoreStrings::cast_to_string(val.g_as_float()).c_str() ); _b2->setText( MoreStrings::cast_to_string(val.b_as_float()).c_str() ); _a2->setText( MoreStrings::cast_to_string(val.a_as_float()).c_str() ); doColorChange(0); blockSignals(false); }
void VertexTriangle::draw(const Color4f& _color) const { glColor4f(_color.r(),_color.g(),_color.b(),_color.a()); glBegin(GL_TRIANGLES); glNormal3f(COORDS(v[0]->n)); glVertex3f(COORDS(v[0]->v)); glNormal3f(COORDS(v[1]->n)); glVertex3f(COORDS(v[1]->v)); glNormal3f(COORDS(v[2]->n)); glVertex3f(COORDS(v[2]->v)); glEnd(); }
void ImageMetrics::ComputeMeanAndStdDeviation(const Image* image, Color4f& mean, Color4f& stddev) { mean = Color4f::ZERO(); stddev = Color4f::ZERO();; UINT32 w = image->GetWidth(); UINT32 h = image->GetHeight(); UINT32 pitch = image->GetPitch(); const Color4f* data = image->GetData(); for (UINT32 row = 0; row < h; row++) { const Color4f* rowData = data + row*pitch; for (UINT32 col = 0; col < w; col++) { mean += rowData[col]; } } mean /= (FLOAT) image->GetSize(); for (UINT32 row = 0; row < h; row++) { const Color4f* rowData = data + row*pitch; for (UINT32 col = 0; col < w; col++) { Color4f diff = rowData[col] - mean; stddev.MultAggregate(diff, diff); } } stddev /= (FLOAT) image->GetSize(); stddev.r = sqrtf(stddev.r); stddev.g = sqrtf(stddev.g); stddev.b = sqrtf(stddev.b); stddev.a = sqrtf(stddev.a); }
void MtlBlinnSW3D::Transmit(ShadeContext3D &sc) { BlinnBlock &block = (BlinnBlock &) sc.GetMaterialBlock(this); const Vector4f &vertexColor = IsSet(block.VertexColor) ? *block.VertexColor : WHITE4F; Color4f diffuseMtl; if (DiffuseMtl) { DiffuseMtl->Shade(sc); diffuseMtl = *block.Color; } else diffuseMtl = WHITE4F; Color4f Kd = Mul(PreDiffuse, Mul(diffuseMtl, vertexColor)); if (fabs(Kd.A) < 0.0001f) Kd = Color4f(1.0f, 1.0f, 1.0f, 0.0f); else { Kd.R /= Kd.A; Kd.G /= Kd.A; Kd.B /= Kd.A; } float32 y = Kd.Luminance(); Color4f satColor = Lerp(Color4f(y, y, y, 1.0f), Kd, Saturation); satColor.A = 1.0f; Color4f textureDetail = Lerp(Color4f(0.0f, 0.0f, 0.0f, 1.0f), satColor, ColorDetail); textureDetail.A = 1.0f; float32 alphaDetail = Lerp(0.0f, 1.0f - Kd.A, AlphaDetail); Color4f outTrans = (1.0f - alphaDetail) * textureDetail + Color4f(alphaDetail); // compute 1 - (1 - ad) * (1 - td) outTrans = Color4f(1.0f) - Mul(Color4f(1.0f) - outTrans, Color4f(1.0f) - Transmittance); sc.Transmittance.R = max(min(outTrans.R, 1.0f), 0.0f); sc.Transmittance.G = max(min(outTrans.G, 1.0f), 0.0f); sc.Transmittance.B = max(min(outTrans.B, 1.0f), 0.0f); sc.Transmittance.A = outTrans.A; FuASSERT(sc.Transmittance.A >= 0.0f && sc.Transmittance.A <= 1.002f, ("")); }
void EdLevelPropertyColorField::doWriteParams2(void) { Color4f val; val.set_r( MoreStrings::cast_from_string<DTfloat>(_r2->text().toUtf8().data()) ); val.set_g( MoreStrings::cast_from_string<DTfloat>(_g2->text().toUtf8().data()) ); val.set_b( MoreStrings::cast_from_string<DTfloat>(_b2->text().toUtf8().data()) ); val.set_a( MoreStrings::cast_from_string<DTfloat>(_a2->text().toUtf8().data()) ); TextBufferStream stream; stream << val; TextBufferStream oldstream; _data->value(oldstream); // Only if value changed if (stream.buffer() != oldstream.buffer()) { emit doCommand(QString("SetProp \"") + _node->full_name().c_str() + "." + _data->title().c_str() + "\" (" + stream.buffer().c_str() + ")", _data->flags() & DATA_FLUSH_UI); } }
Color4f Frame::linear_rgb_to_frame(const Color4f& linear_rgb) const { Color4f result; // Transform the input color to the color space of the frame. switch (impl->m_color_space) { case ColorSpaceLinearRGB: result = linear_rgb; break; case ColorSpaceSRGB: result.rgb() = fast_linear_rgb_to_srgb(linear_rgb.rgb()); result.a = linear_rgb.a; break; case ColorSpaceCIEXYZ: result.rgb() = linear_rgb_to_ciexyz(linear_rgb.rgb()); result.a = linear_rgb.a; break; default: assert(!"Invalid target color space."); result = linear_rgb; break; } // Clamp the color. // todo: mark clamped pixels in the diagnostic map. result = impl->m_clamping ? saturate(result) : clamp_to_zero(result); // Gamma-correct color. if (impl->m_gamma_correct) { // todo: investigate the usage of fast_pow() for gamma correction. const float rcp_target_gamma = impl->m_rcp_target_gamma; result[0] = pow(result[0], rcp_target_gamma); result[1] = pow(result[1], rcp_target_gamma); result[2] = pow(result[2], rcp_target_gamma); } return result; }
void Graphics3DExtrude::drawQuad(const Pnt2f& p1, const Pnt2f& p2, const Pnt2f& p3, const Pnt2f& p4, const Vec2f& t1, const Vec2f& t2, const Vec2f& t3, const Vec2f& t4, const Color4f& color, const TextureObjChunkUnrecPtr Texture, const Real32& Opacity) const { Real32 Alpha( Opacity * getOpacity() * color.alpha()); if(Alpha < 1.0 || Texture->getImage()->hasAlphaChannel()) { //Setup the Blending equations properly glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); } if(Texture != NULL) { Texture->activate(getDrawEnv()); } glBegin(GL_QUADS); glColor4f(color.red(), color.green(), color.blue(), Alpha ); glTexCoord2fv(t1.getValues()); glVertex2fv(p1.getValues()); glTexCoord2fv(t2.getValues()); glVertex2fv(p2.getValues()); glTexCoord2fv(t3.getValues()); glVertex2fv(p3.getValues()); glTexCoord2fv(t4.getValues()); glVertex2fv(p4.getValues()); glEnd(); if(Texture != NULL) { Texture->deactivate(getDrawEnv()); } if(Alpha < 1.0 || Texture->getImage()->hasAlphaChannel()) { glDisable(GL_BLEND); } }
void Render(void) { glCullFace(GL_BACK); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // glClearColor(0,0,0,0); Color4f ccl = colorub_2_color4f( int_2_color4ub(0xe8a76eff) ); glClearColor( ccl.red(), ccl.green(), ccl.blue(), ccl.alpha() ); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPolygonMode(GL_FRONT, GL_FILL); glColor4ub(0xff, 0x00, 0x00, 0xff); glVertexPointer(2, GL_FLOAT, 0, g_stroker.vertices()); glEnableClientState(GL_VERTEX_ARRAY); glDrawArrays(GL_TRIANGLE_STRIP, 0, g_stroker.vertexCount()/2); glPolygonMode(GL_FRONT, GL_LINE); glColor4ub(0xff, 0xff, 0xff, 0xff); glVertexPointer(2, GL_FLOAT, 0, g_stroker.vertices()); glEnableClientState(GL_VERTEX_ARRAY); glDrawArrays(GL_TRIANGLE_STRIP, 0, g_stroker.vertexCount()/2); #ifdef TEXTURE_STROKE_APP // turn on texture glEnable (GL_TEXTURE_2D); RoadRender renderer; int ret = renderer.extrudeLines(gPath, 18); if (RoadRender::EXTRUDE_SUCCESS==ret) { renderer.render(textureId); } // drawTextureQuad(windowWidth, windowHeight, textureId); #endif glutSwapBuffers(); checkForError("swap"); }
void Graphics3DExtrude::drawPolygon(const MFPnt2f Verticies, const Color4f& Color, const Real32& Opacity) const { Real32 Alpha(Color.alpha() * Opacity * getOpacity()); if(Alpha < 1.0) { //Setup the Blending equations properly glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); } glBegin(GL_POLYGON); glColor4f(Color.red(), Color.green(), Color.blue(), Alpha ); for(UInt32 i=0 ; i<Verticies.size() ; ++i) { glVertex2fv(Verticies[i].getValues()); } glEnd(); if(Alpha < 1.0) { glDisable(GL_BLEND); } }
void Graphics3DExtrude::drawLine(const Pnt2f& TopLeft, const Pnt2f& BottomRight, const Real32& Width, const Color4f& Color, const Real32& Opacity) const { GLfloat previousLineWidth; glGetFloatv(GL_LINE_WIDTH, &previousLineWidth); Real32 Alpha(Color.alpha() * Opacity * getOpacity()); if(Alpha < 1.0) { //Setup the blending equations properly glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); } glLineWidth(Width); glBegin(GL_LINES); glColor4f(Color.red(), Color.green(), Color.blue(), Alpha ); glVertex2fv(TopLeft.getValues()); glVertex2fv(BottomRight.getValues()); glEnd(); if(Alpha < 1.0) { glDisable(GL_BLEND); } glLineWidth(previousLineWidth); }
void ColorTest::access() { Color3f c3(15, 255, 10); const Color3f cc3(15, 255, 10); CORRADE_COMPARE(c3.r(), 15); CORRADE_COMPARE(c3.g(), 255); CORRADE_COMPARE(c3.b(), 10); CORRADE_COMPARE(cc3.r(), 15); CORRADE_COMPARE(cc3.g(), 255); CORRADE_COMPARE(cc3.b(), 10); Color4 c4(125, 98, 51, 22); const Color4f cc4(125, 98, 51, 22); CORRADE_COMPARE(c4.r(), 125); CORRADE_COMPARE(c4.g(), 98); CORRADE_COMPARE(c4.b(), 51); CORRADE_COMPARE(c4.a(), 22); CORRADE_COMPARE(cc4.r(), 125); CORRADE_COMPARE(cc4.g(), 98); CORRADE_COMPARE(cc4.b(), 51); CORRADE_COMPARE(cc4.a(), 22); }
MaterialTransitPtr OctreeVisualization::createMatFilled(OctreePtr tree, const Octree::OTNodePtr node, const Color3f& CoolColor, const Color3f& HotColor, Real32 Alpha, BlendChunk* BaseBlendChunk, PolygonChunk* BasePolygonChunk ) { //Calculate the Color //Real32 t = static_cast<Real32>(node->getDepth())/static_cast<Real32>(tree->getDepth()); //Color3f NodeColor(t*HotColor + (1.0f-t)*CoolColor); Color3f NodeColor; Color4f NodeColorWithAlpha; if(node->getContainsObstacles()) { NodeColor = HotColor; NodeColorWithAlpha.setValuesRGBA(NodeColor.red(),NodeColor.green(),NodeColor.blue(),0.55); } else { NodeColor = CoolColor; NodeColorWithAlpha.setValuesRGBA(NodeColor.red(),NodeColor.green(),NodeColor.blue(),0.05); } MaterialChunkRecPtr DefaultMatChunk = MaterialChunk::create(); DefaultMatChunk->setAmbient(NodeColorWithAlpha); DefaultMatChunk->setDiffuse(NodeColorWithAlpha); ChunkMaterialRecPtr NodeMat = ChunkMaterial::create(); NodeMat->setSortKey(1); NodeMat->addChunk(BaseBlendChunk); NodeMat->addChunk(BasePolygonChunk); NodeMat->addChunk(DefaultMatChunk); return MaterialTransitPtr(NodeMat); }
void Graphics3DExtrude::drawQuad(const Pnt2f& p1, const Pnt2f& p2, const Pnt2f& p3, const Pnt2f& p4, const Color4f& c1, const Color4f& c2, const Color4f& c3, const Color4f& c4, const Real32& Opacity) const { Real32 MinAlpha( osgMin(osgMin(c1.alpha(), c2.alpha()), osgMin(c3.alpha(), c4.alpha())) * Opacity * getOpacity()); if(MinAlpha < 1.0) { //Setup the Blending equations properly glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); } glBegin(GL_QUADS); //Front glNormal3f(0.0,0.0,1.0); glColor4f(c1.red(), c1.green(), c1.blue(), c1.alpha() * Opacity * getOpacity() ); glVertex3f(p1.x(), p1.y(), 0.0); glColor4f(c4.red(), c4.green(), c4.blue(), c4.alpha() * Opacity * getOpacity() ); glVertex3f(p4.x(), p4.y(), 0.0); glColor4f(c3.red(), c3.green(), c3.blue(), c3.alpha() * Opacity * getOpacity() ); glVertex3f(p3.x(), p3.y(), 0.0); glColor4f(c2.red(), c2.green(), c2.blue(), c2.alpha() * Opacity * getOpacity() ); glVertex3f(p2.x(), p2.y(), 0.0); //Back glNormal3f(0.0,0.0,-1.0); glColor4f(c1.red(), c1.green(), c1.blue(), c1.alpha() * Opacity * getOpacity() ); glVertex3f(p1.x(), p1.y(), getExtrudeLength()); glColor4f(c2.red(), c2.green(), c2.blue(), c2.alpha() * Opacity * getOpacity() ); glVertex3f(p2.x(), p2.y(), getExtrudeLength()); glColor4f(c3.red(), c3.green(), c3.blue(), c3.alpha() * Opacity * getOpacity() ); glVertex3f(p3.x(), p3.y(), getExtrudeLength()); glColor4f(c4.red(), c4.green(), c4.blue(), c4.alpha() * Opacity * getOpacity() ); glVertex3f(p4.x(), p4.y(), getExtrudeLength()); //Top glNormal3f(0.0,-1.0,0.0); glColor4f(c1.red(), c1.green(), c1.blue(), c1.alpha() * Opacity * getOpacity() ); glVertex3f(p1.x(), p1.y(), 0.0); glColor4f(c2.red(), c2.green(), c2.blue(), c2.alpha() * Opacity * getOpacity() ); glVertex3f(p2.x(), p2.y(), 0.0); glColor4f(c2.red(), c2.green(), c2.blue(), c2.alpha() * Opacity * getOpacity() ); glVertex3f(p2.x(), p2.y(), getExtrudeLength()); glColor4f(c1.red(), c1.green(), c1.blue(), c1.alpha() * Opacity * getOpacity() ); glVertex3f(p1.x(), p1.y(), getExtrudeLength()); //Bottom glNormal3f(0.0,1.0,0.0); glColor4f(c3.red(), c3.green(), c3.blue(), c3.alpha() * Opacity * getOpacity() ); glVertex3f(p3.x(), p3.y(), 0.0); glColor4f(c4.red(), c4.green(), c4.blue(), c4.alpha() * Opacity * getOpacity() ); glVertex3f(p4.x(), p4.y(), 0.0); glColor4f(c4.red(), c4.green(), c4.blue(), c4.alpha() * Opacity * getOpacity() ); glVertex3f(p4.x(), p4.y(), getExtrudeLength()); glColor4f(c3.red(), c3.green(), c3.blue(), c3.alpha() * Opacity * getOpacity() ); glVertex3f(p3.x(), p3.y(), getExtrudeLength()); //Right glNormal3f(1.0,0.0,0.0); glColor4f(c2.red(), c2.green(), c2.blue(), c2.alpha() * Opacity * getOpacity() ); glVertex3f(p2.x(), p2.y(), 0.0); glColor4f(c3.red(), c3.green(), c3.blue(), c3.alpha() * Opacity * getOpacity() ); glVertex3f(p3.x(), p3.y(), 0.0); glColor4f(c3.red(), c3.green(), c3.blue(), c3.alpha() * Opacity * getOpacity() ); glVertex3f(p3.x(), p3.y(), getExtrudeLength()); glColor4f(c2.red(), c2.green(), c2.blue(), c2.alpha() * Opacity * getOpacity() ); glVertex3f(p2.x(), p2.y(), getExtrudeLength()); //Left glNormal3f(-1.0,0.0,0.0); glColor4f(c1.red(), c1.green(), c1.blue(), c1.alpha() * Opacity * getOpacity() ); glVertex3f(p1.x(), p1.y(), 0.0); glVertex3f(p1.x(), p1.y(), getExtrudeLength()); glColor4f(c4.red(), c4.green(), c4.blue(), c4.alpha() * Opacity * getOpacity() ); glVertex3f(p4.x(), p4.y(), getExtrudeLength()); glVertex3f(p4.x(), p4.y(), 0.0); glEnd(); if(MinAlpha < 1.0) { glDisable(GL_BLEND); } }
void Graphics3DExtrude::drawRect(const Pnt2f& TopLeft, const Pnt2f& BottomRight, const Color4f& Color, const Real32& Opacity) const { Real32 Alpha(Color.alpha() * Opacity * getOpacity()); if(Alpha < 1.0 || getEnablePolygonAntiAliasing()) { //Setup the Blending equations properly glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); } glColor4f(Color.red(), Color.green(), Color.blue(), Alpha ); glBegin(GL_QUADS); //Front glNormal3f(0.0,0.0,1.0); glVertex3f(TopLeft.x(), TopLeft.y(), 0.0); glVertex3f(TopLeft.x(), BottomRight.y(), 0.0); glVertex3f(BottomRight.x(), BottomRight.y(), 0.0); glVertex3f(BottomRight.x(), TopLeft.y(), 0.0); //Back glNormal3f(0.0,0.0,-1.0); glVertex3f(TopLeft.x(), TopLeft.y(), getExtrudeLength()); glVertex3f(BottomRight.x(), TopLeft.y(), getExtrudeLength()); glVertex3f(BottomRight.x(), BottomRight.y(), getExtrudeLength()); glVertex3f(TopLeft.x(), BottomRight.y(), getExtrudeLength()); //Top glNormal3f(0.0,-1.0,0.0); glVertex3f(TopLeft.x(), TopLeft.y(), 0.0); glVertex3f(BottomRight.x(), TopLeft.y(), 0.0); glVertex3f(BottomRight.x(), TopLeft.y(), getExtrudeLength()); glVertex3f(TopLeft.x(), TopLeft.y(), getExtrudeLength()); //Bottom glNormal3f(0.0,1.0,0.0); glVertex3f(TopLeft.x(), BottomRight.y(), 0.0); glVertex3f(TopLeft.x(), BottomRight.y(), getExtrudeLength()); glVertex3f(BottomRight.x(), BottomRight.y(), getExtrudeLength()); glVertex3f(BottomRight.x(), BottomRight.y(), 0.0); //Right glNormal3f(1.0,0.0,0.0); glVertex3f(BottomRight.x(), TopLeft.y(), 0.0); glVertex3f(BottomRight.x(), BottomRight.y(), 0.0); glVertex3f(BottomRight.x(), BottomRight.y(), getExtrudeLength()); glVertex3f(BottomRight.x(), TopLeft.y(), getExtrudeLength()); //Left glNormal3f(-1.0,0.0,0.0); glVertex3f(TopLeft.x(), TopLeft.y(), 0.0); glVertex3f(TopLeft.x(), TopLeft.y(), getExtrudeLength()); glVertex3f(TopLeft.x(), BottomRight.y(), getExtrudeLength()); glVertex3f(TopLeft.x(), BottomRight.y(), 0.0); glEnd(); if(Alpha < 1.0 || getEnablePolygonAntiAliasing()) { glDisable(GL_BLEND); } }
void Graphics3DExtrude::drawComplexDisc(const Pnt2f& Center, const Real32& InnerRadius, const Real32& OuterRadius, const Real32& StartAngleRad, const Real32& EndAngleRad, const UInt16& SubDivisions, const Color4f& CenterColor, const Color4f& OuterColor, const Real32& Opacity) const { Real32 angleNow = StartAngleRad; Real32 angleDiff = (EndAngleRad-StartAngleRad)/(static_cast<Real32>(SubDivisions)); if(EndAngleRad-StartAngleRad > 2*3.1415926535) angleDiff = 2*3.1415926535/static_cast<Real32>(SubDivisions); if(CenterColor.alpha() < 1.0 || OuterColor.alpha() < 1.0) { //Setup the blending equations properly glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); } //Front glBegin(GL_QUAD_STRIP); glNormal3f(0.0,0.0,1.0); for(UInt16 i = 0 ; i<SubDivisions+1 ; ++i) { glColor4f(OuterColor.red(), OuterColor.green(), OuterColor.blue(), OuterColor.alpha()); glVertex3f(static_cast<Real32>(Center.x()) + static_cast<Real32>(OuterRadius)*osgCos(angleNow), static_cast<Real32>(Center.y()) + static_cast<Real32>(OuterRadius)*osgSin(angleNow),0.0); glColor4f(CenterColor.red(), CenterColor.green(), CenterColor.blue(), CenterColor.alpha()); glVertex3f(static_cast<Real32>(Center.x()) + static_cast<Real32>(InnerRadius)*osgCos(angleNow), static_cast<Real32>(Center.y()) + static_cast<Real32>(InnerRadius)*osgSin(angleNow), 0.0); angleNow += angleDiff; } glEnd(); //OuterArc angleNow = StartAngleRad; glBegin(GL_QUAD_STRIP); glColor4f(OuterColor.red(), OuterColor.green(), OuterColor.blue(), OuterColor.alpha()); for(UInt16 i = 0 ; i<SubDivisions+1 ; ++i) { glNormal3f(osgCos(angleNow),osgSin(angleNow),0.0); glVertex3f(static_cast<Real32>(Center.x()) + static_cast<Real32>(OuterRadius)*osgCos(angleNow), static_cast<Real32>(Center.y()) + static_cast<Real32>(OuterRadius)*osgSin(angleNow),getExtrudeLength()); glVertex3f(static_cast<Real32>(Center.x()) + static_cast<Real32>(OuterRadius)*osgCos(angleNow), static_cast<Real32>(Center.y()) + static_cast<Real32>(OuterRadius)*osgSin(angleNow),0.0); angleNow += angleDiff; } glEnd(); //InnerArc angleNow = StartAngleRad; glBegin(GL_QUAD_STRIP); glColor4f(CenterColor.red(), CenterColor.green(), CenterColor.blue(), CenterColor.alpha()); for(UInt16 i = 0 ; i<SubDivisions+1 ; ++i) { glNormal3f(-osgCos(angleNow),-osgSin(angleNow),0.0); glVertex3f(static_cast<Real32>(Center.x()) + static_cast<Real32>(InnerRadius)*osgCos(angleNow), static_cast<Real32>(Center.y()) + static_cast<Real32>(InnerRadius)*osgSin(angleNow),0.0); glVertex3f(static_cast<Real32>(Center.x()) + static_cast<Real32>(InnerRadius)*osgCos(angleNow), static_cast<Real32>(Center.y()) + static_cast<Real32>(InnerRadius)*osgSin(angleNow),getExtrudeLength()); angleNow += angleDiff; } glEnd(); //Back angleNow = StartAngleRad; glBegin(GL_QUAD_STRIP); glNormal3f(0.0,0.0,-1.0); for(UInt16 i = 0 ; i<SubDivisions+1 ; ++i) { glColor4f(CenterColor.red(), CenterColor.green(), CenterColor.blue(), CenterColor.alpha()); glVertex3f(static_cast<Real32>(Center.x()) + static_cast<Real32>(InnerRadius)*osgCos(angleNow), static_cast<Real32>(Center.y()) + static_cast<Real32>(InnerRadius)*osgSin(angleNow), getExtrudeLength()); glColor4f(OuterColor.red(), OuterColor.green(), OuterColor.blue(), OuterColor.alpha()); glVertex3f(static_cast<Real32>(Center.x()) + static_cast<Real32>(OuterRadius)*osgCos(angleNow), static_cast<Real32>(Center.y()) + static_cast<Real32>(OuterRadius)*osgSin(angleNow), getExtrudeLength()); angleNow += angleDiff; } glEnd(); if(CenterColor.alpha() < 1.0 || OuterColor.alpha() < 1.0) { glDisable(GL_BLEND); } }