Exemplo n.º 1
0
/********************************************//**
 * \brief Draw a line on image in a given color
 * \warning NOT FUNCTIONNAL
 * \param img t_img* - image to modify (also output)
 * \param pix1 t_pixel - first point of line
 * \param pix2 t_pixel - second point of line
 * \param RGB CPU_INT32U - color of the line
 * \return t_vect - vector representing the line
 *
 * Needs to be done
 * Helpfull macro to define color is SetRGB(r,g,b), with value between 0 and 255
 ***********************************************/
t_vect highlight_line(t_img * img,t_pixel pix1,t_pixel pix2,CPU_INT32U RGB)
{
    t_vect v;
    CPU_FP32 a, b, y_calc;
    CPU_INT16S i,j;

    t_simplearea area_of_draw;

    if((pix2.x - pix1.x) != 0)
    {
        a = ((CPU_FP32)pix2.y - (CPU_FP32)pix1.y) / (((CPU_FP32)pix2.x - (CPU_FP32)pix1.x));
    }else
    {
        a = 1000000;
    }


    b = (CPU_FP32)pix1.y - a * (CPU_FP32)pix1.x;

    //printf("y = %.2f x + %.2f\n",a,b);

    area_of_draw.BotLeft.x = mini(pix1.x,pix2.x);
    area_of_draw.BotLeft.y = mini(pix1.y,pix2.y);
    area_of_draw.TopRight.x = maxi(pix1.x,pix2.x);
    area_of_draw.TopRight.y = maxi(pix1.y,pix2.y);


    for(i=area_of_draw.BotLeft.y;i<= area_of_draw.TopRight.y ;i++)
    {
        for(j=area_of_draw.BotLeft.x ; (j<= area_of_draw.TopRight.x );j++)
        {
                //check if point belong to the line between pix1 and pix 2
                y_calc = a * j + b;
                if(((CPU_INT16S)y_calc -abs(a)/1.5 <= i)&&((CPU_INT16S)y_calc +abs(a)/1.5 >= i))
                {
                    img->Red[i][j] = GetRed(RGB);
                    img->Green[i][j] = GetGreen(RGB);
                    img->Blue[i][j] = GetBlue(RGB);
                }else
                {
                    //nothing
                }


        }
    }
    v.x = 5;
    v.y = a * v.x + b;
    return v;
}
Exemplo n.º 2
0
/**
 *  zeichnet ein Rechteck.
 *
 *  @param[in] x X-Koordinate
 *
 *  @author OLiver
 */
void Window::DrawRectangle(unsigned short x, unsigned short y, unsigned short width, unsigned short height, unsigned int color)
{
	glDisable(GL_TEXTURE_2D);

	glColor4ub(GetRed(color), GetGreen(color), GetBlue(color), GetAlpha(color));

	glBegin(GL_QUADS);
	glVertex2i(x, y);
	glVertex2i(x, y+height);
	glVertex2i(x+width, y+height);
	glVertex2i(x+width, y);
	glEnd();

	glEnable(GL_TEXTURE_2D);
}
Exemplo n.º 3
0
/**
 *  Variiert die übergebene Farbe zufällig in der Helligkeit
 *
 *  @author OLiver
 */
unsigned Minimap::VaryBrightness(const unsigned color, const int range) const
{
	int add = 100 - rand()%(2*range);

	int red = GetRed(color)*add/100;
	if(red < 0) red = 0;
	else if(red > 0xFF) red = 0xFF;
	int green = GetGreen(color)*add/100;
	if(green < 0) green = 0;
	else if(green > 0xFF) green = 0xFF;
	int blue = GetBlue(color)*add/100;
	if(blue < 0) blue = 0;
	else if(blue > 0xFF) blue = 0xFF;

	return MakeColor(GetAlpha(color), red, green, blue);
}
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppRainbow.htm
void Rainbow(
  const double x, 
  unsigned char& r, 
  unsigned char& g,
  unsigned char& b)
{
  const int r0 = GetRed(x);
  const int g0 = GetGreen(x);
  const int b0 = GetBlue(x);
  const int max = std::max(r0, std::max(g0,b0));
  assert(max!=0);

  r = 255.0 * static_cast<double>(r0) / static_cast<double>(max);
  g = 255.0 * static_cast<double>(g0) / static_cast<double>(max);
  b = 255.0 * static_cast<double>(b0) / static_cast<double>(max);
}
/**
 *  Zeichnet die Textur.
 */
