예제 #1
0
void ol::Ellipse::
Draw( const Rgba &innerCol, const Rgba &outerCol ) const {
#ifdef OL_NO_STATE_CHANGE
   GLboolean texturesEnabled;
   glGetBooleanv( GL_TEXTURE_2D, &texturesEnabled );
#endif
   glDisable( GL_TEXTURE_2D );
   
   glPushMatrix();
   glTranslatef( pos.x, pos.y, 0.0 );
   RotateMatrix( angle );
   
   glBegin( GL_TRIANGLE_FAN );
      innerCol.Select();
      glVertex2f( 0.0, 0.0 );
      
      outerCol.Select();
      
      for( float a = 0.0; a < 2 * AL_PI; a += angleIncrement ) {
         glVertex2f( cos(a) * xRad, sin(a) * yRad );
      }
      
      glVertex2f( xRad, 0.0 );
   glEnd();
   
   glPopMatrix();
   
#ifdef OL_NO_STATE_CHANGE
   if( texturesEnabled )
      glEnable( GL_TEXTURE_2D );
#endif
}
예제 #2
0
void GfxRend::
ArcGradient( float x, float y, float innerRad, float outerRad, float startAngle,
             float sweepAngle, Rgba innerCol, Rgba outerCol, float accuracy ) {

   glDisable( GL_TEXTURE_2D );
                   
   float da = GetAngleIncrement( outerRad, accuracy );
   float endAngle = startAngle - sweepAngle; 
   
   if(endAngle < startAngle){
     float temp = startAngle;
     startAngle = endAngle;
     endAngle = temp;
   }
   
   
   glBegin( GL_QUADS );
      float prevIX = x + cos(startAngle) * innerRad;
      float prevIY = y + sin(startAngle) * innerRad;
      
      float prevOX = x + cos(startAngle) * outerRad;
      float prevOY = y + sin(startAngle) * outerRad;
      
      for( float a = startAngle; a < endAngle; a += da ) {
         float cosa = cos(a);
         float sina = sin(a);
         
         float newIX = x + cosa * innerRad;
         float newIY = y + sina * innerRad;
         
         float newOX = x + cosa * outerRad;
         float newOY = y + sina * outerRad;
         
         innerCol.Select();
         glVertex2f( newIX, newIY );
         glVertex2f( prevIX, prevIY );
         
         outerCol.Select();
         glVertex2f( prevOX, prevOY );
         glVertex2f( newOX, newOY );
         
         prevIX = newIX;
         prevIY = newIY;
         
         prevOX = newOX;
         prevOY = newOY;
      }
      
      innerCol.Select();   
      glVertex2f( x + cos(endAngle) * innerRad, y + sin(endAngle) * innerRad);
      glVertex2f( prevIX, prevIY );
      
      outerCol.Select();
      glVertex2f( prevOX, prevOY );
      glVertex2f( x + cos(endAngle) * outerRad, y + sin(endAngle) * outerRad); 
   glEnd();
   
   if( Settings::TextureMappingUsed() )
      glEnable( GL_TEXTURE_2D );
}
예제 #3
0
void GfxRend::
SliceGradient( float x, float y, float rad, float startAngle, float sweepAngle,
               Rgba innerCol, Rgba outerCol, float accuracy ) {
   glDisable( GL_TEXTURE_2D );
   
   float da = GetAngleIncrement( rad, accuracy );
   float endAngle = startAngle - sweepAngle; 
   
   if(endAngle < startAngle){
     float temp = startAngle;
     startAngle = endAngle;
     endAngle = temp;
   }
   
   
   glBegin( GL_TRIANGLE_FAN );
      innerCol.Select();
      glVertex2f( x, y );
      
      outerCol.Select();
       
      for( float a = startAngle; a < endAngle; a += da ) {
         glVertex2f( x + cos(a) * rad, y + sin(a) * rad );
      }
      
      glVertex2f( x + cos( endAngle ) * rad, y + sin( endAngle ) * rad );
   glEnd();
   
   if( Settings::TextureMappingUsed() )
      glEnable( GL_TEXTURE_2D );
}
예제 #4
0
void GfxRend::
DiskRender( float x, float y, float innerRad, float outerRad, Rgba innerCol, Rgba outerCol, float accuracy, bool setCols ) {
   float da = GetAngleIncrement( outerRad, accuracy );
   
   glBegin( GL_QUADS );
      float prevIX = x + innerRad;
      float prevIY = y;
      
      float prevOX = x + outerRad;
      float prevOY = y;
      
      for( float a = 0.0; a <= 2 * AL_PI; a += da ) {
         float cosa = cos(a);
         float sina = sin(a);
         
         float newIX = x + cosa * innerRad;
         float newIY = y + sina * innerRad;
         
         float newOX = x + cosa * outerRad;
         float newOY = y + sina * outerRad;
         
         if( setCols )
            innerCol.Select();
         
         glVertex2f( newIX, newIY );
         glVertex2f( prevIX, prevIY );
         
         if( setCols )
            outerCol.Select();
         
         glVertex2f( prevOX, prevOY );
         glVertex2f( newOX, newOY );
         
         prevIX = newIX;
         prevIY = newIY;
         
         prevOX = newOX;
         prevOY = newOY;
      }
      
      if( setCols )
         innerCol.Select();
         
      glVertex2f( x + innerRad, y );
      glVertex2f( prevIX, prevIY );
      
      if( setCols )
         outerCol.Select();
      
      glVertex2f( prevOX, prevOY );
      glVertex2f( x + outerRad, y );
   glEnd();
}
예제 #5
0
void GfxRend::
LineGradient( float x1, float y1, float x2, float y2, Rgba col1, Rgba col2, float lineWidth ) {
   glDisable( GL_TEXTURE_2D );
   glLineWidth( lineWidth );
   
   glBegin( GL_LINES );
      col1.Select();
      glVertex2f( x1, y1 );
      col2.Select();
      glVertex2f( x2, y2 );
   glEnd();
   
   if( Settings::TextureMappingUsed() )
      glEnable( GL_TEXTURE_2D );
}
예제 #6
0
void GfxRend::
RectOutline( float x, float y, float w, float h, Rgba col, float lineWidth ) {
   col.Select();
   glDisable( GL_TEXTURE_2D );
   glLineWidth( lineWidth );
   
   glBegin( GL_QUADS );
      // Top //
      glVertex2f( x -lineWidth, y -lineWidth );
      glVertex2f( x+w +lineWidth, y -lineWidth );
      glVertex2f( x+w +lineWidth, y );
      glVertex2f( x -lineWidth, y );
      // Bottom //
      glVertex2f( x -lineWidth, y+h );
      glVertex2f( x+w +lineWidth, y+h );
      glVertex2f( x+w +lineWidth, y+h +lineWidth );
      glVertex2f( x -lineWidth, y+h +lineWidth );
      // Left //
      glVertex2f( x -lineWidth, y );
      glVertex2f( x, y );
      glVertex2f( x, y+h );
      glVertex2f( x -lineWidth, y+h );
      // Right //
      glVertex2f( x+w, y );
      glVertex2f( x+w +lineWidth, y );
      glVertex2f( x+w +lineWidth, y+h );
      glVertex2f( x+w, y+h );
   glEnd();
   
   if( Settings::TextureMappingUsed() )
      glEnable( GL_TEXTURE_2D );
}
예제 #7
0
	void GLtexture::setBorderColor(const Rgba& color)
	{
		glBindTexture(GL_TEXTURE_2D, getObject());

		Vector4 fcolor = color.toVector();

		glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, fcolor);
	}
