• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
SamiHuutoniemi

Making a font engine

2 posts in this topic

First post here. Hope I don't do anything that's not okay here.

I'm making a font engine for my Tetris game, but I've run into problems. Problem is I don't know where the problem is, cause everything seems right. Except that no text is drawn of course.

Here is the effects file, anything strange there? The first part is for my colored tetris cubes, and it works fine. It's the second part, that I'm trying to make my font shader.

The code is based on the tutorials from Rastertek, but with some modifications. I have a completely different class structure, and I'm trying to use XNA math.

[source lang="cpp"]cbuffer cbPerObject
{
float4x4 WVP;
};

struct VS_COLOR_OUTPUT
{
float4 Pos : SV_POSITION;
float4 Color : COLOR;
};

VS_COLOR_OUTPUT VS_Color(float4 inPos : POSITION, float4 inColor : COLOR)
{
VS_COLOR_OUTPUT output;
output.Pos = mul(inPos, WVP);
output.Color = inColor;

return output;
}

float4 PS_Color(VS_COLOR_OUTPUT input) : SV_TARGET
{
return input.Color;
}






struct VS_TEXTURE_OUTPUT
{
float4 position: SV_POSITION;
float2 tex: TEXCOORD0;
};

VS_TEXTURE_OUTPUT VS_Font(VS_TEXTURE_OUTPUT input)
{
VS_TEXTURE_OUTPUT output;

// Change the position vector to be 4 units for proper matrix calculations.
input.position.w = 1.0f;

// Calculate the position of the vertex against the world, view, and projection matrices.
output.position = mul(input.position, WVP);


// Store the texture coordinates for the pixel shader.
output.tex = input.tex;

return output;
}

Texture2D shaderTexture;
SamplerState SampleType;

cbuffer PixelBuffer
{
float4 pixelColor;
};


float4 PS_Font(VS_TEXTURE_OUTPUT input) : SV_TARGET
{
float4 color;


// Sample the texture pixel at this location.
color = shaderTexture.Sample(SampleType, input.tex);

// If the color is black on the texture then treat this pixel as transparent.
if(color.r == 0.0f)
{
color.a = 0.0f;
}

// If the color is other than black on the texture then this is a pixel in the font so draw it using the font pixel color.
else
{
color.a = 1.0f;
color = color * pixelColor;
}

return color;
}[/source]

Here is the Text::Render() which is supposed to render the text:

[source lang="cpp"]void Text::Render() {
HRESULT hr;

unsigned int stride, offset;
D3DXVECTOR4 pixelColor;

// Set vertex buffer stride and offset.
stride = sizeof(TextureVertex);
offset = 0;

// Set the vertex buffer to active in the input assembler so it can be rendered.
pD3DEngine->getDeviceContext()->IASetVertexBuffers(0, 1, &pVertexBuffer, &stride, &offset);

// Set the index buffer to active in the input assembler so it can be rendered.
pD3DEngine->getDeviceContext()->IASetIndexBuffer(pIndexBuffer, DXGI_FORMAT_R32_UINT, 0);

// Set the type of primitive that should be rendered from this vertex buffer, in this case triangles.
pD3DEngine->getDeviceContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

// Create a pixel color vector with the input sentence color.
pixelColor = D3DXVECTOR4(colorR, colorG, colorB, 1.0f);

XMFLOAT4X4 worldMatrix;
XMStoreFloat4x4(&worldMatrix, XMMatrixIdentity());
XMMATRIX WVP = XMLoadFloat4x4(&worldMatrix) * pD3DEngine->getViewMatrix() * pD3DEngine->getProjectionMatrix();

// Lock the constant buffer so it can be written to.
D3D11_MAPPED_SUBRESOURCE mappedResource;
hr = pD3DEngine->getDeviceContext()->Map(pConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);

// Get a pointer to the data in the constant buffer.
cbPerObject* dataPtr;
dataPtr = (cbPerObject*)mappedResource.pData;

XMStoreFloat4x4(&dataPtr->WVP, XMMatrixTranspose(WVP));
// Unlock the constant buffer.
pD3DEngine->getDeviceContext()->Unmap(pConstantBuffer, 0);

// Now set the constant buffer in the vertex shader with the updated values.
pD3DEngine->getDeviceContext()->VSSetConstantBuffers(0, 1, &pConstantBuffer);

// Set shader texture resource in the pixel shader.
ID3D11ShaderResourceView* tex = pFont->GetTexture()->GetTexture();
pD3DEngine->getDeviceContext()->PSSetShaderResources(0, 1, &tex);

pD3DEngine->getDeviceContext()->IASetInputLayout(pFontShader->GetInputLayout());
pD3DEngine->getDeviceContext()->VSSetShader(pFontShader->GetVertexShader(), 0, 0);
pD3DEngine->getDeviceContext()->PSSetShader(pFontShader->GetPixelShader(), 0, 0);

// Set the sampler state in the pixel shader.
pD3DEngine->getDeviceContext()->PSSetSamplers(0, 1, &pSampleState);

// Render the triangles.
pD3DEngine->getDeviceContext()->DrawIndexed(numIndices, 0, 0);
}[/source]
I'm happy to post more code on request, if this code looks allright.

Btw: the constant buffer struct is just
[source lang="cpp"]struct cbPerObject {
XMFLOAT4X4 WVP;
};[/source]

EDIT: Found out that my DrawIndexed call yields:
ID3D11DeviceContext::DrawIndexed: Constant Buffer expected at slot 0 of the Pixel Shader unit (with size at least 16 bytes) but none is bound. This is OK, as reads of an unbound Constant Buffer are defined to return 0. It is also posible the developer knows the data will not be used anyway. This is only a problem if the developer actually intended to bind a Constant Buffer here. [ EXECUTION INFO #350: DEVICE_DRAW_CONSTANT_BUFFER_NOT_SET ]

Why is this? I do set the constant buffer! Edited by SamiHuutoniemi
0

Share this post


Link to post
Share on other sites
And a more general question: How does one debug a problem like this, when it's (for me) extremely unobvious where the problem is?
0

Share this post


Link to post
Share on other sites
You set the Vertex shaders CBuffer only, but in your pixel shader, you have another CBuffer called PixelBuffer, which is never set but it is used (which I assume was meant to be filled with the [color=#000000][font=Consolas,]pixelColor variable)[/font][/color]. you need to use PSSetConstantBuffers to bind the CBuffer for your pixel shader (or remove the CBuffer and pass it as a per instance parameter).

As for debugging, best way is to create a debug device while developing (and set the full verbose DX debug output) and have SysInternals' DbgView running in the background. It also requires you to be a bit more familiar with the API, and read the debug messages more carefully. Edited by Necrolis
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0