void glArchivItem_Bitmap::Draw(Rect dstArea, Rect srcArea, unsigned color /*= COLOR_WHITE*/)
{
    if(GetTexture() == 0)
        return;

    RTTR_Assert(dstArea.getSize().x > 0 && dstArea.getSize().y > 0);
    RTTR_Assert(srcArea.getSize().x > 0 && srcArea.getSize().y > 0);
    // Compatibility only!
    Extent srcSize = srcArea.getSize();
    if(srcSize.x == 0)
        srcSize.x = getWidth();
    if(srcSize.y == 0)
        srcSize.y = getHeight();
    srcArea.setSize(srcSize);
    Extent dstSize = dstArea.getSize();
    if(dstSize.x == 0)
        dstSize.x = srcSize.x;
    if(dstSize.y == 0)
        dstSize.y = srcSize.y;
    dstArea.setSize(dstSize);

    RTTR_Assert(getBobType() != libsiedler2::BOBTYPE_BITMAP_PLAYER);

    std::array<Point<GLfloat>, 4> texCoords, vertices;

    dstArea.move(-GetOrigin());

    vertices[0].x = vertices[1].x = GLfloat(dstArea.left);
    vertices[2].x = vertices[3].x = GLfloat(dstArea.right);
    vertices[0].y = vertices[3].y = GLfloat(dstArea.top);
    vertices[1].y = vertices[2].y = GLfloat(dstArea.bottom);

    Point<GLfloat> srcOrig = Point<GLfloat>(srcArea.getOrigin()) / GetTexSize();
    Point<GLfloat> srcEndPt = Point<GLfloat>(srcArea.getEndPt()) / GetTexSize();
    texCoords[0].x = texCoords[1].x = srcOrig.x;
    texCoords[2].x = texCoords[3].x = srcEndPt.x;
    texCoords[0].y = texCoords[3].y = srcOrig.y;
    texCoords[1].y = texCoords[2].y = srcEndPt.y;

    glVertexPointer(2, GL_FLOAT, 0, vertices.data());
    glTexCoordPointer(2, GL_FLOAT, 0, texCoords.data());
    VIDEODRIVER.BindTexture(GetTexture());
    glColor4ub(GetRed(color), GetGreen(color), GetBlue(color), GetAlpha(color));
    glDrawArrays(GL_QUADS, 0, 4);
}
Exemplo n.º 6
0
/**
 *  Berechnet für einen bestimmten Punkt und ein Dreieck die normale Terrainfarbe
 *
 *  @author OLiver
 */
unsigned IngameMinimap::CalcTerrainColor(const MapCoord x, const MapCoord y, const unsigned t)
{
	unsigned color = TERRAIN_COLORS[gwv.GetLandscapeType()][ (t==0) ? gwv.GetNode(x,y).t1 : gwv.GetNode(x,y).t2];

	// Schattierung
	int shadow = gwv.GetNode(x,y).shadow;
	int r = GetRed(color)+shadow-0x40;
	int g = GetGreen(color)+shadow-0x40;
	int b = GetBlue(color)+shadow-0x40;

	if(r < 0) r = 0;
	else if(r > 255) r = 255;
	if(g < 0) g = 0;
	else if(g > 255) g = 255;
	if(b < 0) b = 0;
	else if(b > 255) b = 255;

	return MakeColor(0xFF,unsigned(r),unsigned(g),unsigned(b));
}
Exemplo n.º 7
0
/**
 *  Calculate the normal terrain color for a given point and triangle
 */
unsigned IngameMinimap::CalcTerrainColor(const MapPoint pt, const unsigned t)
{
    unsigned color = TerrainData::GetColor(gwv.GetWorld().GetLandscapeType(), (t == 0) ? gwv.GetNode(pt).t1 : gwv.GetNode(pt).t2); //-V807

    // Schattierung
    int shadow = gwv.GetNode(pt).shadow;
    int r = GetRed(color) + shadow - 0x40;
    int g = GetGreen(color) + shadow - 0x40;
    int b = GetBlue(color) + shadow - 0x40;

    if(r < 0) r = 0;
    else if(r > 255) r = 255;
    if(g < 0) g = 0;
    else if(g > 255) g = 255;
    if(b < 0) b = 0;
    else if(b > 255) b = 255;

    return MakeColor(0xFF, unsigned(r), unsigned(g), unsigned(b));
}
Exemplo n.º 8
0
/********************************************//**
 * \brief Draw a rectangular area on image in a given color
 *
 * \param img t_img* - image to modify (also output)
 * \param area t_area* - area to highlight
 * \param RGB CPU_INT32U - highlight color
 * \return CPU_VOID
 *
 * Helpfull macro to define color is SetRGB(r,g,b), with value between 0 and 255
 ***********************************************/
CPU_VOID highlight_area(t_img * img,t_area * area,CPU_INT32U RGB)
{
    CPU_INT16S i,j;

    for(i=0;i< img->he ;i++)
    {
        for(j=0 ; j< img->wi ;j++)
        {
            if  (
                    (((j >= area->BotLeft.x)  && (j <= area->BotRight.x)) && ((i == area->BotLeft.y)  || (i == area->BotRight.y)))
                ||  (((j >= area->TopLeft.x)  && (j <= area->TopRight.x)) && ((i == area->TopLeft.y)  || (i == area->TopRight.y)))
                ||  (((i >= area->BotLeft.y)  && (i <= area->TopLeft.y) ) && ((j == area->BotLeft.x)  || (j == area->TopLeft.x)) )
                ||  (((i >= area->BotRight.y) && (i <= area->TopRight.y)) && ((j == area->BotRight.x) || (j == area->TopRight.x)))
                )
            {
                img->Green[i][j]= GetGreen(RGB);
                img->Blue[i][j] = GetBlue(RGB);
                img->Red[i][j]  = GetRed(RGB);
            }
        }
    }
}
Exemplo n.º 9
0
/**
 *  Zusätzliche Dinge, die die einzelnen Maps vor dem Zeichenvorgang zu tun haben
 *  in dem Falle: Karte aktualisieren
 *
 *  @author OLiver
 */