예제 #8
0
void GfxRend::
EllipseSliceGradient( float x, float y, float xRad, float yRad,
                      Rgba innerCol1, Rgba outerCol1, Rgba innerCol2, Rgba outerCol2, float startAngle, float sweepAngle, float angle, float accuracy ) {
   glDisable( GL_TEXTURE_2D );
   
   glPushMatrix();
   glTranslatef( x, y, 0.0 );
   RotateMatrix( angle );
   
   float da = 1.0;
   
   if( xRad < yRad )
      da = GetAngleIncrement( xRad, accuracy );
   else
      da = GetAngleIncrement( yRad, accuracy );
   
   float endAngle = startAngle - sweepAngle; 
   
   if( endAngle < startAngle ){
     float temp = startAngle;
     startAngle = endAngle;
     endAngle = temp;
   }
   
   if( endAngle - startAngle >= da ) {
      glBegin( GL_QUAD_STRIP );
         for( float a = startAngle; a < endAngle; a += da ) {
            float colFact = (a-startAngle)/(endAngle-startAngle);
               
            innerCol1.InterpolateWith( innerCol2, colFact ).Select();
            glVertex2f( 0.0, 0.0 );
            
            outerCol1.InterpolateWith( outerCol2, colFact ).Select();
            glVertex2f( cos(a) * xRad, sin(a) * yRad );
         }
         
         glVertex2f( cos( endAngle ) * xRad, sin( endAngle ) * yRad );
      glEnd();
   }
   
   glPopMatrix();
   
   if( Settings::TextureMappingUsed() )
      glEnable( GL_TEXTURE_2D );
}
예제 #9
0
void GfxRend::
Disk( float x, float y, float innerRad, float outerRad, Rgba col, float accuracy ) {
   col.Select();
   glDisable( GL_TEXTURE_2D );
   
   DiskRender( x, y, innerRad, outerRad, col, col, accuracy, false );
   
   if( Settings::TextureMappingUsed() )
      glEnable( GL_TEXTURE_2D );
}
예제 #10
0
void GfxRend::
Point( float x, float y, Rgba col ) {
   col.Select();
   glDisable( GL_TEXTURE_2D );
   
   glBegin( GL_POINTS );
      glVertex2f( x + 0.5, y + 0.5 );
   glEnd();
   
   if( Settings::TextureMappingUsed() )
      glEnable( GL_TEXTURE_2D );
}
예제 #11
0
const Rgba Interpolate(const Rgba& start, const Rgba& end, float fractionFromStartToEnd) {

	float lerpedR = Interpolate(start.fR(), end.fR(), fractionFromStartToEnd);
	float lerpedG = Interpolate(start.fG(), end.fG(), fractionFromStartToEnd);
	float lerpedB = Interpolate(start.fB(), end.fB(), fractionFromStartToEnd);
	float lerpedA = Interpolate(start.fA(), end.fA(), fractionFromStartToEnd);

	unsigned char lerpedCR = Rgba::cR(lerpedR);
	unsigned char lerpedCG = Rgba::cG(lerpedG);
	unsigned char lerpedCB = Rgba::cB(lerpedB);
	unsigned char lerpedCA = Rgba::cA(lerpedA);

	return Rgba(lerpedCR, lerpedCG, lerpedCB, lerpedCA);
}
예제 #12
0
void GfxRend::
CircleGradient( float x, float y, float rad, Rgba innerCol, Rgba outerCol, float accuracy ) {
   glDisable( GL_TEXTURE_2D );
   
   float da = GetAngleIncrement( rad, accuracy );
   
   glBegin( GL_TRIANGLE_FAN );
      innerCol.Select();
      glVertex2f( x, y );
      
      outerCol.Select();
      
      for( float a = 0.0; a < 2 * AL_PI; a += da ) {
         glVertex2f( x + cos(a) * rad, y + sin(a) * rad );
      }
      
      glVertex2f( x + rad, y );
   glEnd();
   
   if( Settings::TextureMappingUsed() )
      glEnable( GL_TEXTURE_2D );
}
예제 #13
0
void GfxRend::
Polygon( float *xCoordinates, float *yCoordinates, int numCoordinates, Rgba col ) {
   col.Select();
   glDisable( GL_TEXTURE_2D );
   
   glBegin( GL_POLYGON );
      for( int i = 0; i < numCoordinates; i++ ) {
         glVertex2f(xCoordinates[i], yCoordinates[i]);
      }
   glEnd();
   
   if( Settings::TextureMappingUsed() )
      glEnable( GL_TEXTURE_2D );
}
예제 #14
0
void GfxRend::
Triangle( float x1, float y1, float x2, float y2, float x3, float y3, Rgba col ) {
   col.Select();
   glDisable( GL_TEXTURE_2D );
   
   glBegin( GL_TRIANGLES );
      glVertex2f( x1, y1 );
      glVertex2f( x2, y2 );
      glVertex2f( x3, y3 );
   glEnd();
   
   if( Settings::TextureMappingUsed() )
      glEnable( GL_TEXTURE_2D );
}
예제 #15
0
   void DrawOutline( const Rgba &color ) const {
   #ifdef OL_NO_STATE_CHANGE
      GLboolean texturesEnabled;
      glGetBooleanv( GL_TEXTURE_2D, &texturesEnabled );
   #endif
      glDisable( GL_TEXTURE_2D );
      color.Select();

      ExecDrawOutline();

   #ifdef OL_NO_STATE_CHANGE
      if( texturesEnabled )
         glEnable( GL_TEXTURE_2D );
   #endif
   }
