Skip to content

Commit

Permalink
font rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
YasirNacak committed Oct 7, 2018
1 parent aec4ebf commit ff41e83
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*.tlog
*.idb
*.exe
*.cso

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
Expand Down
Binary file added data/typeface/argentum_sans_bold_16.spritefont
Binary file not shown.
Binary file added data/typeface/argentum_sans_regular_16.spritefont
Binary file not shown.
24 changes: 24 additions & 0 deletions project/dx11engine.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
</Link>
<FxCompile>
<ObjectFileOutput>$(SolutionDir)data\shader\%(Filename).cso</ObjectFileOutput>
</FxCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
Expand All @@ -122,6 +125,9 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
</Link>
<FxCompile>
<ObjectFileOutput>$(SolutionDir)data\shader\%(Filename).cso</ObjectFileOutput>
</FxCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
Expand All @@ -138,6 +144,9 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
</Link>
<FxCompile>
<ObjectFileOutput>$(SolutionDir)data\shader\%(Filename).cso</ObjectFileOutput>
</FxCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
Expand All @@ -154,6 +163,9 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
</Link>
<FxCompile>
<ObjectFileOutput>$(SolutionDir)data\shader\%(Filename).cso</ObjectFileOutput>
</FxCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\src\Engine.cpp" />
Expand Down Expand Up @@ -195,6 +207,10 @@
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.0</ShaderModel>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)data\shader\%(Filename).cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)data\shader\%(Filename).cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)data\shader\%(Filename).cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)data\shader\%(Filename).cso</ObjectFileOutput>
</FxCompile>
<FxCompile Include="..\data\shader\vertexshader.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
Expand All @@ -205,8 +221,16 @@
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">5.0</ShaderModel>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Vertex</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.0</ShaderModel>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)data\shader\%(Filename).cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)data\shader\%(Filename).cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)data\shader\%(Filename).cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)data\shader\%(Filename).cso</ObjectFileOutput>
</FxCompile>
</ItemGroup>
<ItemGroup>
<None Include="..\data\typeface\argentum_sans_bold_16.spritefont" />
<None Include="..\data\typeface\argentum_sans_regular_16.spritefont" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
11 changes: 11 additions & 0 deletions project/dx11engine.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<Filter Include="data\shader">
<UniqueIdentifier>{9174d02c-d37a-4928-8e5d-17fa19a66cf2}</UniqueIdentifier>
</Filter>
<Filter Include="data\typeface">
<UniqueIdentifier>{f8c1fb49-3d9f-47ab-9ad5-32cc9f13b610}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\input\Keyboard.cpp">
Expand Down Expand Up @@ -110,4 +113,12 @@
<Filter>data\shader</Filter>
</FxCompile>
</ItemGroup>
<ItemGroup>
<None Include="..\data\typeface\argentum_sans_bold_16.spritefont">
<Filter>data\typeface</Filter>
</None>
<None Include="..\data\typeface\argentum_sans_regular_16.spritefont">
<Filter>data\typeface</Filter>
</None>
</ItemGroup>
</Project>
11 changes: 9 additions & 2 deletions src/graphics/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ namespace s3d { namespace graphics {
return false;
}

_spriteBatch = std::make_unique<DirectX::SpriteBatch>(this->_deviceContext.Get());
_spriteFont = std::make_unique<DirectX::SpriteFont>(this->_device.Get(), L"data\\typeface\\argentum_sans_regular_16.spritefont");

return true;
}

Expand All @@ -183,6 +186,10 @@ namespace s3d { namespace graphics {
this->_deviceContext->IASetVertexBuffers(0, 1, _vertexBuffer2.GetAddressOf(), &stride, &offset);
this->_deviceContext->Draw(3, 0);

_spriteBatch->Begin();
_spriteFont->DrawString(_spriteBatch.get(), L"dx11engine", DirectX::XMFLOAT2(0, 0), DirectX::Colors::Aquamarine, 0.0f, DirectX::XMFLOAT2(0.0f, 0.0f), DirectX::XMFLOAT2(1.0f, 1.0f));
_spriteBatch->End();

this->_swapChain->Present(1, NULL);
}

Expand All @@ -194,10 +201,10 @@ namespace s3d { namespace graphics {
{"COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0}
};

if(!_vertexShader.Initialize(this->_device, L"vertexshader.cso", layout, ARRAYSIZE(layout)))
if(!_vertexShader.Initialize(this->_device, L"data\\shader\\vertexshader.cso", layout, ARRAYSIZE(layout)))
return false;

if (!_pixelShader.Initialize(this->_device, L"pixelshader.cso"))
if (!_pixelShader.Initialize(this->_device, L"data\\shader\\pixelshader.cso"))
return false;

// this wont stay like that
Expand Down
5 changes: 5 additions & 0 deletions src/graphics/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "AdapterReader.h"
#include "Shader.h"
#include "Vertex.h"
#include <SpriteBatch.h>
#include <SpriteFont.h>

using Microsoft::WRL::ComPtr;

Expand Down Expand Up @@ -32,5 +34,8 @@ namespace s3d { namespace graphics {
ComPtr<ID3D11DepthStencilState> _depthStencilState;

ComPtr<ID3D11RasterizerState> _rasterizerState;

std::unique_ptr<DirectX::SpriteBatch> _spriteBatch;
std::unique_ptr<DirectX::SpriteFont> _spriteFont;
};
} }

0 comments on commit ff41e83

Please sign in to comment.