New text render

This commit is contained in:
lanariel 2014-02-13 16:27:53 +01:00
parent 491dc88bd1
commit e71264b806
5 changed files with 26 additions and 21 deletions

View File

@ -159,7 +159,7 @@ namespace Oyster
Render::Gui::Begin2DRender(); Render::Gui::Begin2DRender();
} }
void API::RenderGuiElement(API::Texture tex, Math::Float2 pos, Math::Float2 size, Math::Float3 color) void API::RenderGuiElement(API::Texture tex, Math::Float3 pos, Math::Float2 size, Math::Float3 color)
{ {
Render::Gui::Render((ID3D11ShaderResourceView*)tex,pos,size,color); Render::Gui::Render((ID3D11ShaderResourceView*)tex,pos,size,color);
} }
@ -192,9 +192,9 @@ namespace Oyster
Render::Gui::Begin2DTextRender(); Render::Gui::Begin2DTextRender();
} }
void API::RenderText(std::wstring text, Math::Float2 Pos, Math::Float2 Size, Math::Float3 color) void API::RenderText(std::wstring text, Math::Float3 Pos, Math::Float2 Size, float FontSize, Math::Float3 color)
{ {
Render::Gui::RenderText(text,Pos,Size,color); Render::Gui::RenderText(text, Pos, Size, FontSize, color);
} }
} }
} }

View File

@ -57,13 +57,13 @@ namespace Oyster
static void StartGuiRender(); static void StartGuiRender();
//! @brief Renders a single GUI element using the texture provided and the Pos in the center, %based system //! @brief Renders a single GUI element using the texture provided and the Pos in the center, %based system
static void RenderGuiElement(Texture, Math::Float2 Pos, Math::Float2 Size, Math::Float3 Color = Math::Float3(1,1,1)); static void RenderGuiElement(Texture, Math::Float3 Pos, Math::Float2 Size, Math::Float3 Color = Math::Float3(1,1,1));
//! @brief Configures Renderer to process 2D Text, data will be passed in to EndFrame() //! @brief Configures Renderer to process 2D Text, data will be passed in to EndFrame()
static void StartTextRender(); static void StartTextRender();
//! @brief Renders a single GUI string using the texture provided and the Pos in the center, %based system //! @brief Renders a single GUI string using the texture provided and the Pos in the center, %based system
static void RenderText(std::wstring, Math::Float2 Pos, Math::Float2 Size, Math::Float3 Color = Math::Float3(1,1,1)); static void RenderText(std::wstring, Math::Float3 Pos, Math::Float2 Size, float FontSize, Math::Float3 Color = Math::Float3(1,1,1));
//! @brief Performs light calculations, post effects and presents the scene //! @brief Performs light calculations, post effects and presents the scene
static void EndFrame(); static void EndFrame();

View File

