Skip to content

Commit 544de8e

Browse files
committed
bitmap, text primitives in gpu
1 parent a376366 commit 544de8e

File tree

1 file changed

+42
-63
lines changed

1 file changed

+42
-63
lines changed

Source/Renderer/GraphicalPrimitive.cpp

Lines changed: 42 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include "Matrix.h"
33
#include "FrameMan.h"
44
#include "SceneMan.h"
5+
#include "GLResourceMan.h"
6+
#include "SLTerrain.h"
57

68
#include "GUI.h"
79
#include "AllegroBitmap.h"
@@ -34,23 +36,18 @@ Vector GraphicalPrimitive::WrapCoordinates(Vector targetPos, const Vector& scene
3436
}
3537

3638
void GraphicalPrimitive::DrawTiled(BITMAP* drawScreen, const Vector& targetPos) {
37-
DrawLineV(-targetPos + Vector(-30, -30), -targetPos + Vector(30, 30), {53, 0, 0, 255});
38-
DrawLineV(-targetPos + Vector(30, -30), -targetPos + Vector(-30, 30), {53, 0, 0, 255});
39-
4039
Vector tiledTarget{targetPos};
4140
if (g_SceneMan.SceneWrapsX()) {
4241
tiledTarget.m_X = std::fmodf(targetPos.m_X, g_SceneMan.GetSceneWidth());
4342
}
4443
if (g_SceneMan.SceneWrapsY()) {
4544
tiledTarget.m_Y = std::fmodf(targetPos.m_Y, g_SceneMan.GetSceneHeight());
4645
}
47-
DrawLineV(-tiledTarget + Vector(-30, -30), -tiledTarget + Vector(30, 30), {53, 0, 0, 255});
48-
DrawLineV(-tiledTarget + Vector(30, -30), -tiledTarget + Vector(-30, 30), {53, 0, 0, 255});
4946

5047
float bitmapWidth = g_SceneMan.GetSceneWidth();
5148
float bitmapHeight = g_SceneMan.GetSceneHeight();
52-
int areaToCoverX = drawScreen->w;
53-
int areaToCoverY = drawScreen->h;
49+
float areaToCoverX = drawScreen->w + g_SceneMan.GetTerrain()->GetOffset().m_X;
50+
float areaToCoverY = drawScreen->h + g_SceneMan.GetTerrain()->GetOffset().m_Y;
5451

5552
for (int tiledOffsetX = 0; tiledOffsetX < areaToCoverX;) {
5653
float destX = tiledOffsetX - tiledTarget.m_X;
@@ -213,46 +210,47 @@ void PolygonFillPrimitive::Draw(BITMAP* drawScreen, const Vector& targetPos) {
213210
DrawTriangleStrip(drawPoints.data(), drawPoints.size(), {m_Color, 0, 0, 255});
214211
}
215212

216-
void TextPrimitive::Draw(BITMAP* drawScreen, const Vector& targetPos) {
217-
if (m_Text.empty()) {
213+
214+
void TextPrimitive::CreateTextBitmap() {
215+
if(m_Text.empty()) {
218216
return;
219217
}
220-
221-
AllegroBitmap playerGUIBitmap(drawScreen);
222218
GUIFont* font = m_IsSmall ? g_FrameMan.GetSmallFont() : g_FrameMan.GetLargeFont();
223219
Matrix rotation = Matrix(m_RotAngle);
224220
Vector targetPosAdjustment = Vector();
225221

226-
BITMAP* tempDrawBitmap = nullptr;
227-
if (m_BlendMode > DrawBlendMode::NoBlend || m_RotAngle != 0) {
228-
int textWidth = font->CalculateWidth(m_Text);
229-
int textHeight = font->CalculateHeight(m_Text);
222+
int textWidth = font->CalculateWidth(m_Text);
223+
int textHeight = font->CalculateHeight(m_Text);
224+
225+
drawing_mode(DRAW_MODE_SOLID, nullptr, 0, 0);
226+
227+
m_TextBitmap = create_bitmap_ex(8, textWidth * 2, textHeight);
228+
clear_to_color(m_TextBitmap, ColorKeys::g_MaskColor);
229+
AllegroBitmap tempDrawAllegroBitmap(m_TextBitmap);
230+
font->DrawAligned(&tempDrawAllegroBitmap, textWidth, 0, m_Text, m_Alignment);
230231

231-
tempDrawBitmap = create_bitmap_ex(8, textWidth * 2, textHeight);
232-
clear_to_color(tempDrawBitmap, ColorKeys::g_MaskColor);
233-
AllegroBitmap tempDrawAllegroBitmap(tempDrawBitmap);
234-
font->DrawAligned(&tempDrawAllegroBitmap, textWidth, 0, m_Text, m_Alignment);
232+
m_TargetPosAlignment = Vector(static_cast<float>(textWidth), 0);
233+
}
235234

236-
targetPosAdjustment = Vector(static_cast<float>(textWidth), 0);
235+
void TextPrimitive::Draw(BITMAP* drawScreen, const Vector& targetPos) {
236+
if (!m_TextBitmap) {
237+
return;
237238
}
238239

239-
Vector drawStart = WrapCoordinates(targetPos, m_StartPos) - targetPosAdjustment;
240+
Vector drawStart = WrapCoordinates(targetPos, m_StartPos) - m_TargetPosAlignment;
241+
Rectangle bitmapRect(0.0f, 0.0f, m_TextBitmap->w, m_TextBitmap->h);
242+
Rectangle destRect(
243+
drawStart.m_X,
244+
drawStart.m_Y,
245+
m_TextBitmap->w,
246+
m_TextBitmap->h);
247+
DrawTexturePro(m_TextBitmap, bitmapRect, destRect, {0.0f, 0.0f}, m_RotAngle, {255, 255, 255, 255});
248+
}
240249

241-
if (m_BlendMode > DrawBlendMode::NoBlend) {
242-
if (m_RotAngle != 0) {
243-
rotate_sprite_trans(drawScreen, tempDrawBitmap, drawStart.GetFloorIntX(), drawStart.GetFloorIntY(), ftofix(rotation.GetAllegroAngle()));
244-
} else {
245-
draw_trans_sprite(drawScreen, tempDrawBitmap, drawStart.GetFloorIntX(), drawStart.GetFloorIntY());
246-
}
247-
} else {
248-
if (m_RotAngle != 0) {
249-
rotate_sprite(drawScreen, tempDrawBitmap, drawStart.GetFloorIntX(), drawStart.GetFloorIntY(), ftofix(rotation.GetAllegroAngle()));
250-
} else {
251-
font->DrawAligned(&playerGUIBitmap, drawStart.GetFloorIntX(), drawStart.GetFloorIntY(), m_Text, m_Alignment);
252-
}
253-
}
254-
if (tempDrawBitmap) {
255-
destroy_bitmap(tempDrawBitmap);
250+
TextPrimitive::~TextPrimitive() {
251+
if (m_TextBitmap) {
252+
g_GLResourceMan.DestroyBitmapInfo(m_TextBitmap);
253+
destroy_bitmap(m_TextBitmap);
256254
}
257255
}
258256

@@ -261,33 +259,14 @@ void BitmapPrimitive::Draw(BITMAP* drawScreen, const Vector& targetPos) {
261259
return;
262260
}
263261

264-
BITMAP* bitmapToDraw = create_bitmap_ex(8, m_Bitmap->w, m_Bitmap->h);
265-
clear_to_color(bitmapToDraw, ColorKeys::g_MaskColor);
266-
draw_sprite(bitmapToDraw, m_Bitmap, 0, 0);
267-
268-
if (m_HFlipped || m_VFlipped) {
269-
BITMAP* flipBitmap = create_bitmap_ex(8, bitmapToDraw->w, bitmapToDraw->h);
270-
clear_to_color(flipBitmap, ColorKeys::g_MaskColor);
271-
272-
if (m_HFlipped && !m_VFlipped) {
273-
draw_sprite_h_flip(flipBitmap, bitmapToDraw, 0, 0);
274-
} else if (!m_HFlipped && m_VFlipped) {
275-
draw_sprite_v_flip(flipBitmap, bitmapToDraw, 0, 0);
276-
} else if (m_HFlipped && m_VFlipped) {
277-
draw_sprite_vh_flip(flipBitmap, bitmapToDraw, 0, 0);
278-
}
279-
280-
blit(flipBitmap, bitmapToDraw, 0, 0, 0, 0, bitmapToDraw->w, bitmapToDraw->h);
281-
destroy_bitmap(flipBitmap);
282-
}
262+
Vector drawStart = WrapCoordinates(targetPos, m_StartPos);
283263

284-
Matrix rotation = Matrix(m_RotAngle);
264+
Rectangle flippedRect(
265+
drawStart.m_X - m_Bitmap->w / 2,
266+
drawStart.m_Y - m_Bitmap->h / 2,
267+
m_VFlipped ? -m_Bitmap->w : m_Bitmap->w,
268+
m_HFlipped ? -m_Bitmap->h : m_Bitmap->h
269+
);
285270

286-
Vector drawStart = WrapCoordinates(targetPos, m_StartPos);
287-
if (m_BlendMode > DrawBlendMode::NoBlend) {
288-
pivot_scaled_sprite_trans(drawScreen, bitmapToDraw, drawStart.GetFloorIntX(), drawStart.GetFloorIntY(), bitmapToDraw->w / 2, bitmapToDraw->h / 2, ftofix(rotation.GetAllegroAngle()), ftofix(1.0));
289-
} else {
290-
pivot_scaled_sprite(drawScreen, bitmapToDraw, drawStart.GetFloorIntX(), drawStart.GetFloorIntY(), bitmapToDraw->w / 2, bitmapToDraw->h / 2, ftofix(rotation.GetAllegroAngle()), ftofix(1.0));
291-
}
292-
destroy_bitmap(bitmapToDraw);
271+
DrawTexturePro(m_Bitmap, Rectangle(0.0f, 0.0f, m_Bitmap->w, m_Bitmap->h), flippedRect, {0.0f, 0.0f}, m_RotAngle, {255, 255, 255, 255});
293272
}

0 commit comments

Comments
 (0)