Skip to content

Commit

Permalink
First working text rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
nieznanysprawiciel committed Nov 11, 2024
1 parent f4365bf commit b7b7927
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions swGUI/Core/Media/Geometry/Layouts/VertexShape2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ template <> InputLayoutDescriptor CreateLayoutDescriptor< VertexText2D >()
InputLayoutDescriptor desc;
desc.AddEntry( AttributeSemantic::Position, ResourceFormat::RESOURCE_FORMAT_R32G32_FLOAT,
offsetof( VertexText2D, Position ) );
desc.AddEntry( AttributeSemantic::Texcoord, ResourceFormat::RESOURCE_FORMAT_R32G32_FLOAT,
offsetof( VertexText2D, AtlasCoords ) );
desc.AddEntry( AttributeSemantic::Texcoord, ResourceFormat::RESOURCE_FORMAT_R32G32_FLOAT,
offsetof( VertexText2D, UV ) );
desc.AddEntry( AttributeSemantic::Texcoord, ResourceFormat::RESOURCE_FORMAT_R32G32_FLOAT,
offsetof( VertexText2D, AtlasCoords ) );

return std::move( desc );
}
Expand Down
6 changes: 3 additions & 3 deletions swGUI/Core/Shaders/hlsl/Templates/Opacity.psh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
struct OutputVS
{
linear float4 Pos : SV_Position;
noperspective float2 Tex : TEXCOORD;
noperspective float2 Mask : TEXCOORD;
noperspective float2 Tex : TEXCOORD0;
noperspective float2 Mask : TEXCOORD1;
};

// ================================ //
Expand Down Expand Up @@ -53,6 +53,6 @@ float4 main ( OutputVS input ) : SV_Target
{
float4 color = BrushFunction( input.Pos, input.Tex );
float4 opacity = opacityMask.Sample(OpacitySampler, input.Mask);
color.z = color.z * opacity.z;
color.a = color.a * opacity.a;
return color;
}
8 changes: 4 additions & 4 deletions swGUI/Core/Shaders/hlsl/Templates/Opacity.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
struct InputVS
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD;
float2 Mask : TEXCOORD;
float2 Tex : TEXCOORD0;
float2 Mask : TEXCOORD1;
};

// ================================ //
//
struct OutputVS
{
linear float4 Pos : SV_Position;
noperspective float2 Tex : TEXCOORD;
noperspective float2 Mask: TEXCOORD;
noperspective float2 Tex : TEXCOORD0;
noperspective float2 Mask: TEXCOORD1;
};

// ================================ //
Expand Down
2 changes: 1 addition & 1 deletion swGUI/Prototypes/PrototyperGUI/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void AddControls ( HostWindow* host )
AddRectangle( host, gradientBrush, stroke, 120, 768, 2, Position( 750, 0 ) );

auto background = std::make_shared< SolidColorBrush >( Color( 0.5, 0.5, 0.5, 1.0 ) );
auto pen = std::make_shared< SolidColorBrush >( Color( 0.0, 1.0, 0.0, 1.0 ) );
auto pen = std::make_shared< SolidColorBrush >( Color( 1.0, 1.0, 1.0, 1.0 ) );
AddText( host, background, pen, 200, 200, Position( 50, 600 ), L"Hello World" );
}

Expand Down
7 changes: 4 additions & 3 deletions swGraphicAPI/Assets/TextAsset/Text.inl
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ inline void TextGeometryGenerator< VertexType, IndexType, TextAcc >::Gen
}

auto& glyph = m_layout.Glyphs.at( wch );

PutLetterVertex( vertex, glyph, translate, idx );
PutLetterUV( vertex, glyph, translate, idx );
vertexIdx = GenerateBackground ? vertexIdx - 4 : vertexIdx;

PutLetterVertex( vertex, glyph, translate, vertexIdx );
PutLetterUV( vertex, glyph, translate, vertexIdx );
}

// ================================ //
Expand Down

0 comments on commit b7b7927

Please sign in to comment.