void IngameMinimap::BeforeDrawing()
{
	// Ab welcher Knotenanzahl (Teil der Gesamtknotenanzahl) die Textur komplett neu erstellt werden soll
	static const unsigned MAX_NODES_UPDATE_DENOMINATOR = 2; // (2 = 1/2, 3 = 1/3 usw.)

	// Überhaupt Änderungen nötig?
	if(nodes_updated_list.size())
	{
		// Komplette Textur neu erzeugen, weil es zu viele Knoten sind?
		if(nodes_updated_list.size() >= map_width*map_height/MAX_NODES_UPDATE_DENOMINATOR)
		{
			// Ja, alles neu erzeugen
			UpdateAll();
			// Alles Aktualisierungen wieder zurücksetzen
			for(MapCoord y = 0;y<map_height;++y)
			{
				for(MapCoord x = 0;x<map_width;++x)
					nodes_updated[y*map_width+x] = false;
			}
		}
		else
		{
			// Entsprechende Pixel updaten
			for(list<Node>::iterator it = nodes_updated_list.begin();it.valid();++it)
			{
				for(unsigned t = 0;t<2;++t)
				{
					unsigned color = CalcPixelColor(&gwv,it->x,it->y,t);
					map.tex_setPixel((it->x*2+t+(it->y&1))%(map_width*2),it->y,GetRed(color),GetGreen(color),
						GetBlue(color),GetAlpha(color));
				}
				// Jetzt muss er nicht mehr geändert werden
				nodes_updated[it->y*map_width+it->x] = false;
			}
		}

		this->nodes_updated_list.clear();
	}
}
Exemplo n.º 10
0
/**
 *  Alle Punkte Updaten, bei denen das DrawnObject 
 *  gleich dem übergebenen drawn_object ist
 *
 *  @author OLiver
 */
void IngameMinimap::UpdateAll(const DrawnObject drawn_object)
{
	// Gesamte Karte neu berechnen
	for(MapCoord y = 0;y<map_height;++y)
	{
		for(MapCoord x = 0;x<map_width;++x)
		{
			for(unsigned t = 0;t<2;++t)
			{
				if(dos[y*map_width+x] == drawn_object ||  // das gewünschte Objekt
					(drawn_object == DO_PLAYER && // bei DO_PLAYER auf evtl. nicht gezeichnete Häuser und Straßen
					((dos[y*map_width+x] == DO_BUILDING && !houses) || // achten, da dort auch nur das Player-
					(dos[y*map_width+x] == DO_ROAD && !roads)))) // Territorium zu sehen ist!
				{
					unsigned color = CalcPixelColor(&gwv,x,y,t);
					map.tex_setPixel((x*2+t+(y&1))%(map_width*2),y,GetRed(color),GetGreen(color),
									GetBlue(color),GetAlpha(color));
				}
			}
		}
	}
}
Exemplo n.º 11
0
/**
 *  Update all nodes with the given drawn object
 */
void IngameMinimap::UpdateAll(const DrawnObject drawn_object)
{
    // Gesamte Karte neu berechnen
    for(MapCoord y = 0; y < map_height; ++y)
    {
        for(MapCoord x = 0; x < map_width; ++x)
        {
            MapPoint pt(x, y);
            for(unsigned t = 0; t < 2; ++t)
            {
                if(dos[GetMMIdx(pt)] == drawn_object ||
                    (drawn_object == DO_PLAYER && // for DO_PLAYER check for not drawn buildings or roads as there is only the player territory visible
                        ((dos[GetMMIdx(pt)] == DO_BUILDING && !houses) ||
                            (dos[GetMMIdx(pt)] == DO_ROAD && !roads))))
                {
                    unsigned color = CalcPixelColor(pt, t);
                    map.tex_setPixel((x * 2 + t + (y & 1)) % (map_width * 2), y, GetRed(color), GetGreen(color),
                        GetBlue(color), GetAlpha(color));
                }
            }
        }
    }
}
Exemplo n.º 12
0
/* ================================================================
   塗りつぶし。

   αが0xff以外の時は, 
   各RGBに対して目標値と現在のピクセルとでαブレンディングする

   (※リトルエンディアンを仮定)
================================================================ */
void VnImage::Fill(u_int32_t color, const VnRect& rect)
{
  const u_int8_t r = GetRed(color);
  const u_int8_t g = GetGreen(color);
  const u_int8_t b = GetBlue(color);
  const u_int8_t a = GetAlpha(color);

  VnRect dst_rect(0, 0, Width(), Height());
  dst_rect &= rect;

  if (a == 0xff) {
    const u_int32_t fill_color = ToMachineColor(color);
//     cerr << "Fill: " << hex << fill_color << dec << endl;

    // 不透明塗りつぶし
    for(int y = 0; y < dst_rect.height; ++y) {
      u_int32_t* dst = GetPixelBuf(dst_rect.x, dst_rect.y + y);
      for(int x = 0; x < dst_rect.width; ++x, ++dst) {
        *dst = fill_color;
      }
    }
  } else {
    // αブレンディング

    for(int y = 0; y < dst_rect.height; ++y) {
      u_int32_t* dst = GetPixelBuf(dst_rect.x, dst_rect.y + y);
      for(int x = 0; x < dst_rect.width; ++x, ++dst) {
        // よりよい最適化は後回し
        // リトルエンディアンの場合, 0xAABBGGRRとなる
        const int dr = ((r - ( *dst        & 0xff)) * a) >> 8;
        const int dg = ((g - ((*dst >>  8) & 0xff)) * a) >> 8;
        const int db = ((b - ((*dst >> 16) & 0xff)) * a) >> 8;
        *dst += (dr | (dg << 8) | (db << 16));
      }
    }
  }
}
Exemplo n.º 13
0
// ****************************************************************************
//
//  Function Name:	RSolidColor::LightenBy( )
//
//  Description:		
//
//  Returns:			Nothing
//
//  Exceptions:		None
//
// ****************************************************************************
//
void RSolidColor::LightenBy( YScaleFactor scale )
	{
	YColorComponent	red	= GetRed();
	YColorComponent	green	= GetGreen();
	YColorComponent	blue	= GetBlue();
	uLONG				redder	= static_cast<uLONG>( ::Round( static_cast<YRealDimension>( kMaxColorComponent - red )  * scale ) );
	uLONG				greener	= static_cast<uLONG>( ::Round( static_cast<YRealDimension>( kMaxColorComponent - green )  * scale ) );
	uLONG				bluer		= static_cast<uLONG>( ::Round( static_cast<YRealDimension>( kMaxColorComponent - blue )  * scale ) );

	TpsAssert( ( scale >= 0.0 ), "Negative color component makes no sense." );
	TpsAssert( ( scale <= 1.0 ), "Bad color component scale factor." );

	redder = red + redder;
	if ( redder > kMaxColorComponent )
		red = kMaxColorComponent;
	else
		red = static_cast<YColorComponent>( redder );
	greener = green + greener;
	if ( greener > kMaxColorComponent )
		green = kMaxColorComponent;
	else
		green = static_cast<YColorComponent>( greener );
	bluer = blue + bluer;
	if ( bluer > kMaxColorComponent )
		blue = kMaxColorComponent;
	else
		blue = static_cast<YColorComponent>( bluer );

#ifdef	_WINDOWS							 
	m_Color = RGB( red, green, blue );
#endif	// _WINDOWS
#ifdef	MAC							 
	m_Color.red = red;
	m_Color.green = green;
	m_Color.blue = blue;
#endif	// MAC
	}
