font_creator project for font loading;

init font_main + "stbtt_InitFont";
Lexend-Regular.ttf as normal font;


git-svn-id: svn://ammerhai.com/home/mike/pokemon_repo@17 24008968-59e6-ed4c-a10b-0b2c954b24ab
This commit is contained in:
mikeb 2021-07-03 17:31:05 +00:00
parent ce923a77fb
commit 1f91eb9cf1
16 changed files with 5457 additions and 6 deletions

Binary file not shown.

View File

@ -0,0 +1,24 @@
struct PixelShaderInput {
float4 pos : SV_POSITION;
float4 uvst : COORDINATES;
uint tile_type : TILE_TYPE;
};
struct PixelShaderOutput {
float4 color : SV_TARGET;
};
Texture2DArray<float4> tex1 : register(t0);
SamplerState texture_sampler : register(s0);
PixelShaderOutput main(PixelShaderInput input) {
PixelShaderOutput output;
#if 1
output.color = tex1.Sample(texture_sampler, float3(input.uvst.xy, input.tile_type));
#else
output.color = float4(1, 0, 1, 1);
#endif
return output;
}

View File

@ -0,0 +1,56 @@
struct VertexShaderInput {
// Per Vertex
float4 pos : VERTEX_POSITION;
float2 uv : UV_VERTEX;
uint vid : SV_VertexID;
// Per Instance
float4 pos_size : INSTANCE_POSITION_SIZE;
uint tile_type : TILE_TYPE;
float4 uv0uv1 : UV_INSTANCE;
};
struct VertexShaderOutput {
float4 pos : SV_POSITION;
float4 uv0uv1 : COORDINATES;
uint tile_type : TILE_TYPE;
};
VertexShaderOutput main(VertexShaderInput input) {
VertexShaderOutput output;
float2 rect_pos = input.pos_size.xy;
float2 rect_size = input.pos_size.zw;
float3x3 coord_sys = {
2, 0, -1,
0, -2, 1,
0, 0, 1
};
input.pos_size.xy = mul(coord_sys, float3(input.pos_size.xy, 1)).xy;
float3x3 pos = {
1, 0, input.pos_size.x,
0, 1, input.pos_size.y,
0, 0, 1
};
float3x3 size = {
rect_size.x, 0, 0,
0, rect_size.y, 0,
0, 0, 1
};
output.pos.xy = mul(pos, mul(size, input.pos.xyz)).xy;
//output.pos.xy = mul(pos, input.pos.xyz).xy;
output.pos.zw = float2(0, 1);
output.uv0uv1.zw = float2(0, 0);
output.uv0uv1.xy = lerp(input.uv0uv1.xy, input.uv0uv1.zw, input.uv.xy);
output.tile_type = input.tile_type;
return output;
}

BIN
bin/font_creator.exe Normal file

Binary file not shown.

BIN
bin/font_creator.pdb Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

158
font_creator.vcxproj Normal file
View File

@ -0,0 +1,158 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{47fdfb7b-4bd1-4255-9740-81e9e21495d1}</ProjectGuid>
<RootNamespace>fontcreator</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>ClangCL</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>ClangCL</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)bin\</OutDir>
<IntDir>$(SolutionDir)vs_trash\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)bin\</OutDir>
<IntDir>$(SolutionDir)vs_trash\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\font_main.cpp" />
<ClCompile Include="src\load_entire_file.cpp" />
<ClCompile Include="src\log.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\stb_truetype.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\font_main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\log.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\load_entire_file.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\stb_truetype.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

14
font_creator.vcxproj.user Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerWorkingDirectory>$(ProjectDir)bin\</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerWorkingDirectory>$(ProjectDir)bin\</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

View File

@ -5,16 +5,32 @@ VisualStudioVersion = 16.0.31019.35
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pokemon", "pokemon.vcxproj", "{07F7D6C3-29D6-4D4C-BA7D-0D867747FB24}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "font_creator", "font_creator.vcxproj", "{47FDFB7B-4BD1-4255-9740-81E9E21495D1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{07F7D6C3-29D6-4D4C-BA7D-0D867747FB24}.Debug|x64.ActiveCfg = Debug|x64
{07F7D6C3-29D6-4D4C-BA7D-0D867747FB24}.Debug|x64.Build.0 = Debug|x64
{07F7D6C3-29D6-4D4C-BA7D-0D867747FB24}.Debug|x86.ActiveCfg = Debug|Win32
{07F7D6C3-29D6-4D4C-BA7D-0D867747FB24}.Debug|x86.Build.0 = Debug|Win32
{07F7D6C3-29D6-4D4C-BA7D-0D867747FB24}.Release|x64.ActiveCfg = Release|x64
{07F7D6C3-29D6-4D4C-BA7D-0D867747FB24}.Release|x64.Build.0 = Release|x64
{07F7D6C3-29D6-4D4C-BA7D-0D867747FB24}.Release|x86.ActiveCfg = Release|Win32
{07F7D6C3-29D6-4D4C-BA7D-0D867747FB24}.Release|x86.Build.0 = Release|Win32
{47FDFB7B-4BD1-4255-9740-81E9E21495D1}.Debug|x64.ActiveCfg = Debug|x64
{47FDFB7B-4BD1-4255-9740-81E9E21495D1}.Debug|x64.Build.0 = Debug|x64
{47FDFB7B-4BD1-4255-9740-81E9E21495D1}.Debug|x86.ActiveCfg = Debug|Win32
{47FDFB7B-4BD1-4255-9740-81E9E21495D1}.Debug|x86.Build.0 = Debug|Win32
{47FDFB7B-4BD1-4255-9740-81E9E21495D1}.Release|x64.ActiveCfg = Release|x64
{47FDFB7B-4BD1-4255-9740-81E9E21495D1}.Release|x64.Build.0 = Release|x64
{47FDFB7B-4BD1-4255-9740-81E9E21495D1}.Release|x86.ActiveCfg = Release|Win32
{47FDFB7B-4BD1-4255-9740-81E9E21495D1}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -74,8 +74,8 @@
<IntDir>$(SolutionDir)vs_trash\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)bin</OutDir>
<IntDir>$(SolutionDir)vs_trash</IntDir>
<OutDir>$(SolutionDir)bin\</OutDir>
<IntDir>$(SolutionDir)vs_trash\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
@ -112,6 +112,11 @@
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\create_window.cpp" />
<ClCompile Include="src\load_entire_file.cpp" />

