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); }
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::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 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); } }
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); } }
OSG_USING_NAMESPACE Vec4f cToV (Color4f & col) { return Vec4f(col.red(), col.green(), col.blue(), col.alpha()); }
Action::ResultE LineParticleSystemDrawer::draw(DrawEnv *pEnv, ParticleSystemUnrecPtr System, const MFUInt32& Sort) { UInt32 NumParticles(System->getNumParticles()); bool areEndpointsFadeSame(getEndPointFading().x() == getEndPointFading().y()); Color4f Color; if(NumParticles != 0) { bool SeparateColors(System->getNumColors() > 1); bool SeparateSizes(System->getNumSizes() > 1); bool SeparateNormals(System->getNumNormals() > 1); glBegin(GL_LINES); //Colors if(!SeparateColors && areEndpointsFadeSame) { Color = System->getColor(0); glColor4f(Color.red(), Color.green(), Color.blue(), Color.alpha() * getEndPointFading().x()); } //Sizes if(!SeparateSizes) { //glColor4fv(System->getColor(0).getValuesRGBA()); } //Normals if(!SeparateNormals) { glNormal3fv(System->getNormal(0).getValues()); } for(UInt32 i(0) ; i<NumParticles ; ++i) { //Start Color if(SeparateColors) { Color = System->getColor(i); glColor4f(Color.red(), Color.green(), Color.blue(), Color.alpha() * getEndPointFading().x()); } else if(!SeparateColors && !areEndpointsFadeSame) { Color = System->getColor(0); glColor4f(Color.red(), Color.green(), Color.blue(), Color.alpha() * getEndPointFading().x()); } //Sizes if(SeparateSizes) { //glColor4fv(System->getColor(i).getValuesRGBA()); } //Normals if(SeparateNormals) { glNormal3fv(System->getNormal(i).getValues()); } //Positions glVertex3fv(System->getPosition(i).getValues()); //End Color if(SeparateColors && !areEndpointsFadeSame) { Color = System->getColor(i); glColor4f(Color.red(), Color.green(), Color.blue(), Color.alpha() * getEndPointFading().y()); } else if(!SeparateColors && !areEndpointsFadeSame) { Color = System->getColor(0); glColor4f(Color.red(), Color.green(), Color.blue(), Color.alpha() * getEndPointFading().y()); } glVertex3fv(getLineEndpoint(System, i).getValues()); } glEnd(); } return Action::Continue; }