Exemplo n.º 14
0
 uint32 Color::ToRGBA() const
 {
     return (GetRed() << 24) | (GetGreen() << 16) | (GetBlue() << 8) | (GetAlpha() << 0);
 }
Exemplo n.º 15
0
PWL_CREATEPARAM CFFL_FormFiller::GetCreateParam() {
  ASSERT(m_pApp != NULL);

  PWL_CREATEPARAM cp;
  cp.pParentWnd = NULL;
  cp.pProvider = this;
  cp.rcRectWnd = GetPDFWindowRect();

  FX_DWORD dwCreateFlags = PWS_BORDER | PWS_BACKGROUND | PWS_VISIBLE;
  FX_DWORD dwFieldFlag = m_pWidget->GetFieldFlags();
  if (dwFieldFlag & FIELDFLAG_READONLY) {
    dwCreateFlags |= PWS_READONLY;
  }

  FX_COLORREF color;
  if (m_pWidget->GetFillColor(color)) {
    cp.sBackgroundColor =
        CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color));
  }

  if (m_pWidget->GetBorderColor(color)) {
    cp.sBorderColor =
        CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color));
  }

  cp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);

  if (m_pWidget->GetTextColor(color)) {
    cp.sTextColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color));
  }

  cp.fFontSize = m_pWidget->GetFontSize();
  cp.dwBorderWidth = m_pWidget->GetBorderWidth();

  int nBorderStyle = m_pWidget->GetBorderStyle();

  switch (nBorderStyle) {
    case BBS_SOLID:
      cp.nBorderStyle = PBS_SOLID;
      break;
    case BBS_DASH:
      cp.nBorderStyle = PBS_DASH;
      cp.sDash = CPWL_Dash(3, 3, 0);
      break;
    case BBS_BEVELED:
      cp.nBorderStyle = PBS_BEVELED;
      cp.dwBorderWidth *= 2;
      break;
    case BBS_INSET:
      cp.nBorderStyle = PBS_INSET;
      cp.dwBorderWidth *= 2;
      break;
    case BBS_UNDERLINE:
      cp.nBorderStyle = PBS_UNDERLINED;
      break;
  }

  if (cp.fFontSize <= 0) {
    dwCreateFlags |= PWS_AUTOFONTSIZE;
  }

  cp.dwFlags = dwCreateFlags;
  cp.pSystemHandler = m_pApp->GetSysHandler();
  return cp;
}
void glArchivItem_Bitmap_Player::Draw(short dst_x, short dst_y, short dst_w, short dst_h, short src_x, short src_y, short src_w, short src_h, const unsigned int color, const unsigned int player_color)
{
    if(texture == 0)
        GenerateTexture();
    if(texture == 0)
        return;

    if(src_w == 0)
        src_w = width;
    if(src_h == 0)
        src_h = height;
    if(dst_w == 0)
        dst_w = src_w;
    if(dst_h == 0)
        dst_h = src_h;

    struct GL_T2F_C4UB_V3F_Struct
    {
        GLfloat tx, ty;
        GLubyte r, g, b, a;
        GLfloat x, y, z;
    };

    GL_T2F_C4UB_V3F_Struct tmp[8];

    tmp[0].z = tmp[1].z = tmp[2].z = tmp[3].z = 0.0;

    int x = -nx + dst_x;
    int y = -ny + dst_y;

    tmp[0].x = tmp[1].x = GLfloat(x);
    tmp[2].x = tmp[3].x = GLfloat(x + dst_w);

    tmp[0].y = tmp[3].y = GLfloat(y);
    tmp[1].y = tmp[2].y = GLfloat(y + dst_h);

    tmp[0].tx = tmp[1].tx = (GLfloat)(src_x) / (GLfloat)tex_width / 2.0f;
    tmp[2].tx = tmp[3].tx = (GLfloat)(src_x + src_w) / (GLfloat)tex_width / 2.0f;

    tmp[0].ty = tmp[3].ty = (GLfloat)src_y / tex_height;
    tmp[1].ty = tmp[2].ty = (GLfloat)(src_y + src_h) / tex_height;

    tmp[4] = tmp[0];
    tmp[5] = tmp[1];
    tmp[6] = tmp[2];
    tmp[7] = tmp[3];

    tmp[4].tx += 0.5;
    tmp[5].tx += 0.5;
    tmp[6].tx += 0.5;
    tmp[7].tx += 0.5;

    tmp[0].r = tmp[1].r = tmp[2].r = tmp[3].r = GetRed(color);
    tmp[0].g = tmp[1].g = tmp[2].g = tmp[3].g = GetGreen(color);
    tmp[0].b = tmp[1].b = tmp[2].b = tmp[3].b = GetBlue(color);
    tmp[0].a = tmp[1].a = tmp[2].a = tmp[3].a = GetAlpha(color);

    tmp[4].r = tmp[5].r = tmp[6].r = tmp[7].r = GetRed(player_color);
    tmp[4].g = tmp[5].g = tmp[6].g = tmp[7].g = GetGreen(player_color);
    tmp[4].b = tmp[5].b = tmp[6].b = tmp[7].b = GetBlue(player_color);
    tmp[4].a = tmp[5].a = tmp[6].a = tmp[7].a = GetAlpha(player_color);

    glInterleavedArrays(GL_T2F_C4UB_V3F, 0, tmp);

    VideoDriverWrapper::inst().BindTexture(texture);

    glDrawArrays(GL_QUADS, 0, 8);
}
Exemplo n.º 17
0
 uint8 Color::ToGrey() const
 {
     return static_cast<uint8>(GetRed() * 0.30 + GetGreen() * 0.59 + GetBlue() * 0.11);
 }