예제 #16
0
void Line::
Draw( const Rgba &color1, const Rgba &color2 ) const {
   glLineWidth( lineWidth );

#ifdef OL_NO_STATE_CHANGE
   GLboolean texturesEnabled;
   glGetBooleanv( GL_TEXTURE_2D, &texturesEnabled );
#endif
   glDisable( GL_TEXTURE_2D );
   glPushMatrix();
   glTranslatef( origin.x, origin.y, 0.0 );
   glBegin( GL_LINES );
      color1.Select();
      glVertex2f( start.x, start.y );
      color2.Select();
      glVertex2f( end.x, end.y );
   glEnd();
   glPopMatrix();

#ifdef OL_NO_STATE_CHANGE
   if( texturesEnabled )
      glEnable( GL_TEXTURE_2D );
#endif
}
예제 #17
0
void GfxRend::
TriangleOutline( float x1, float y1, float x2, float y2, float x3, float y3, Rgba col, float lineWidth ) {
   col.Select();
   glDisable( GL_TEXTURE_2D );
   glLineWidth( lineWidth );
   
   glBegin( GL_LINE_LOOP );
      glVertex2f( x1, y1 );
      glVertex2f( x2, y2 );
      glVertex2f( x3, y3 );
   glEnd();
   
   if( Settings::TextureMappingUsed() )
      glEnable( GL_TEXTURE_2D );
}
예제 #18
0
void GfxRend::
PolygonOutline( float *xCoordinates, float *yCoordinates, int numCoordinates, Rgba col, float lineWidth ) {
   col.Select();
   glDisable( GL_TEXTURE_2D );
   glLineWidth( lineWidth );
   
   glBegin( GL_LINE_LOOP );
      for( int i = 0; i < numCoordinates; i++ ) {
         glVertex2f(xCoordinates[i], yCoordinates[i]);
      }
   glEnd();
   
   if( Settings::TextureMappingUsed() )
      glEnable( GL_TEXTURE_2D );
}
예제 #19
0
void GfxRend::
Rect( float x, float y, float w, float h, Rgba col ) {
   col.Select();
   glDisable( GL_TEXTURE_2D );
   
   glBegin( GL_QUADS );
      
      glVertex2f( x, y+h );
      glVertex2f( x+w, y+h );
      glVertex2f( x+w, y );
      glVertex2f( x, y );
      
   glEnd();
   
   if( Settings::TextureMappingUsed() )
      glEnable( GL_TEXTURE_2D );
}
예제 #20
0
void ol::Ellipse::
DrawSlice( const Rgba &color1, const Rgba &color2, float startAngle, float angleSweep ) const {
#ifdef OL_NO_STATE_CHANGE
   GLboolean texturesEnabled;
   glGetBooleanv( GL_TEXTURE_2D, &texturesEnabled );
#endif
   glDisable( GL_TEXTURE_2D );
      
   glPushMatrix();
   glTranslatef( pos.x, pos.y, 0.0 );
   RotateMatrix( angle );
   
   float endAngle = startAngle - angleSweep; 
   
   if( endAngle < startAngle ){
     float temp = startAngle;
     startAngle = endAngle;
     endAngle = temp;
   }
   
   glBegin( GL_TRIANGLE_FAN );
      glVertex2f( 0.0, 0.0 );
      
      float mixAlpha = 0.0;
      float mixIncr = angleIncrement / (endAngle - startAngle);
      
      for( float a = startAngle; a < endAngle; a += angleIncrement ) {
         color1.MixWith( color2, mixAlpha ).Select();
         glVertex2f( cos(a) * xRad, sin(a) * yRad );
         mixAlpha += mixIncr;
      }
      
      glVertex2f( cos( endAngle ) * xRad, sin( endAngle ) * yRad );
   glEnd();
   
   glPopMatrix();
   
#ifdef OL_NO_STATE_CHANGE
   if( texturesEnabled )
      glEnable( GL_TEXTURE_2D );
#endif
}
예제 #21
0
void GfxRend::
EllipseSlice( float x, float y, float xRad, float yRad, Rgba col, float startAngle, float sweepAngle, float angle, float accuracy ) {
   col.Select();
   glDisable( GL_TEXTURE_2D );
   
   glPushMatrix();
   glTranslatef( x, y, 0.0 );
   RotateMatrix( angle );
   
   float da = 1.0;
   
   if( xRad < yRad )
      da = GetAngleIncrement( xRad, accuracy );
   else
      da = GetAngleIncrement( yRad, accuracy );
   
   float endAngle = startAngle - sweepAngle; 
   
   if( endAngle < startAngle ){
     float temp = startAngle;
     startAngle = endAngle;
     endAngle = temp;
   }
   
   glBegin( GL_TRIANGLE_FAN );
      glVertex2f( 0.0, 0.0 );
       
      for( float a = startAngle; a < endAngle; a += da ) {
         glVertex2f( cos(a) * xRad, sin(a) * yRad );
      }
      
      glVertex2f( cos( endAngle ) * xRad, sin( endAngle ) * yRad );
   glEnd();
   
   glPopMatrix();
   
   if( Settings::TextureMappingUsed() )
      glEnable( GL_TEXTURE_2D );
}
예제 #22
0
void GfxRend::
CircleOutline( float x, float y, float rad, Rgba col, float lineWidth, float accuracy ) {
   col.Select();
   glDisable( GL_TEXTURE_2D );
   
   if( lineWidth > 1 + OL_NEAR_ZERO ) {
      Disk( x, y, rad - lineWidth, rad + lineWidth, col, accuracy );
      return;
   }
   
   glLineWidth( lineWidth );
   
   float da = GetAngleIncrement( rad, accuracy );
   
   glBegin( GL_LINE_LOOP );
      for( float a = 0.0; a < 2 * AL_PI; a += da ) {
         glVertex2f( x + cos(a) * rad, y + sin(a) * rad );
      }
   glEnd();
   
   if( Settings::TextureMappingUsed() )
      glEnable( GL_TEXTURE_2D );
}
예제 #23
0
	void  RiverManager::loadRiverInfo(const String& filename, const TiXmlElement* elemNode)
	{
		if (!elemNode)
		{
			return ;
		}

		const TiXmlAttribute* attr = NULL;
		const TiXmlElement* elem;
		const char* v(NULL);

		for (elem = elemNode->FirstChildElement(); elem; elem = elem->NextSiblingElement()) 
		{
			const String& value = elem->ValueTStr();
			
			if (value == "RiverManager") 
			{
				
			}
			else if (value == "RiverDef")
			{
				addRiverDef(RiverDef());
				RiverDef& riverDef = m_riverDefSet[m_riverDefSet.size()-1];

				if (v = elem->Attribute("name"))
				{
					riverDef.setName(v);
				}

				double d;
				if (elem->Attribute("width", &d))
				{
					riverDef.setWidth(d);
				}

				if (elem->Attribute("depth", &d))
				{
					riverDef.setDepth(d);
				}

				if (v = elem->Attribute("fogColor"))
				{
					Rgba color;
					color.fromString(v);
					riverDef.setFogColor(color);
				}
				
				if (elem->Attribute("intervalLength", &d))
				{
					riverDef.getSpline().setIntervalLength(d);
				}

				int n;
				if (elem->Attribute("closed", &n))
				{
					riverDef.getSpline().setClosed(n != 0);
				}
				
				if (v = elem->Attribute("controlPoints"))
				{
					const char* pCh = v;
					Vector3 point;
					Spline& spline = riverDef.getSpline();
					String token;
					int pass=0;

					for (int i=0; v[i]!='\0'; ++i)
					{
						if (v[i] == ' ')
						{
							if (pass == 0)
							{
								point.x = (float) atof(token.c_str());
								++pass;
							}
							else if (pass == 1)
							{
								point.y = (float) atof(token.c_str());
								++pass;
							}
							else if (pass == 2)
							{
								point.z = (float) atof(token.c_str());
								spline.addControlPoint(point);
								pass = 0;
							}

							token.clear();
						}
						else
						{
							token += v[i];
						}
					}
				}
			}
		} // for
	}
