|
|
@@ -362,9 +362,10 @@ void CSDL_Ext::update(SDL_Surface * what)
|
|
|
logGlobal->error("%s SDL_UpdateTexture %s", __FUNCTION__, SDL_GetError());
|
|
|
}
|
|
|
|
|
|
-uint8_t lerp(uint8_t a, uint8_t b, float f)
|
|
|
+template<typename Int>
|
|
|
+Int lerp(Int a, Int b, float f)
|
|
|
{
|
|
|
- return a + std::round((b-a)*f);
|
|
|
+ return a + std::round((b - a) * f);
|
|
|
}
|
|
|
|
|
|
static void drawLineX(SDL_Surface * sur, int x1, int y1, int x2, int y2, const SDL_Color & color1, const SDL_Color & color2)
|
|
|
@@ -372,7 +373,7 @@ static void drawLineX(SDL_Surface * sur, int x1, int y1, int x2, int y2, const S
|
|
|
for(int x = x1; x <= x2; x++)
|
|
|
{
|
|
|
float f = float(x - x1) / float(x2 - x1);
|
|
|
- int y = y1 + std::round((y2-y1)*f);
|
|
|
+ int y = lerp(y1, y2, f);
|
|
|
|
|
|
uint8_t r = lerp(color1.r, color2.r, f);
|
|
|
uint8_t g = lerp(color1.g, color2.g, f);
|
|
|
@@ -389,7 +390,7 @@ static void drawLineY(SDL_Surface * sur, int x1, int y1, int x2, int y2, const S
|
|
|
for(int y = y1; y <= y2; y++)
|
|
|
{
|
|
|
float f = float(y - y1) / float(y2 - y1);
|
|
|
- int x = x1 + std::round((x2-x1)*f);
|
|
|
+ int x = lerp(x1, x2, f);
|
|
|
|
|
|
uint8_t r = lerp(color1.r, color2.r, f);
|
|
|
uint8_t g = lerp(color1.g, color2.g, f);
|
|
|
@@ -418,14 +419,14 @@ void CSDL_Ext::drawLine(SDL_Surface * sur, int x1, int y1, int x2, int y2, const
|
|
|
if ( x1 < x2)
|
|
|
drawLineX(sur, x1,y1,x2,y2, color1, color2);
|
|
|
else
|
|
|
- drawLineX(sur, x2,y2,x1,y1, color1, color2);
|
|
|
+ drawLineX(sur, x2,y2,x1,y1, color2, color1);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if ( y1 < y2)
|
|
|
drawLineY(sur, x1,y1,x2,y2, color1, color2);
|
|
|
else
|
|
|
- drawLineY(sur, x2,y2,x1,y1, color1, color2);
|
|
|
+ drawLineY(sur, x2,y2,x1,y1, color2, color1);
|
|
|
}
|
|
|
}
|
|
|
|