Exemplo n.º 18
0
// Given RGB in range 0..255, convert to range 0..1
void CColour::NormalizeRGB(double &r,double &g,double &b)
{
    r = (GetRed()   / 255.0);
    g = (GetGreen() / 255.0);
    b = (GetBlue()  / 255.0);
}
void glArchivItem_Bitmap_Player::Draw(DrawPoint dst, short dst_w, short dst_h, short src_x, short src_y, short src_w, short src_h, const unsigned int color, const unsigned int player_color)
{
    if(GetTexture() == 0)
        return;

    if(src_w == 0)
        src_w = width_;
    if(src_h == 0)
        src_h = height_;
    if(dst_w == 0)
        dst_w = src_w;
    if(dst_h == 0)
        dst_h = src_h;

    Point<GLfloat> texCoords[8], vertices[8];

    int x = -nx_ + dst.x;
    int y = -ny_ + dst.y;

    vertices[0].x = vertices[1].x = GLfloat(x);
    vertices[2].x = vertices[3].x = GLfloat(x + dst_w);

    vertices[0].y = vertices[3].y = GLfloat(y);
    vertices[1].y = vertices[2].y = GLfloat(y + dst_h);

    texCoords[0].x = texCoords[1].x = (GLfloat)(src_x) / (GLfloat)tex_width_ / 2.0f;
    texCoords[2].x = texCoords[3].x = (GLfloat)(src_x + src_w) / (GLfloat)tex_width_ / 2.0f;

    texCoords[0].y = texCoords[3].y = (GLfloat)src_y / tex_height_;
    texCoords[1].y = texCoords[2].y = (GLfloat)(src_y + src_h) / tex_height_;

    std::copy(vertices, vertices + 4, vertices + 4);
    std::copy(texCoords, texCoords + 4, texCoords + 4);

    texCoords[4].x += 0.5;
    texCoords[5].x += 0.5;
    texCoords[6].x += 0.5;
    texCoords[7].x += 0.5;

    struct
    {
        GLbyte r, g, b, a;
    } colors[8];
    colors[0].r = GetRed(color);
    colors[0].g = GetGreen(color);
    colors[0].b = GetBlue(color);
    colors[0].a = GetAlpha(color);
    colors[3] = colors[2] = colors[1] = colors[0];

    colors[4].r = GetRed(player_color);
    colors[4].g = GetGreen(player_color);
    colors[4].b = GetBlue(player_color);
    colors[4].a = GetAlpha(player_color);
    colors[7] = colors[6] = colors[5] = colors[4];

    glEnableClientState(GL_COLOR_ARRAY);
    glVertexPointer(2, GL_FLOAT, 0, vertices);
    glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
    glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
    VIDEODRIVER.BindTexture(GetTexture());
    glDrawArrays(GL_QUADS, 0, 8);
    glDisableClientState(GL_COLOR_ARRAY);
}
Exemplo n.º 20
0
/**
 *  Additional stuff we need to do before drawing (in this case: update the map)
 */
