Skip to content

Commit

Permalink
feat: pl_draw.h v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffstadt committed Oct 22, 2024
1 parent e713c3e commit ed47700
Show file tree
Hide file tree
Showing 17 changed files with 1,378 additions and 1,198 deletions.
46 changes: 22 additions & 24 deletions examples/example_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
// adding another font
plFontConfig tFontConfig0 = {
.bSdf = false,
.fFontSize = 18.0f,
.fSize = 18.0f,
.uHOverSampling = 1,
.uVOverSampling = 1,
.uRangeCount = 1,
Expand All @@ -221,7 +221,7 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
// adding previous font but as a signed distance field
plFontConfig tFontConfig1 = {
.bSdf = true, // only works with ttf
.fFontSize = 18.0f,
.fSize = 18.0f,
.uHOverSampling = 1,
.uVOverSampling = 1,
.ucOnEdgeValue = 180,
Expand Down Expand Up @@ -305,51 +305,49 @@ pl_app_update(plAppData* ptAppData)

// lines
float fXCursor = 0.0f;
gptDraw->add_line(ptAppData->ptFGLayer, (plVec2){fXCursor, 0.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 1.0f);
gptDraw->add_line(ptAppData->ptFGLayer, (plVec2){fXCursor, 0.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plDrawLineOptions){.fThickness = 1.0f, .uColor = PL_COLOR_32_MAGENTA});
fXCursor += 100.0f;
gptDraw->add_triangle(ptAppData->ptFGLayer, (plVec2){fXCursor + 50.0f, 0.0f}, (plVec2){fXCursor, 100.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 1.0f);
gptDraw->add_triangle(ptAppData->ptFGLayer, (plVec2){fXCursor + 50.0f, 0.0f}, (plVec2){fXCursor, 100.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plDrawLineOptions){.fThickness = 1.0f, .uColor = PL_COLOR_32_MAGENTA});
fXCursor += 100.0f;
gptDraw->add_circle(ptAppData->ptFGLayer, (plVec2){fXCursor + 50.0f, 50.0f}, 50.0f, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 0, 1.0f);
gptDraw->add_circle(ptAppData->ptFGLayer, (plVec2){fXCursor + 50.0f, 50.0f}, 50.0f, 0, (plDrawLineOptions){.fThickness = 1.0f, .uColor = PL_COLOR_32_MAGENTA});
fXCursor += 100.0f;
gptDraw->add_rect(ptAppData->ptFGLayer, (plVec2){fXCursor, 5.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 1.0f, 0, 0);
gptDraw->add_rect_rounded(ptAppData->ptFGLayer, (plVec2){fXCursor, 5.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, 0, 0, 0, (plDrawLineOptions){.fThickness = 1.0f, .uColor = PL_COLOR_32_MAGENTA});
fXCursor += 100.0f;
gptDraw->add_rect(ptAppData->ptFGLayer, (plVec2){fXCursor, 5.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 2.0f, 25.0f, 0);
gptDraw->add_rect_rounded(ptAppData->ptFGLayer, (plVec2){fXCursor, 5.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, 25.0f, 0, 0, (plDrawLineOptions){.fThickness = 1.0f, .uColor = PL_COLOR_32_MAGENTA});
fXCursor += 100.0f;
gptDraw->add_rect_ex(ptAppData->ptFGLayer, (plVec2){fXCursor, 5.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 2.0f, 25.0f, 0, PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_LEFT);
gptDraw->add_rect_rounded(ptAppData->ptFGLayer, (plVec2){fXCursor, 5.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, 25.0f, 0, PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_LEFT, (plDrawLineOptions){.fThickness = 1.0f, .uColor = PL_COLOR_32_MAGENTA});
fXCursor += 100.0f;
gptDraw->add_quad(ptAppData->ptFGLayer, (plVec2){fXCursor + 5.0f, 5.0f}, (plVec2){fXCursor + 5.0f, 100.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plVec2){fXCursor + 100.0f, 5.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 1.0f);
gptDraw->add_quad(ptAppData->ptFGLayer, (plVec2){fXCursor + 5.0f, 5.0f}, (plVec2){fXCursor + 5.0f, 100.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plVec2){fXCursor + 100.0f, 5.0f}, (plDrawLineOptions){.fThickness = 1.0f, .uColor = PL_COLOR_32_MAGENTA});
fXCursor += 100.0f;
gptDraw->add_bezier_quad(ptAppData->ptFGLayer, (plVec2){fXCursor, 0.0f}, (plVec2){fXCursor + 100.0f, 0.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 1.0f, 0);
gptDraw->add_bezier_quad(ptAppData->ptFGLayer, (plVec2){fXCursor, 0.0f}, (plVec2){fXCursor + 100.0f, 0.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, 0, (plDrawLineOptions){.fThickness = 1.0f, .uColor = PL_COLOR_32_MAGENTA});
fXCursor += 100.0f;
gptDraw->add_bezier_cubic(ptAppData->ptFGLayer, (plVec2){fXCursor, 0.0f}, (plVec2){fXCursor + 100.0f, 0.0f}, (plVec2){fXCursor, 100.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 1.0f, 0);
gptDraw->add_bezier_cubic(ptAppData->ptFGLayer, (plVec2){fXCursor, 0.0f}, (plVec2){fXCursor + 100.0f, 0.0f}, (plVec2){fXCursor, 100.0f}, (plVec2){fXCursor + 100.0f, 100.0f}, 0, (plDrawLineOptions){.fThickness = 1.0f, .uColor = PL_COLOR_32_MAGENTA});
fXCursor += 100.0f;

// solids
fXCursor = 100.0f;
gptDraw->add_triangle_filled(ptAppData->ptFGLayer, (plVec2){fXCursor + 50.0f, 100.0f}, (plVec2){fXCursor, 200.0f}, (plVec2){fXCursor + 100.0f, 200.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f});
gptDraw->add_triangle_filled(ptAppData->ptFGLayer, (plVec2){fXCursor + 50.0f, 100.0f}, (plVec2){fXCursor, 200.0f}, (plVec2){fXCursor + 100.0f, 200.0f}, (plDrawSolidOptions){.uColor = PL_COLOR_32_MAGENTA});
fXCursor += 100.0f;
gptDraw->add_circle_filled(ptAppData->ptFGLayer, (plVec2){fXCursor + 50.0f, 150.0f}, 50.0f, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 0);
gptDraw->add_circle_filled(ptAppData->ptFGLayer, (plVec2){fXCursor + 50.0f, 150.0f}, 50.0f, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_MAGENTA});
fXCursor += 100.0f;
gptDraw->add_rect_filled(ptAppData->ptFGLayer, (plVec2){fXCursor, 105.0f}, (plVec2){fXCursor + 100.0f, 200.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 0, 0);
gptDraw->add_rect_rounded_filled(ptAppData->ptFGLayer, (plVec2){fXCursor, 105.0f}, (plVec2){fXCursor + 100.0f, 200.0f}, 0, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_MAGENTA});
fXCursor += 100.0f;
gptDraw->add_rect_filled(ptAppData->ptFGLayer, (plVec2){fXCursor, 105.0f}, (plVec2){fXCursor + 100.0f, 200.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 25.0f, 0);
gptDraw->add_rect_rounded_filled(ptAppData->ptFGLayer, (plVec2){fXCursor, 105.0f}, (plVec2){fXCursor + 100.0f, 200.0f}, 25.0f, 0, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_MAGENTA});
fXCursor += 100.0f;
gptDraw->add_rect_filled_ex(ptAppData->ptFGLayer, (plVec2){fXCursor, 105.0f}, (plVec2){fXCursor + 100.0f, 200.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 25.0f, 0, PL_DRAW_RECT_FLAG_ROUND_CORNERS_TOP_LEFT);
fXCursor += 100.0f;
gptDraw->add_quad_filled(ptAppData->ptFGLayer, (plVec2){fXCursor + 5.0f, 105.0f}, (plVec2){fXCursor + 5.0f, 200.0f}, (plVec2){fXCursor + 100.0f, 200.0f}, (plVec2){fXCursor + 100.0f, 105.0f}, (plVec4){1.0f, 0.0f, 1.0f, 1.0f});
gptDraw->add_quad_filled(ptAppData->ptFGLayer, (plVec2){fXCursor + 5.0f, 105.0f}, (plVec2){fXCursor + 5.0f, 200.0f}, (plVec2){fXCursor + 100.0f, 200.0f}, (plVec2){fXCursor + 100.0f, 105.0f}, (plDrawSolidOptions){.uColor = PL_COLOR_32_MAGENTA});
// gptDraw->add_circle_filled(ptAppData->ptBGLayer, (plVec2){100.0f, 100.0f}, 25.0f, (plVec4){1.0f, 0.0f, 1.0f, 1.0f}, 24);

// default text
gptDraw->add_text(ptAppData->ptFGLayer, ptAppData->ptDefaultFont, 13.0f, (plVec2){25.0f, 300.0f}, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}, "Proggy @ 13 (loaded at 13)", 0.0f);
gptDraw->add_text(ptAppData->ptFGLayer, ptAppData->ptDefaultFont, 45.0f, (plVec2){25.0f, 315.0f}, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}, "Proggy @ 45 (loaded at 13)", 0.0f);
gptDraw->add_text(ptAppData->ptFGLayer, (plVec2){25.0f, 300.0f}, "Proggy @ 13 (loaded at 13)", (plDrawTextOptions){.ptFont = ptAppData->ptDefaultFont, .uColor = PL_COLOR_32_WHITE});
gptDraw->add_text(ptAppData->ptFGLayer, (plVec2){25.0f, 315.0f}, "Proggy @ 45 (loaded at 13)", (plDrawTextOptions){.ptFont = ptAppData->ptDefaultFont, .uColor = PL_COLOR_32_WHITE, .fSize = 45.0f});

// bitmap text
gptDraw->add_text(ptAppData->ptFGLayer, ptAppData->ptCousineBitmapFont, 18.0f, (plVec2){25.0f, 400.0f}, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}, "Cousine @ 18, bitmap (loaded at 18)", 0.0f);
gptDraw->add_text(ptAppData->ptFGLayer, ptAppData->ptCousineBitmapFont, 100.0f, (plVec2){25.0f, 420.0f}, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}, "Cousine @ 100, bitmap (loaded at 18)", 0.0f);
gptDraw->add_text(ptAppData->ptFGLayer, (plVec2){25.0f, 400.0f}, "Cousine @ 18, bitmap (loaded at 18)", (plDrawTextOptions){.ptFont = ptAppData->ptCousineBitmapFont, .uColor = PL_COLOR_32_WHITE});
gptDraw->add_text(ptAppData->ptFGLayer, (plVec2){25.0f, 420.0f}, "Cousine @ 100, bitmap (loaded at 18)", (plDrawTextOptions){.ptFont = ptAppData->ptCousineBitmapFont, .uColor = PL_COLOR_32_WHITE, .fSize = 100.0f});

// sdf text
gptDraw->add_text(ptAppData->ptFGLayer, ptAppData->ptCousineSDFFont, 18.0f, (plVec2){25.0f, 520.0f}, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}, "Cousine @ 18, sdf (loaded at 18)", 0.0f);
gptDraw->add_text(ptAppData->ptFGLayer, ptAppData->ptCousineSDFFont, 100.0f, (plVec2){25.0f, 540.0f}, (plVec4){1.0f, 1.0f, 1.0f, 1.0f}, "Cousine @ 100, sdf (loaded at 18)", 0.0f);
gptDraw->add_text(ptAppData->ptFGLayer, (plVec2){25.0f, 520.0f}, "Cousine @ 18, sdf (loaded at 18)", (plDrawTextOptions){.ptFont = ptAppData->ptCousineSDFFont, .uColor = PL_COLOR_32_WHITE, .fSize = 100.0f});
gptDraw->add_text(ptAppData->ptFGLayer, (plVec2){25.0f, 540.0f}, "Cousine @ 100, sdf (loaded at 18)", (plDrawTextOptions){.ptFont = ptAppData->ptCousineSDFFont, .uColor = PL_COLOR_32_WHITE, .fSize = 100.0f});

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~drawing prep~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
6 changes: 3 additions & 3 deletions examples/example_3.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Index of this file:

// extensions
#include "pl_shader_ext.h"
#include "pl_draw_ext.h" // not yet stable
#include "pl_draw_ext.h"
#include "pl_ui_ext.h" // not yet stable
#include "pl_graphics_ext.h" // not yet stable
#include "pl_draw_backend_ext.h" // not yet stable
Expand Down Expand Up @@ -275,7 +275,7 @@ pl_app_update(plAppData* ptAppData)

const float pfRatios[] = {1.0f};
gptUi->layout_row(PL_UI_LAYOUT_ROW_TYPE_DYNAMIC, 0.0f, 1, pfRatios);
if(gptUi->collapsing_header("Information"))
if(gptUi->begin_collapsing_header("Information"))
{

gptUi->text("Pilot Light %s", PILOT_LIGHT_VERSION);
Expand All @@ -289,7 +289,7 @@ pl_app_update(plAppData* ptAppData)

gptUi->end_collapsing_header();
}
if(gptUi->collapsing_header("User Interface"))
if(gptUi->begin_collapsing_header("User Interface"))
{
gptUi->checkbox("UI Debug", &ptAppData->bShowUiDebug);
gptUi->checkbox("UI Demo", &ptAppData->bShowUiDemo);
Expand Down
19 changes: 9 additions & 10 deletions examples/example_8.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Index of this file:

// extensions
#include "pl_graphics_ext.h" // not yet stable
#include "pl_draw_ext.h" // not yet stable
#include "pl_draw_ext.h"
#include "pl_shader_ext.h"
#include "pl_draw_backend_ext.h" // not yet stable

Expand Down Expand Up @@ -483,32 +483,31 @@ pl_app_update(plAppData* ptAppData)

// 3d drawing API usage
const plMat4 tOrigin = pl_identity_mat4();
gptDraw->add_3d_transform(ptAppData->pt3dDrawlist, &tOrigin, 10.0f, 0.2f);
gptDraw->add_3d_transform(ptAppData->pt3dDrawlist, &tOrigin, 10.0f, (plDrawLineOptions){.fThickness = 0.2f});

plDrawCylinderDesc tCylinderDesc = {
.fRadius = 1.5f,
.tBasePos = {-2.5f, 1.0f, 0.0f},
.tTipPos = {-2.5f, 4.0f, 0.0f},
.tColor = (plVec4){1.0f, 1.0f, 0.0f, 0.75f},
.uSegments = 12
};
gptDraw->add_3d_cylinder_filled_ex(ptAppData->pt3dDrawlist, &tCylinderDesc);
gptDraw->add_3d_cylinder_filled(ptAppData->pt3dDrawlist, tCylinderDesc, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGBA(1.0f, 1.0f, 0.0f, 0.75f)});

gptDraw->add_3d_triangle_filled(ptAppData->pt3dDrawlist,
(plVec3){1.0f, 1.0f, 0.0f},
(plVec3){4.0f, 1.0f, 0.0f},
(plVec3){1.0f, 4.0f, 0.0f},
(plVec4){1.0f, 1.0f, 0.0f, 0.75f});
(plDrawSolidOptions){.uColor = PL_COLOR_32_YELLOW});

gptDraw->add_3d_sphere_filled(ptAppData->pt3dDrawlist,
(plVec3){5.5f, 2.5f, 0.0f}, 1.5f, (plVec4){1.0f, 1.0f, 0.0f, 0.75f});
(plDrawSphereDesc){.fRadius = 1.0F, .tCenter = {5.5f, 2.5f, 0.0f}}, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGBA(1.0f, 1.0f, 0.0f, 0.75f)});

gptDraw->add_3d_circle_xz_filled(ptAppData->pt3dDrawlist,
(plVec3){8.5f, 2.5f, 0.0f}, 1.5f, (plVec4){1.0f, 1.0f, 0.0f, 0.75f}, 0);
(plVec3){8.5f, 2.5f, 0.0f}, 1.5f, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGBA(1.0f, 1.0f, 0.0f, 0.75f)});

gptDraw->add_3d_band_xz_filled(ptAppData->pt3dDrawlist, (plVec3){11.5f, 2.5f, 0.0f}, 0.75f, 1.5f, (plVec4){1.0f, 1.0f, 0.0f, 0.75f}, 0);
gptDraw->add_3d_band_xy_filled(ptAppData->pt3dDrawlist, (plVec3){11.5f, 2.5f, 0.0f}, 0.75f, 1.5f, (plVec4){1.0f, 0.0f, 0.0f, 0.75f}, 0);
gptDraw->add_3d_band_yz_filled(ptAppData->pt3dDrawlist, (plVec3){11.5f, 2.5f, 0.0f}, 0.75f, 1.5f, (plVec4){1.0f, 0.0f, 1.0f, 0.75f}, 0);
gptDraw->add_3d_band_xz_filled(ptAppData->pt3dDrawlist, (plVec3){11.5f, 2.5f, 0.0f}, 0.75f, 1.5f, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGBA(1.0f, 1.0f, 0.0f, 0.75f)});
gptDraw->add_3d_band_xy_filled(ptAppData->pt3dDrawlist, (plVec3){11.5f, 2.5f, 0.0f}, 0.75f, 1.5f, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGBA(1.0f, 0.0f, 0.0f, 0.75f)});
gptDraw->add_3d_band_yz_filled(ptAppData->pt3dDrawlist, (plVec3){11.5f, 2.5f, 0.0f}, 0.75f, 1.5f, 0, (plDrawSolidOptions){.uColor = PL_COLOR_32_RGBA(1.0f, 0.0f, 1.0f, 0.75f)});

// gptDraw->add_3d_triangle_filled(ptAppData->pt3dDrawlist,
// (plVec3){1.0f, 1.0f, 3.0f},
Expand Down
Loading

0 comments on commit ed47700

Please sign in to comment.