• 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
jozsef.horvath

Unable to draw triangle...

2 posts in this topic

Hey everyone.

I've been stuck at this nonsense error for a week now and I can't seem to find the problem. Okay I simplyfied it, because I can't draw even a triangle. Must be some initialization problem but I can't find it even with compare tools. In my other project I could succesfully render my scenes.
Here're the correspoding code snipets:
[CODE]
bool DXManager::Initialize(const HINSTANCE hInstance, const HWND hWnd)
{
m_hInstance = hInstance;
m_hWnd = hWnd;
assert(DriverTypes);
assert(DriverTypes_COUNT);
assert(FeatureLevels);
assert(FeatureLevels_COUNT);
RECT ClientRect;
ZeroMemory(&ClientRect, sizeof(RECT));
GetClientRect(m_hWnd, &ClientRect);
UINT ClientWidth = ClientRect.right - ClientRect.left;
UINT ClientHeight = ClientRect.bottom - ClientRect.top;
DXGI_SWAP_CHAIN_DESC SwapChain_DESCRIPTOR;
ZeroMemory(&SwapChain_DESCRIPTOR, sizeof(DXGI_SWAP_CHAIN_DESC));
SwapChain_DESCRIPTOR.BufferCount = 1;
SwapChain_DESCRIPTOR.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
SwapChain_DESCRIPTOR.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
SwapChain_DESCRIPTOR.BufferDesc.Width = ClientWidth;
SwapChain_DESCRIPTOR.BufferDesc.Height = ClientHeight;
SwapChain_DESCRIPTOR.BufferDesc.RefreshRate.Numerator = 60;
SwapChain_DESCRIPTOR.BufferDesc.RefreshRate.Denominator = 1;
SwapChain_DESCRIPTOR.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
SwapChain_DESCRIPTOR.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
SwapChain_DESCRIPTOR.Flags = 0;
SwapChain_DESCRIPTOR.OutputWindow = m_hWnd;
SwapChain_DESCRIPTOR.SampleDesc.Count = 1;
SwapChain_DESCRIPTOR.SampleDesc.Quality = 0;
SwapChain_DESCRIPTOR.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
SwapChain_DESCRIPTOR.Windowed = true;
HRESULT result = E_FAIL;
for (UINT Driver_INDEX = 0; Driver_INDEX < DriverTypes_COUNT; ++Driver_INDEX)
{
result = D3D11CreateDeviceAndSwapChain( 0,
DriverTypes[Driver_INDEX],
0,
D3D11_CREATE_DEVICE_DEBUG,
FeatureLevels,
FeatureLevels_COUNT,
D3D11_SDK_VERSION,
&SwapChain_DESCRIPTOR,
&m_SwapChain,
&m_Device,
&m_FeatureLevel,
&m_Context);
if (SUCCEEDED(result))
{
m_DriverType = DriverTypes[Driver_INDEX];
break;
}
}
if (FAILED(result))
{
const WCHAR* ErrorString = DXGetErrorStringW(result);
const WCHAR* ErrorDescription = DXGetErrorDescriptionW(result);
MessageBox(m_hWnd, ErrorDescription, ErrorString, MB_ICONERROR | MB_OK);
return false;
}
result = E_FAIL;
ID3D11Texture2D* BackBufferPTR;
result = m_SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<LPVOID*>(&BackBufferPTR));
if (FAILED(result))
{
if (BackBufferPTR != 0)
BackBufferPTR->Release();
DXTRACE_MSG(L"Failed to retrieve backbuffer!");
return false;
}

result = E_FAIL;
result = m_Device->CreateRenderTargetView(BackBufferPTR, 0, &m_RenderTargetView);
if (BackBufferPTR)
BackBufferPTR->Release();
if (FAILED(result))
{
DXTRACE_MSG(L"Failed to create RenderTargetView!");
return false;
}
D3D11_VIEWPORT Viewport;
ZeroMemory(&Viewport, sizeof(D3D11_VIEWPORT));
Viewport.Width = static_cast<float>(ClientWidth);
Viewport.Height = static_cast<float>(ClientHeight);
Viewport.TopLeftX = 0.0f;
Viewport.TopLeftY = 0.0f;
Viewport.MinDepth = 0.0f;
Viewport.MaxDepth = 1.0f;
m_Context->RSSetViewports(1, &Viewport);
return true;
}
[/CODE]