@ -16,7 +16,7 @@ namespace Oyster
Core::PipelineManager::SetRenderPass(Render::Resources::Gui::Pass); Core::PipelineManager::SetRenderPass(Render::Resources::Gui::Pass);
} }
void Gui::Render(ID3D11ShaderResourceView* tex,Math::Float2 pos, Math::Float2 size, Math::Float3 color) void Gui::Render(ID3D11ShaderResourceView* tex,Math::Float3 pos, Math::Float2 size, Math::Float3 color)
{ {
Core::deviceContext->PSSetShaderResources(0,1,&tex); Core::deviceContext->PSSetShaderResources(0,1,&tex);
@ -28,6 +28,7 @@ namespace Oyster
gd.Translation = Math::Matrix::identity; gd.Translation = Math::Matrix::identity;
gd.Translation.m41 = pos.x; gd.Translation.m41 = pos.x;
gd.Translation.m42 = pos.y; gd.Translation.m42 = pos.y;
gd.Translation.m43 = pos.z;
gd.Translation.m11 = size.x; gd.Translation.m11 = size.x;
gd.Translation.m22 = size.y; gd.Translation.m22 = size.y;
@ -49,10 +50,10 @@ namespace Oyster
Core::PipelineManager::SetRenderPass(Resources::Gui::Text::Pass); Core::PipelineManager::SetRenderPass(Resources::Gui::Text::Pass);
} }
void Gui::RenderText(std::wstring text, Math::Float2 pos, Math::Float2 size, Math::Float3 color) void Gui::RenderText(std::wstring text, Math::Float3 pos, Math::Float2 size, float FontSize, Math::Float3 color)
{ {
size.x = size.x / (text.length() * TEXT_SPACING /2); //size.x = size.x / (text.length() * TEXT_SPACING /2);
pos *= 2; pos *= 2;
@ -60,15 +61,18 @@ namespace Oyster
pos.y *= -1; pos.y *= -1;
pos.x = pos.x - (size.x * (text.length()-1) * TEXT_SPACING /2); //pos.x = pos.x - (size.x * (text.length()-1) * TEXT_SPACING /2);
pos.x = pos.x + size.x/ (text.length() * TEXT_SPACING/2);
pos.y = pos.y - size.y/2;
Definitions::GuiData gd; Definitions::GuiData gd;
gd.Translation = Math::Matrix::identity; gd.Translation = Math::Matrix::identity;
gd.Translation.m41 = pos.x; gd.Translation.m41 = pos.x;
gd.Translation.m42 = pos.y; gd.Translation.m42 = pos.y;
gd.Translation.m11 = size.x; gd.Translation.m43 = pos.z;
gd.Translation.m22 = size.y; gd.Translation.m11 = FontSize * 0.8f;
gd.Translation.m22 = FontSize;
void* data = Render::Resources::Gui::Data.Map(); void* data = Render::Resources::Gui::Data.Map();
@ -82,19 +86,20 @@ namespace Oyster
void* dest = Resources::Gui::Text::Vertex.Map(); void* dest = Resources::Gui::Text::Vertex.Map();
Definitions::Text2D* dataView = reinterpret_cast<Definitions::Text2D*>(dest); Definitions::Text2D* dataView = reinterpret_cast<Definitions::Text2D*>(dest);
//tmpInst.charOffset=_pos;
for (unsigned int i=0; i<text.length(); i++) for (unsigned int i=0; i<text.length(); i++)
{ {
tmpInst.coff=(1.0f/TEXT_NR_LETTERS); tmpInst.coff=(1.0f/TEXT_NR_LETTERS);
tmpInst.offset=text[i]-32; tmpInst.offset=text[i]-32;
tmpInst.pos=i*(size.x * TEXT_SPACING); tmpInst.pos=i*(FontSize * 0.8f * TEXT_SPACING);
//float tst=getCharID(_str[i]); if(tmpInst.pos > size.x)
//tmpInst.offset=tst; {
//tmpInst.charOffset.x=_pos.x-i*TEXT_SIZE; text = text.substr(0,i-1);
//tmpInst.data=tst; break;
}
dataView[i]=tmpInst; dataView[i]=tmpInst;
} }
//TextInstances[_id].NumLetters=instances;
Resources::Gui::Text::Vertex.Unmap(); Resources::Gui::Text::Vertex.Unmap();

View File

@ -12,9 +12,9 @@ namespace Oyster
{ {
public: public:
static void Begin2DRender(); static void Begin2DRender();
static void Render(ID3D11ShaderResourceView* tex, Math::Float2 pos, Math::Float2 size, Math::Float3 tint = Math::Float3(1,1,1)); static void Render(ID3D11ShaderResourceView* tex, Math::Float3 pos, Math::Float2 size, Math::Float3 tint = Math::Float3(1,1,1));
static void Begin2DTextRender(); static void Begin2DTextRender();
static void RenderText(std::wstring text, Math::Float2 pos, Math::Float2 size, Math::Float3 tint = Math::Float3(1,1,1)); static void RenderText(std::wstring text, Math::Float3 pos, Math::Float2 size, float FontSize, Math::Float3 tint = Math::Float3(1,1,1));
}; };
} }
} }

View File

@ -246,7 +246,7 @@ HRESULT Render(float deltaTime)
fps = std::to_wstring(f); fps = std::to_wstring(f);
//Oyster::Graphics::API::RenderText(L"Lanariel",Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f)); //Oyster::Graphics::API::RenderText(L"Lanariel",Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f));
//Oyster::Graphics::API::RenderText(L"Lanariel WAS HERE",Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f)); //Oyster::Graphics::API::RenderText(L"Lanariel WAS HERE",Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f));
Oyster::Graphics::API::RenderText(fps,Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float3(0,1,0)); Oyster::Graphics::API::RenderText(fps,Oyster::Math::Float3(0.5f,0.1f,1.0f),Oyster::Math::Float2(0.5f,0.1f), 0.08f, Oyster::Math::Float3(0,1,0));
Oyster::Graphics::API::EndFrame(); Oyster::Graphics::API::EndFrame();
return S_OK; return S_OK;