void IngameMinimap::BeforeDrawing()
{
    // Ab welcher Knotenanzahl (Teil der Gesamtknotenanzahl) die Textur komplett neu erstellt werden soll
    static const unsigned MAX_NODES_UPDATE_DENOMINATOR = 2; // (2 = 1/2, 3 = 1/3 usw.)

    if(!nodesToUpdate.empty())
    {
        // Komplette Textur neu erzeugen, weil es zu viele Knoten sind?
        if(nodesToUpdate.size() >= map_width * map_height / MAX_NODES_UPDATE_DENOMINATOR)
        {
            // Ja, alles neu erzeugen
            UpdateAll();
            for(MapPoint p(0, 0); p.y < map_height; p.y++)
                for(p.x = 0; p.x < map_width; p.x++)
                    nodes_updated[GetMMIdx(p)] = false;
        } else
        {
            // Entsprechende Pixel updaten
            for(std::vector<MapPoint>::iterator it = nodesToUpdate.begin(); it != nodesToUpdate.end(); ++it)
            {
                for(unsigned t = 0; t < 2; ++t)
                {
                    unsigned color = CalcPixelColor(*it, t);
                    map.tex_setPixel((it->x * 2 + t + (it->y & 1)) % (map_width * 2), it->y, GetRed(color), GetGreen(color),
                        GetBlue(color), GetAlpha(color));
                }
                nodes_updated[GetMMIdx(*it)] = false;
            }
        }

        this->nodesToUpdate.clear();
    }
}
Exemplo n.º 21
0
	rgb &= 0x00FFFF00;
	rgb |= b;
}

bool Colour::operator == (const Colour& rhs) const
{
	return rgb == rhs.rgb;
}

u16 Colour::ToVDPFormat() const
{
	//u8 rNybble = (u8)(((float)GetRed()	/ (float)0xFF) * (float)0xE);
	//u8 gNybble = (u8)(((float)GetGreen() / (float)0xFF) * (float)0xE);
	//u8 bNybble = (u8)(((float)GetBlue() / (float)0xFF) * (float)0xE);

	u8 rNybble = (u8)(GetRed() >> 5) << 1;
	u8 gNybble = (u8)(GetGreen() >> 5) << 1;
	u8 bNybble = (u8)(GetBlue() >> 5) << 1;

	u16 mdValue = bNybble << 8 | gNybble << 4 | rNybble;
	return mdValue;
}

ion::Colour Colour::ToIonColour() const
{
	return ion::Colour(GetRed(), GetGreen(), GetBlue(), 255);
}