And the triangle file:
[CODE]
bool Triangle::LoadContent(void)
{
bool CompilationResult = false;
HRESULT Result = E_FAIL;

// Vertex Shader
ID3DBlob* vsBuffer = 0;
CompilationResult = CompileShaderFromFile(L"./Shaders/BasicHLSL.fx", "VS_Main", "vs_4_0", &vsBuffer);
if (!CompilationResult)
return false;
Result = m_Device->CreateVertexShader( vsBuffer->GetBufferPointer(),
vsBuffer->GetBufferSize(),
0,
&m_VertexShader);
if (FAILED(Result))
{
DXTRACE_ERR_MSGBOX(L"Error loading vertex shader", Result);
if (vsBuffer != 0)
vsBuffer->Release();

return false;
}
// Vertex Shader END
Result = m_Device->CreateInputLayout( SimpleVertex_InputLayout,
1,
vsBuffer->GetBufferPointer(),
vsBuffer->GetBufferSize(),
&m_InputLayout);
if (FAILED(Result))
{
DXTRACE_ERR_MSGBOX(L"Error while creating input layout", Result);
vsBuffer->Release();
return false;
}
if (vsBuffer != 0)
vsBuffer->Release();
vsBuffer = 0;
// PIXEL SHADER
ID3DBlob* psBuffer = 0;
CompilationResult = CompileShaderFromFile(L"./Shaders/BasicHLSL.fx", "PS_Main", "ps_4_0", &psBuffer);
if (!CompilationResult)
return false;
Result = E_FAIL;
Result = m_Device->CreatePixelShader( psBuffer->GetBufferPointer(),
psBuffer->GetBufferSize(),
0,
&m_PixelShader);
if (FAILED(Result))
{
DXTRACE_ERR_MSGBOX(L"Error loading pixel shader", Result);
psBuffer->Release();
return false;
}
if (psBuffer != 0)
psBuffer->Release();
psBuffer = 0;
// PIXEL SHADER END
// Load Vertices to array
SimpleVertex Vertices[] =
{
XMFLOAT3( 0.0f, 0.5f, -0.25f),
XMFLOAT3( 0.5f,-0.5f, -0.25f),
XMFLOAT3(-0.5f,-0.5f, -0.25f)
};
D3D11_BUFFER_DESC VertexBuffer_DESCRIPTOR;
ZeroMemory(&VertexBuffer_DESCRIPTOR, sizeof(D3D11_BUFFER_DESC));
VertexBuffer_DESCRIPTOR.Usage = D3D11_USAGE_DEFAULT;
VertexBuffer_DESCRIPTOR.BindFlags = D3D11_BIND_VERTEX_BUFFER;
VertexBuffer_DESCRIPTOR.ByteWidth = sizeof(SimpleVertex) * 3;

// setup vertex data
D3D11_SUBRESOURCE_DATA InitialData;
ZeroMemory(&InitialData, sizeof(D3D11_SUBRESOURCE_DATA));
InitialData.pSysMem = Vertices;
Result = m_Device->CreateBuffer(&VertexBuffer_DESCRIPTOR, &InitialData, &m_VertexBuffer);
if (FAILED(Result))
return false;
// TODO
// FIX: - causes assertion!
// delete/[]/ Vertices;
return true;
}
void Triangle::Render(void)
{
assert(m_Context);
float BgColor[4] = { 0.0f, 0.0f, 0.15f, 1.0f };
m_Context->ClearRenderTargetView(m_RenderTargetView, BgColor);
UINT Stride = sizeof(SimpleVertex);
UINT Offset = 0;
assert(m_InputLayout);
assert(m_VertexBuffer);
m_Context->IASetInputLayout(m_InputLayout);
m_Context->IASetVertexBuffers(0, 1, &m_VertexBuffer, &Stride, &Offset);
m_Context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
assert(m_VertexShader);
assert(m_PixelShader);
m_Context->VSSetShader(m_VertexShader, 0, 0);
m_Context->PSSetShader(m_PixelShader, 0, 0);
m_Context->Draw(3, 0);
assert(m_SwapChain);
m_SwapChain->Present(0, 0);
}
[/CODE]

Could someone tell me what am I missing? HLSL in this simple case:
[CODE]
float4 VS_Main(float4 Position : POSITION) : SV_POSITION
{
return Position;
}
float4 PS_Main(float4 Position : SV_POSITION) : SV_TARGET
{
return float4( 1.0f, 1.0f, 1.0f, 1.0f);
}
[/CODE]

Only the blank d3d client area is visible but no triangle. Vertex buffers are loaded and the fx file is compiled so I have no idea where is that error.
0

Share this post


Link to post
Share on other sites
Your vertex positions have a negative z value, which will cause the triangle to get clipped. The visible range is [-1, 1] for X and Y and [0, 1] for Z. Edited by MJP
0

Share this post


Link to post
Share on other sites
Ah thanks, but changing those to positive 0.25 doesn't change anything. Only the blue d3d client area is visible but the triangle is nowhere.
0

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