예제 #24
0
 // Draws a filled disk //
 void DrawDisk( const Rgba &color, float innerXRadius, float innerYRadius ) const {
    color.Select();
    DiskRender( color, color, innerXRadius, innerYRadius, false );
 }
예제 #25
0
void GfxRend::
EllipseOutline( float x, float y, float xRad, float yRad,
                Rgba col, float angle, float lineWidth, float accuracy ) {
   col.Select();
   glDisable( GL_TEXTURE_2D );
   
   glPushMatrix();
   glTranslatef( x, y, 0.0 );
   RotateMatrix( angle );
   
   float da = 1.0;
   
   if( xRad < yRad )        
      da = GetAngleIncrement( xRad, accuracy );
   else
      da = GetAngleIncrement( yRad, accuracy );
   
   
   float innerXRad = xRad - lineWidth;
   float outerXRad = xRad + lineWidth;
   
   glBegin( GL_QUADS );
      float prevIX = innerXRad;
      float prevIY = 0.0;
      
      float prevOX = outerXRad;
      float prevOY = 0.0;
      
      for( float a = 0.0; a <= 2 * AL_PI; a += da ) {
         float cosa = cos(a);
         float sina = sin(a);
         
         float newIX = cosa * innerXRad;
         float newIY = sina * (yRad - lineWidth);
         
         float newOX = cosa * outerXRad;
         float newOY = sina * (yRad + lineWidth);
         
         glVertex2f( newIX, newIY );
         glVertex2f( prevIX, prevIY );
         
         glVertex2f( prevOX, prevOY );
         glVertex2f( newOX, newOY );
         
         prevIX = newIX;
         prevIY = newIY;
         
         prevOX = newOX;
         prevOY = newOY;
      }
         
      glVertex2f( innerXRad, 0.0 );
      glVertex2f( prevIX, prevIY );
      
      glVertex2f( prevOX, prevOY );
      glVertex2f( outerXRad, 0.0 );
   glEnd();
   
   glPopMatrix();
   
   if( Settings::TextureMappingUsed() )
      glEnable( GL_TEXTURE_2D );
}
예제 #26
0
Vector4 ToVector4(const Rgba& colorToConvert){
	return colorToConvert.ToVector4();
}
예제 #27
0
void ol::Ellipse::
DiskRender( const Rgba &innerCol, const Rgba &outerCol, float innerXRad, float innerYRad, bool setCols ) const {
#ifdef OL_NO_STATE_CHANGE
   GLboolean texturesEnabled;
   glGetBooleanv( GL_TEXTURE_2D, &texturesEnabled );
#endif
   glDisable( GL_TEXTURE_2D );
   
   glPushMatrix();
   glTranslatef( pos.x, pos.y, 0.0 );
   RotateMatrix( angle );
   
   glBegin( GL_QUADS );
      float prevIX = innerXRad;
      float prevIY = 0.0;
      
      float prevOX = xRad;
      float prevOY = 0.0;
      
      for( float a = 0.0; a <= 2 * AL_PI; a += angleIncrement ) {
         float cosa = cos(a);
         float sina = sin(a);
         
         float newIX = cosa * innerXRad;
         float newIY = sina * innerYRad;
         
         float newOX = cosa * xRad;
         float newOY = sina * yRad;
         
         if( setCols )
            innerCol.Select();
         
         glVertex2f( newIX, newIY );
         glVertex2f( prevIX, prevIY );
         
         if( setCols )
            outerCol.Select();
         
         glVertex2f( prevOX, prevOY );
         glVertex2f( newOX, newOY );
         
         prevIX = newIX;
         prevIY = newIY;
         
         prevOX = newOX;
         prevOY = newOY;
      }
      
      if( setCols )
         innerCol.Select();
      
      glVertex2f( innerXRad, 0.0 );
      glVertex2f( prevIX, prevIY );
      
      if( setCols )
         outerCol.Select();
      
      glVertex2f( prevOX, prevOY );
      glVertex2f( xRad, 0.0 );
   glEnd();
   
   glPopMatrix();
   
#ifdef OL_NO_STATE_CHANGE
   if( texturesEnabled )
      glEnable( GL_TEXTURE_2D );
#endif
}
예제 #28
0
void ol::Ellipse::
DrawArc( const Rgba &innerColor, const Rgba &outerColor, float startAngle, float angleSweep,
         float innerXRad, float innerYRad ) const {
#ifdef OL_NO_STATE_CHANGE
   GLboolean texturesEnabled;
   glGetBooleanv( GL_TEXTURE_2D, &texturesEnabled );
#endif
   glDisable( GL_TEXTURE_2D );
   
   glPushMatrix();
   glTranslatef( pos.x, pos.y, 0.0 );
   RotateMatrix( angle );
   
   float endAngle = startAngle - angleSweep; 
   
   if( endAngle < startAngle ) {
     float temp = startAngle;
     startAngle = endAngle;
     endAngle = temp;
   }
   
   glBegin( GL_QUADS );
      float prevIX = cos( startAngle ) * innerXRad;
      float prevIY = sin( startAngle ) * innerYRad;
      
      float prevOX = cos( startAngle ) * xRad;
      float prevOY = sin( startAngle ) * yRad;
      
      for( float a = startAngle; a < endAngle; a += angleIncrement ) {
         float cosa = cos(a);
         float sina = sin(a);
         
         float newIX = cosa * innerXRad;
         float newIY = sina * innerYRad;
         
         float newOX = cosa * xRad;
         float newOY = sina * yRad;
         
         innerColor.Select();
         glVertex2f( newIX, newIY );
         glVertex2f( prevIX, prevIY );
         
         outerColor.Select();
         glVertex2f( prevOX, prevOY );
         glVertex2f( newOX, newOY );
         
         prevIX = newIX;
         prevIY = newIY;
         
         prevOX = newOX;
         prevOY = newOY;
      }
      
      innerColor.Select();
      glVertex2f( cos( endAngle ) * innerXRad, sin( endAngle ) * innerYRad );
      glVertex2f( prevIX, prevIY );
      
      outerColor.Select();
      glVertex2f( prevOX, prevOY );
      glVertex2f( cos( endAngle ) * xRad, sin( endAngle ) * yRad ); 
   glEnd();
   
   glPopMatrix();
   
#ifdef OL_NO_STATE_CHANGE
   if( texturesEnabled )
      glEnable( GL_TEXTURE_2D );
#endif
}
//-----------------------------------------------------------------------------------------------
void SetColor( const Rgba& color, float alpha )
{
    Rgba colorWithAlphaApplied = color;
    colorWithAlphaApplied.ScaleAlpha( alpha );
    glColor4ub( colorWithAlphaApplied.r, colorWithAlphaApplied.g, colorWithAlphaApplied.b, colorWithAlphaApplied.a );
}
예제 #30
0
void GfxRend::
LineStripRender( float *xCoordinates, float *yCoordinates, int numCoordinates, Rgba *cols,
                 float lineWidth, bool singleColor, bool useSideColors,
                 Rgba leftCol, Rgba rightCol ) {
   if( singleColor )
      cols->Select();
   else
      cols[0].Select();
   
   glDisable( GL_TEXTURE_2D );
   
   // Find the normal of the beginning of the strip //
   
   float lastX = xCoordinates[0];
   float lastY = yCoordinates[0];
   
   float lastSx = xCoordinates[1] - lastX;
   float lastSy = yCoordinates[1] - lastY;
   
   float lastSLength = sqrt( lastSx * lastSx + lastSy * lastSy );
   
   lastSx /= lastSLength;
   lastSy /= lastSLength;
   
   float lastUpperX = lastX + lastSy * lineWidth;
   float lastUpperY = lastY - lastSx * lineWidth;
   
   float lastLowerX = lastX - lastSy * lineWidth;
   float lastLowerY = lastY + lastSx * lineWidth;
   
   // Render the begin of the strip //
   
   if( !useSideColors ) {
      glBegin( GL_QUAD_STRIP );
         glVertex2f( lastUpperX, lastUpperY );
         glVertex2f( lastLowerX, lastLowerY );
   }
   
   for( int i = 1; i < numCoordinates-1; i++ ) {
      float x = xCoordinates[i];
      float y = yCoordinates[i];
      
      if( x == lastX && y == lastY ) {
         continue;
      }
      
      // Find the direction vector from the next point to the current one //
      
      float bx = x - xCoordinates[i+1];
      float by = y - yCoordinates[i+1];
      
      float bLength = sqrt( bx * bx + by * by );
      
      if( bLength > -OL_NEAR_ZERO && bLength < OL_NEAR_ZERO ) {
         continue;
      }
      
      bx /= bLength;
      by /= bLength;
      
      // Find the direction vector of the displacement //
      
      float cx = lastSx + bx;
      float cy = lastSy + by;
      
      float cLength = sqrt( cx * cx + cy * cy );
      
      float nx, ny;
      
      if( cLength > -OL_NEAR_ZERO && cLength < OL_NEAR_ZERO ) {
         nx = -by;
         ny = bx;
         
         float nRatio = lineWidth/sqrt( nx * nx + ny * ny );
         
         nx *= nRatio;
         ny *= nRatio;
      }
      else {
         cx /= cLength;
         cy /= cLength;
      
         // Make sure that the displacement happens always in the same side //
         
         float diff1 = lastSx - bx;
         float diff2 = lastSy - by;
         float diff3 = cx - bx;
         float diff4 = cy - by;
         
         if(( diff1 * diff4 ) - ( diff2 * diff3 ) > 0) {
            cx = -cx;
            cy = -cy;
         }
         
         // Find the displacement multiplicator //
         
         float s = lastSy * cx + (-lastSx) * cy;
         
         nx = cx * lineWidth / s;
         ny = cy * lineWidth / s;
      }
      
      // Find the displaced coordinates //
      
      float upperX = x + nx;
      float upperY = y + ny;
      
      float lowerX = x - nx;
      float lowerY = y - ny;
      
      
      if( !useSideColors ) {
         if( !singleColor )
            cols[i].Select();
         
         glVertex2f( upperX, upperY );
         glVertex2f( lowerX, lowerY );
      }
      else {
         glBegin( GL_QUAD_STRIP );
            // Upper side //
            leftCol.Select();
            glVertex2f( lastUpperX, lastUpperY );
            glVertex2f( upperX, upperY );
            
            // Middle //
            if( !singleColor )
               cols[i-1].Select();
            else
               cols->Select();
            
            glVertex2f( lastX, lastY );
            
            if( !singleColor )
               cols[i].Select();
            
            glVertex2f( x, y );
            
            // Lower side //
            rightCol.Select();
            glVertex2f( lastLowerX, lastLowerY );
            glVertex2f( lowerX, lowerY );
         glEnd();
      }
      
      // Store the information which can be used when calculating the next point //
      
      lastX = x;
      lastY = y;
      
      lastSx = -bx;
      lastSy = -by;
      
      lastUpperX = upperX;
      lastUpperY = upperY;
      
      lastLowerX = lowerX;
      lastLowerY = lowerY;
   }
   
   // Render the end of the strip //
   
   int lastIndex = numCoordinates-1;
   
   float x = xCoordinates[lastIndex];
   float y = yCoordinates[lastIndex];
   
   float upperX = x + lastSy * lineWidth;
   float upperY = y - lastSx * lineWidth;
   
   float lowerX = x - lastSy * lineWidth;
   float lowerY = y + lastSx * lineWidth;
   
   if( !useSideColors ) {
         if( !singleColor )
            cols[lastIndex].Select();
         
         glVertex2f( upperX, upperY );
         glVertex2f( lowerX, lowerY );
      
      glEnd();
   }
   else {
      glBegin( GL_QUAD_STRIP );
         // Upper side //
         leftCol.Select();
         glVertex2f( lastUpperX, lastUpperY );
         glVertex2f( upperX, upperY );
         
         // Middle //
         if( !singleColor )
            cols[lastIndex-1].Select();
         else
            cols->Select();
         
         glVertex2f( lastX, lastY );
         
         if( !singleColor )
            cols[lastIndex].Select();
         
         glVertex2f( x, y );
         
         // Lower side //
         rightCol.Select();
         glVertex2f( lastLowerX, lastLowerY );
         glVertex2f( lowerX, lowerY );
      glEnd();
   }
   
   if( Settings::TextureMappingUsed() )
      glEnable( GL_TEXTURE_2D );
}