View File

@ -4,7 +4,11 @@
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerWorkingDirectory>$(ProjectDir)bin</LocalDebuggerWorkingDirectory>
<LocalDebuggerWorkingDirectory>$(ProjectDir)bin\</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerWorkingDirectory>$(ProjectDir)bin\</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

22
src/font_main.cpp Normal file
View File

@ -0,0 +1,22 @@
#define STB_TRUETYPE_IMPLEMENTATION
#include "stb_truetype.h"
#include "load_entire_file.h"
#include "log.h"
int main() {
stbtt_fontinfo font_info;
String font_file = load_entire_file("../assets/fonts/Lexend-Regular.ttf");
if (!font_file.length) {
log_error("Loading font file has failed.");
return 1;
}
if (!stbtt_InitFont(&font_info, (unsigned char*)font_file.data, 0)) {
log_error("Init Font has failed.");
return 1;
}
return 0;
}

View File

@ -52,6 +52,12 @@ ID3D11VertexShader* vertex_shader;
ID3DBlob* pixel_shader_code;
ID3D11PixelShader* pixel_shader;
ID3DBlob* font_vertex_shader_code;
ID3D11VertexShader* font_vertex_shader;
ID3DBlob* font_pixel_shader_code;
ID3D11PixelShader* font_pixel_shader;
ID3D11Buffer* quad_instance_buffer;
int16 window_width;
@ -383,6 +389,8 @@ bool LoadShaders() {
ID3DBlob* error_msgs = 0;
HRESULT error_code = 0;
//Basic Shader
if (error_code = D3DCompileFromFile(L"../Assets/Shader/basic_vertex_shader.hlsl", 0, 0, "main", "vs_5_0", D3DCOMPILE_DEBUG | D3DCOMPILE_WARNINGS_ARE_ERRORS | D3DCOMPILE_OPTIMIZATION_LEVEL0 | D3DCOMPILE_SKIP_OPTIMIZATION, 0, &vertex_shader_code, &error_msgs)) {
log("CompileFromFile has failed");
if (error_msgs)
@ -406,6 +414,32 @@ bool LoadShaders() {
log_error("CreatePixelShader has failed");
return 1;
}
//Font Shader
if (error_code = D3DCompileFromFile(L"../Assets/Shader/font_vertex_shader.hlsl", 0, 0, "main", "vs_5_0", D3DCOMPILE_DEBUG | D3DCOMPILE_WARNINGS_ARE_ERRORS | D3DCOMPILE_OPTIMIZATION_LEVEL0 | D3DCOMPILE_SKIP_OPTIMIZATION, 0, &font_vertex_shader_code, &error_msgs)) {
log("CompileFromFile has failed");
if (error_msgs)
log_error("%.*s", error_msgs->GetBufferSize(), error_msgs->GetBufferPointer());
return 1;
}
if (device->CreateVertexShader(font_vertex_shader_code->GetBufferPointer(), font_vertex_shader_code->GetBufferSize(), 0, &font_vertex_shader)) {
log_error("CreateVertexShader has failed");
return 1;
}
if (error_code = D3DCompileFromFile(L"../Assets/Shader/font_pixel_shader.hlsl", 0, 0, "main", "ps_5_0", D3DCOMPILE_DEBUG | D3DCOMPILE_WARNINGS_ARE_ERRORS | D3DCOMPILE_OPTIMIZATION_LEVEL0, 0, &font_pixel_shader_code, &error_msgs)) {
log("CompileFromFile has failed");
if (error_msgs)
log_error("%.*s", error_msgs->GetBufferSize(), error_msgs->GetBufferPointer());
return 1;
}
if (device->CreatePixelShader(font_pixel_shader_code->GetBufferPointer(), font_pixel_shader_code->GetBufferSize(), 0, &font_pixel_shader)) {
log_error("CreatePixelShader has failed");
return 1;
}
return 0;
}
@ -830,7 +864,7 @@ int main() {
vertex_buffer,
player_instance_buffer,
};
devicecontext->IASetVertexBuffers(0, sizeof(player_input_buffers) / sizeof(*player_input_buffers), player_input_buffers, input_strides, input_offsets);
devicecontext->PSSetShaderResources(0, 1, &player_texture);
@ -839,8 +873,11 @@ int main() {
//Moving Quad
//quad_pos += {0.001f, 0.001f};
render_quad(quad_pos, quad_size, quad_texture, { 0, 0 }, { 1, 1 });
render_quad({ 0.1, 0.2 }, { 0.01, 0.01 }, quad_texture, { 0, 0 }, { 1, 1 });
devicecontext->VSSetShader(font_vertex_shader, 0, 0);
devicecontext->PSSetShader(font_pixel_shader, 0, 0);
render_quad(quad_pos, quad_size, quad_texture, { 0, 0 }, { 0.5, 1 });
render_quad({ 0.1, 0.2 }, { 0.01, 0.01 }, quad_texture, { 0, 0 }, { 1, 1});
//
swap_chain->Present(1, 0);

5082
src/stb_truetype.h Normal file

File diff suppressed because it is too large Load Diff