Palette::Palette()
{
	m_colours.resize(coloursPerPalette);
Exemplo n.º 22
0
/**
 *
 *  @author OLiver
 */
unsigned IngameMinimap::CalcPixelColor(const void * param, const MapCoord x, const MapCoord y, const unsigned t)
{
	const GameWorldViewer& gwv = *static_cast<const GameWorldViewer*>(param);

	unsigned color = 0;

	// Beobeachtender Spieler
	unsigned char viewing_player = GameClient::inst().GetPlayerID();

	Visibility visibility = gwv.GetVisibility(x,y);

	if(visibility == VIS_INVISIBLE)
	{
		dos[y*map_width+x] = DO_INVISIBLE;
		// Man sieht nichts --> schwarz
		return 0xFF000000;
	}
	else
	{
		DrawnObject drawn_object = DO_INVALID;

		bool fow = (visibility == VIS_FOW);

		unsigned char owner;
		if(!fow)
			owner = gwv.GetNode(x,y).owner;
		else
			owner = gwv.GetNode(x,y).fow[GameClient::inst().GetPlayerID()].owner;

		// Baum an dieser Stelle?
		if((!fow && gwv.GetNO(x,y)->GetGOT() == GOT_TREE) || (fow && gwv.GetFOWObject(x,y,viewing_player)->GetType() == FOW_TREE))
		{
			color = VaryBrightness(TREE_COLOR,VARY_TREE_COLOR);
			drawn_object = DO_TERRAIN;
			// Ggf. mit Spielerfarbe
			if(owner)
			{
				drawn_object = DO_PLAYER;
				if(territory)
					color = CombineWithPlayerColor(color,owner);
			}
		}
		// Granit an dieser Stelle?
		else if((!fow && gwv.GetNO(x,y)->GetGOT() == GOT_GRANITE) || (fow && gwv.GetFOWObject(x,y,viewing_player)->GetType() == FOW_GRANITE))
		{
			color = VaryBrightness(GRANITE_COLOR,VARY_GRANITE_COLOR);
			drawn_object = DO_TERRAIN;
			// Ggf. mit Spielerfarbe
			if(owner)
			{
				drawn_object = DO_PLAYER;
				if(territory)
					color = CombineWithPlayerColor(color,owner);
			}
		}
		// Ansonsten die jeweilige Terrainfarbe nehmen
		else
		{
			// Ggf. Spielerfarbe mit einberechnen, falls das von einem Spieler ein Territorium ist
			if(owner)
			{
				// Gebäude?
				GO_Type got = gwv.GetNO(x,y)->GetGOT();
				FOW_Type fot = gwv.GetFOWObject(x,y,viewing_player)->GetType();

				if(((!fow && (got == GOT_NOB_USUAL || got == GOT_NOB_MILITARY || 
				   got == GOT_NOB_STOREHOUSE || got == GOT_NOB_USUAL ||
				   got == GOT_NOB_HQ || got == GOT_BUILDINGSITE)) || (fow && (fot == FOW_BUILDING || fot == FOW_BUILDINGSITE))))
				   drawn_object = DO_BUILDING;
				/// Straßen?
				else if(IsRoad(x,y,visibility))
					drawn_object = DO_ROAD;
				// ansonsten normales Territorium?
				else
					drawn_object = DO_PLAYER;

				if(drawn_object == DO_BUILDING && houses)
				   color = BUILDING_COLOR;
				/// Straßen?
				else if(drawn_object == DO_ROAD && roads)
					color = ROAD_COLOR;
				// ansonsten normales Territorium?
				else if(territory)
					// Normales Terrain und Spielerfarbe berechnen
					color = CombineWithPlayerColor(CalcTerrainColor(x,y,t),owner);
				else
					// Normales Terrain berechnen
					color = CalcTerrainColor(x,y,t);
			}
			else
			{
				// Normales Terrain berechnen
				color = CalcTerrainColor(x,y,t);
				drawn_object = DO_TERRAIN;
			}
		}

		// Bei FOW die Farben abdunkeln
		if(fow)
			color = MakeColor(0xFF,GetRed(color)/2,GetGreen(color)/2,GetBlue(color)/2);

		dos[y*map_width+x] = drawn_object;
	}

	return color;
}
Exemplo n.º 23
0
unsigned IngameMinimap::CalcPixelColor(const MapPoint pt, const unsigned t)
{
    unsigned color = 0;

    Visibility visibility = gwv.GetVisibility(pt);

    if(visibility == VIS_INVISIBLE)
    {
        dos[GetMMIdx(pt)] = DO_INVISIBLE;
        // Man sieht nichts --> schwarz
        return 0xFF000000;
    } else
    {
        DrawnObject drawn_object = DO_INVALID;

        const bool fow = (visibility == VIS_FOW);

        unsigned char owner;
        NodalObjectType noType = NOP_NOTHING;
        FOW_Type fot = FOW_NOTHING;
        if(!fow)
        {
            const MapNode& node = gwv.GetNode(pt);
            owner = node.owner;
            if(node.obj)
                noType = node.obj->GetType();
        } else
        {
            const FoWNode& node = gwv.GetYoungestFOWNode(pt);
            owner = node.owner;
            if(node.object)
                fot = node.object->GetType();
        }

       // Baum an dieser Stelle?
        if((!fow && noType == NOP_TREE) || (fow && fot == FOW_TREE)) //-V807
        {
            color = VaryBrightness(TREE_COLOR, VARY_TREE_COLOR);
            drawn_object = DO_TERRAIN;
            // Ggf. mit Spielerfarbe
            if(owner)
            {
                drawn_object = DO_PLAYER;
                if(territory)
                    color = CombineWithPlayerColor(color, owner);
            }
        }
        // Granit an dieser Stelle?
        else if((!fow && noType == NOP_GRANITE) || (fow && fot == FOW_GRANITE))
        {
            color = VaryBrightness(GRANITE_COLOR, VARY_GRANITE_COLOR);
            drawn_object = DO_TERRAIN;
            // Ggf. mit Spielerfarbe
            if(owner)
            {
                drawn_object = DO_PLAYER;
                if(territory)
                    color = CombineWithPlayerColor(color, owner);
            }
        }
        // Ansonsten die jeweilige Terrainfarbe nehmen
        else
        {
            // Ggf. Spielerfarbe mit einberechnen, falls das von einem Spieler ein Territorium ist
            if(owner)
            {
                // Building?
                if(((!fow && (noType == NOP_BUILDING || noType == NOP_BUILDINGSITE)) || (fow && (fot == FOW_BUILDING || fot == FOW_BUILDINGSITE))))
                    drawn_object = DO_BUILDING;
                /// Roads?
                else if(IsRoad(pt, visibility))
                    drawn_object = DO_ROAD;
                // ansonsten normales Territorium?
                else
                    drawn_object = DO_PLAYER;

                if(drawn_object == DO_BUILDING && houses)
                    color = BUILDING_COLOR;
                /// Roads?
                else if(drawn_object == DO_ROAD && roads)
                    color = ROAD_COLOR;
                // ansonsten normales Territorium?
                else if(territory)
                    // Normales Terrain und Spielerfarbe berechnen
                    color = CombineWithPlayerColor(CalcTerrainColor(pt, t), owner);
                else
                    // Normales Terrain berechnen
                    color = CalcTerrainColor(pt, t);
            } else
            {
                // Normales Terrain berechnen
                color = CalcTerrainColor(pt, t);
                drawn_object = DO_TERRAIN;
            }
        }

        // Bei FOW die Farben abdunkeln
        if(fow)
            color = MakeColor(0xFF, GetRed(color) / 2, GetGreen(color) / 2, GetBlue(color) / 2);

        dos[GetMMIdx(pt)] = drawn_object;
    }

    return color;
}
/**
 *  Zeichnet einen Text.
 *
 *  @param[in] x      X-Koordinate
 *  @param[in] y      Y-Koordinate
 *  @param[in] text   Der Text
 *  @param[in] format Format des Textes (verodern)
 *                      @p FontStyle::LEFT    - Text links ( standard )
 *                      @p FontStyle::CENTER  - Text mittig
 *                      @p FontStyle::RIGHT   - Text rechts
 *                      @p FontStyle::TOP     - Text oben ( standard )
 *                      @p FontStyle::VCENTER - Text vertikal zentriert
 *                      @p FontStyle::BOTTOM  - Text unten
 *  @param[in] color  Farbe des Textes
 *  @param[in] length Länge des Textes
 *  @param[in] max    maximale Länge
 *  @param     end    Suffix for displaying a truncation of the text (...)
 */
void glArchivItem_Font::Draw(DrawPoint pos, const std::string& text, FontStyle format, unsigned color, unsigned short length,
                             unsigned short maxWidth, const std::string& end)
{
    if(!fontNoOutline)
        initFont();

    RTTR_Assert(isValidUTF8(text));

    // Breite bestimmen
    if(length == 0)
        length = (unsigned short)text.length();

    unsigned maxNumChars;
    unsigned short textWidth;
    bool drawEnd;
    if(maxWidth == 0xFFFF)
    {
        maxNumChars = length;
        textWidth = getWidth(text, length);
        drawEnd = false;
    } else
    {
        RTTR_Assert(isValidUTF8(end));
        textWidth = getWidth(text, length, maxWidth, &maxNumChars);
        if(!end.empty() && maxNumChars < length)
        {
            unsigned short endWidth = getWidth(end);

            // If "end" does not fit, draw nothing
            if(textWidth < endWidth)
                return;

            // Wieviele Buchstaben gehen in den "Rest" (ohne "end")
            textWidth = getWidth(text, length, textWidth - endWidth, &maxNumChars) + endWidth;
            drawEnd = true;
        } else
            drawEnd = false;
    }

    if(maxNumChars == 0)
        return;
    auto itEnd = text.cbegin();
    std::advance(itEnd, maxNumChars);

    // Vertical alignment (assumes 1 line only!)
    if(format.is(FontStyle::BOTTOM))
        pos.y -= dy;
    else if(format.is(FontStyle::VCENTER))
        pos.y -= dy / 2;
    // Horizontal center must change current line only. Everything else changes the start point
    DrawPoint curPos(pos);
    // Horizontal alignment
    if(format.is(FontStyle::RIGHT))
        curPos.x = pos.x -= textWidth;
    else if(format.is(FontStyle::CENTER))
    {
        unsigned short line_width;
        const auto itNl = std::find(text.cbegin(), itEnd, '\n');
        if(itNl != itEnd)
            line_width = getWidthInternal(text.cbegin(), itNl);
        else
            line_width = textWidth;
        curPos.x = pos.x - line_width / 2;
    }

    texList.texCoords.clear();
    texList.vertices.clear();

    for(auto it = text.begin(); it != itEnd;)
    {
        const uint32_t curChar = utf8::next(it, itEnd);
        if(curChar == '\n')
        {
            if(format.is(FontStyle::CENTER))
            {
                unsigned short line_width;
                const auto itNl = std::find(it, itEnd, '\n');
                line_width = getWidthInternal(it, itNl);
                curPos.x = pos.x - line_width / 2;
            } else
                curPos.x = pos.x;
            curPos.y += dy;
        } else
            DrawChar(curChar, texList, curPos);
    }

    if(drawEnd)
    {
        for(auto it = end.begin(); it != end.end();)
        {
            const uint32_t curChar = utf8::next(it, end.end());
            if(curChar == '\n')
            {
                curPos.x = pos.x;
                curPos.y += dy;
            } else
                DrawChar(curChar, texList, curPos);
        }
    }

    if(texList.vertices.empty())
        return;

    // Get texture first as it might need to be created
    glArchivItem_Bitmap& usedFont = format.is(FontStyle::NO_OUTLINE) ? *fontNoOutline : *fontWithOutline;
    unsigned texture = usedFont.GetTexture();
    if(!texture)
        return;
    const GlPoint texSize(usedFont.GetTexSize());
    RTTR_Assert(texList.texCoords.size() == texList.vertices.size());
    RTTR_Assert(texList.texCoords.size() % 4u == 0);
    // Vectorizable loop
    for(unsigned i = 0; i < texList.texCoords.size(); i += 4)
    {
        for(int j = 0; j < 4; j++)
            texList.texCoords[i + j] /= texSize;
    }

    glVertexPointer(2, GL_FLOAT, 0, &texList.vertices[0]);
    glTexCoordPointer(2, GL_FLOAT, 0, &texList.texCoords[0]);
    VIDEODRIVER.BindTexture(texture);
    glColor4ub(GetRed(color), GetGreen(color), GetBlue(color), GetAlpha(color));
    glDrawArrays(GL_QUADS, 0, texList.vertices.size());
}
Exemplo n.º 25
0
float Color::GetRedF() const
{
  return CHANNEL_TO_FLOAT(GetRed());
}
Exemplo n.º 26
0
Arquivo: sprite.cpp Projeto: kanc/UTAD
void Sprite::Render() const {

	Renderer::Instance().SetBlendMode(this->blendMode);
	Renderer::Instance().SetColor(GetRed(), GetGreen(), GetBlue(), GetAlpha());
	Renderer::Instance().DrawImage(this->image,x,y,(uint32)currentFrame,(double)(image->GetWidth() * scalex), (double)(image->GetHeight() * scaley), WrapValue(angle,360));
}