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


  • Content count

  • Joined

  • Last visited

Community Reputation

155 Neutral

About Wedvich

  • Rank
  1. unsigned int stride = sizeof( SimpleVertex );   That did it. Thank you so much! 
  2. Yeah, I've tried to disable/remove anything related to the depth/stencil testing, but it makes no difference. Here's how I clear my buffers: m_pDeviceContext->ClearRenderTargetView( m_pRenderTargetView, clearColor ); m_pDeviceContext->ClearDepthStencilView( m_pDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0 );   Is this incorrect?
  3. The quoted part is commented out, but either way there is no constant buffer set or used in the shader. Also, here's the graphics debugger log file: [attachment=13303:Graphics Experiment.zip]
  4. I failed a bit with the Y axis there, my bad. Thanks for pointing that out! :) But as you say it still shouldn't matter with culling turned off, and I tried to change the vertex data to the correct coordinates now but with no effect.   I'm pretty sure the render target and the shaders are being set properly. I do have the D3D11_CREATE_DEVICE_DEBUG flag set, but there are no D3D warnings or errors in the debug output. Here's the full initializaiton procedure of the device and render target: bool D3D11RenderSystem::Initialize() { Log::LoggingContext loggingContext( "D3D11RenderSystem::Initialize()" ); IDXGIFactory* pFactory; HRESULT hr = CreateDXGIFactory( __uuidof( IDXGIFactory ), reinterpret_cast< void** >( &pFactory ) ); if ( FAILED( hr ) ) { Log::Write( "ERROR: Could not create DXGI factory!" ); return false; } IDXGIAdapter* pAdapter; hr = pFactory->EnumAdapters( 0, &pAdapter ); if ( FAILED( hr ) ) { Log::Write( "ERROR: Could not get DXGI adapter!" ); return false; } IDXGIOutput* pAdapterOutput; hr = pAdapter->EnumOutputs( 0, &pAdapterOutput ); if ( FAILED( hr ) ) { Log::Write( "ERROR: Could not get DXGI adapter output!" ); return false; } unsigned int numDisplayModes; hr = pAdapterOutput->GetDisplayModeList( DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numDisplayModes, nullptr ); if ( FAILED( hr ) || numDisplayModes == 0 ) { Log::Write( "ERROR: Could not get number of adapter display modes!" ); return false; } auto displayModeList = new DXGI_MODE_DESC[ numDisplayModes ]; hr = pAdapterOutput->GetDisplayModeList( DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &numDisplayModes, displayModeList ); if ( FAILED( hr ) ) { Log::Write( "ERROR: Could not get list of adapter display modes!" ); return false; } RECT cr; GetClientRect( m_pWindow, &cr ); unsigned int width = cr.right - cr.left; unsigned int height = cr.bottom - cr.top; unsigned int numerator = 0; unsigned int denominator = 1; for ( unsigned int i = 0; i < numDisplayModes; ++i ) if ( displayModeList[ i ].Width == width && displayModeList[ i ].Height == height ) { numerator = displayModeList[ i ].RefreshRate.Numerator; denominator = displayModeList[ i ].RefreshRate.Denominator; } DXGI_ADAPTER_DESC adapterDesc; hr = pAdapter->GetDesc( &adapterDesc ); if ( FAILED( hr ) ) { Log::Write( "ERROR: Could not get adapter description!" ); return false; } std::wstring videoCardDescription( adapterDesc.Description ); m_videoCardDescription = std::string( videoCardDescription.begin(), videoCardDescription.end() ); m_videoCardMemory = adapterDesc.DedicatedVideoMemory / 1024 / 1024; std::stringstream ss; ss << "Detected video card: " << m_videoCardDescription; Log::Write( ss.str() ); ss.str( "" ); ss << "Video memory: " << m_videoCardMemory << " MB"; Log::Write( ss.str() ); delete[] displayModeList; ComRelease( pAdapterOutput ); ComRelease( pAdapter ); ComRelease( pFactory ); unsigned int debugFlags = 0; bool tripleBuffering = true; DXGI_SWAP_CHAIN_DESC swapChainDesc; swapChainDesc.BufferCount = tripleBuffering ? 2 : 1; swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; swapChainDesc.BufferDesc.Height = height; swapChainDesc.BufferDesc.RefreshRate.Denominator = m_vsync ? denominator : 1; swapChainDesc.BufferDesc.RefreshRate.Numerator = m_vsync ? numerator : 0; swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; swapChainDesc.BufferDesc.Width = width; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.Flags = 0; swapChainDesc.OutputWindow = m_pWindow; swapChainDesc.SampleDesc.Count = 1; swapChainDesc.SampleDesc.Quality = 0; swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; swapChainDesc.Windowed = !m_fullscreen; D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0 }; const unsigned int numFeatureLevels = ARRAYSIZE( featureLevels ); D3D_DRIVER_TYPE driverTypes[] = { D3D_DRIVER_TYPE_HARDWARE, D3D_DRIVER_TYPE_WARP, D3D_DRIVER_TYPE_REFERENCE }; const unsigned int numDriverTypes = ARRAYSIZE( driverTypes ); unsigned int creationFlags = 0; #ifdef _DEBUG creationFlags |= D3D11_CREATE_DEVICE_DEBUG; #endif for ( unsigned int driverType = 0; driverType < numDriverTypes; ++driverType ) { hr = D3D11CreateDeviceAndSwapChain( nullptr, driverTypes[ driverType ], nullptr, creationFlags, featureLevels, numFeatureLevels, D3D11_SDK_VERSION, &swapChainDesc, &m_pSwapChain, &m_pDevice, &m_featureLevel, &m_pDeviceContext ); if ( SUCCEEDED( hr ) ) { m_driverType = driverTypes[ driverType ]; break; } } if ( FAILED( hr ) ) { Log::Write( "ERROR: Could not create device and swap chain!" ); return false; } ID3D11Texture2D* pBackBuffer; hr = m_pSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), reinterpret_cast< void** >( &pBackBuffer ) ); if ( FAILED( hr ) ) { Log::Write( "ERROR: Could not get back buffer texture!" ); return false; } hr = m_pDevice->CreateRenderTargetView( pBackBuffer, nullptr, &m_pRenderTargetView ); if ( FAILED( hr ) ) { Log::Write( "ERROR: Could not create render target view!" ); return false; } ComRelease( pBackBuffer ); D3D11_TEXTURE2D_DESC depthBufferDesc; depthBufferDesc.ArraySize = 1; depthBufferDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; depthBufferDesc.CPUAccessFlags = 0; depthBufferDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; depthBufferDesc.Height = height; depthBufferDesc.MipLevels = 1; depthBufferDesc.MiscFlags = 0; depthBufferDesc.SampleDesc.Count = 1; depthBufferDesc.SampleDesc.Quality = 0; depthBufferDesc.Usage = D3D11_USAGE_DEFAULT; depthBufferDesc.Width = width; hr = m_pDevice->CreateTexture2D( &depthBufferDesc, nullptr, &m_pDepthStencilBuffer ); if ( FAILED( hr ) ) { Log::Write( "ERROR: Could not create depth stencil buffer!" ); return false; } D3D11_DEPTH_STENCIL_DESC depthStencilDesc; depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR; depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS; depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; depthStencilDesc.DepthEnable = true; depthStencilDesc.DepthFunc = D3D11_COMPARISON_LESS; depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR; depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; depthStencilDesc.StencilEnable = true; depthStencilDesc.StencilReadMask = 0xFF; depthStencilDesc.StencilWriteMask = 0xFF; hr = m_pDevice->CreateDepthStencilState( &depthStencilDesc, &m_pDepthStencilState ); if ( FAILED( hr ) ) { Log::Write( "ERROR: Could not create depth stencil state!" ); return false; } m_pDeviceContext->OMSetDepthStencilState( m_pDepthStencilState, 1 ); D3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc; ZeroMemory( &depthStencilViewDesc, sizeof( depthStencilViewDesc ) ); depthStencilViewDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; depthStencilViewDesc.Texture2D.MipSlice = 0; depthStencilViewDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; hr = m_pDevice->CreateDepthStencilView( m_pDepthStencilBuffer, &depthStencilViewDesc, &m_pDepthStencilView ); if ( FAILED( hr ) ) { Log::Write( "ERROR: Could not create depth stencil view!" ); return false; } m_pDeviceContext->OMSetRenderTargets( 1, &m_pRenderTargetView, m_pDepthStencilView ); D3D11_RASTERIZER_DESC rasterizerDesc; rasterizerDesc.AntialiasedLineEnable = false; rasterizerDesc.CullMode = D3D11_CULL_NONE; rasterizerDesc.DepthBias = 0; rasterizerDesc.DepthBiasClamp = 0.0f; rasterizerDesc.DepthClipEnable = true; rasterizerDesc.FillMode = D3D11_FILL_SOLID; rasterizerDesc.FrontCounterClockwise = false; rasterizerDesc.MultisampleEnable = false; rasterizerDesc.ScissorEnable = false; rasterizerDesc.SlopeScaledDepthBias = 0.0f; hr = m_pDevice->CreateRasterizerState( &rasterizerDesc, &m_pRasterizerState ); if ( FAILED( hr ) ) { Log::Write( "ERROR: Could not create rasterizer state!" ); return false; } m_pDeviceContext->RSSetState( m_pRasterizerState ); D3D11_VIEWPORT viewport; viewport.Height = static_cast< float >( height ); viewport.MaxDepth = 1.0f; viewport.MinDepth = 0.0f; viewport.TopLeftX = 0.0f; viewport.TopLeftY = 0.0f; viewport.Width = static_cast< float >( width ); m_pDeviceContext->RSSetViewports( 1, &viewport ); IDXGIDevice* pDevice = nullptr; m_pDevice->QueryInterface( __uuidof( IDXGIDevice ), reinterpret_cast<void** >( &pDevice ) ); pDevice->GetParent( __uuidof( IDXGIAdapter ), reinterpret_cast< void** >( &pAdapter ) ); pAdapter->GetParent( __uuidof( IDXGIFactory ), reinterpret_cast< void** >( &pFactory ) ); pFactory->MakeWindowAssociation( m_pWindow, DXGI_MWA_NO_ALT_ENTER ); ComRelease( pDevice ); ComRelease( pAdapter ); ComRelease( pFactory ); return true; }     And here's the shader creation: bool StartupScene::Load( Untopia::ICore* pCore ) { Log::LoggingContext loggingContext( "StartupScene::Load()" ); auto pRenderSystem = reinterpret_cast< D3D11RenderSystem* >( pCore->GetSubsystem( "render" ) ); auto pDevice = pRenderSystem->GetDevice(); SimpleVertex vertices[]= { { XMFLOAT3( -1.0f, 1.0f, 0.0f ) }, { XMFLOAT3( 1.0f, 1.0f, 0.0f ) }, { XMFLOAT3( -1.0f, -1.0f, 0.0f ) }, }; m_vertexCount = ARRAYSIZE( vertices ); D3D11_BUFFER_DESC vertexBufferDesc; vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; vertexBufferDesc.ByteWidth = sizeof( Vertex ) * m_vertexCount; vertexBufferDesc.CPUAccessFlags = 0; vertexBufferDesc.MiscFlags = 0; vertexBufferDesc.StructureByteStride = 0; vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT; D3D11_SUBRESOURCE_DATA vertexData; vertexData.pSysMem = vertices; vertexData.SysMemPitch = 0; vertexData.SysMemSlicePitch = 0; HRESULT hr = pDevice->CreateBuffer( &vertexBufferDesc, &vertexData, &m_pVertexBuffer ); if ( FAILED( hr ) ) { Log::Write( "ERROR: Could not create vertex buffer!" ); return false; } char* vsBytes = nullptr; unsigned int numVsBytes = 0; std::ifstream vsFile( "SimpleVS.cso", std::ios::in | std::ios::binary | std::ios::ate ); if ( vsFile.is_open() ) { numVsBytes = static_cast<unsigned int>( vsFile.tellg() ); vsBytes = new char[ numVsBytes ]; vsFile.seekg( 0, std::ios::beg ); vsFile.read( vsBytes, numVsBytes ); vsFile.close(); } hr = pDevice->CreateVertexShader( vsBytes, numVsBytes, nullptr, &m_pVertexShader ); if ( FAILED( hr ) ) { Log::Write( "ERROR: Could not create vertex shader!" ); return false; } D3D11_INPUT_ELEMENT_DESC inputLayouts[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; hr = pDevice->CreateInputLayout( inputLayouts, ARRAYSIZE( inputLayouts ), vsBytes, numVsBytes, &m_pInputLayout ); if ( FAILED( hr ) ) { Log::Write( "ERROR: Could not create input layout!" ); return false; } delete[] vsBytes; char* psBytes = nullptr; unsigned int numPsBytes = 0; std::ifstream psFile( "SimplePS.cso", std::ios::in | std::ios::binary | std::ios::ate ); if ( psFile.is_open() ) { numPsBytes = static_cast<unsigned int>( psFile.tellg() ); psBytes = new char[ numPsBytes ]; psFile.seekg( 0, std::ios::beg ); psFile.read( psBytes, numPsBytes ); psFile.close(); } hr = pDevice->CreatePixelShader( psBytes, numPsBytes, nullptr, &m_pPixelShader ); if ( FAILED( hr ) ) { Log::Write( "ERROR: Could not create pixel shader!" ); return false; } delete[] psBytes; return true; }     And finally, the rendering function: void StartupScene::Render( IRenderSystem* pRenderSystem ) { auto pDeviceContext = reinterpret_cast< D3D11RenderSystem* >( pRenderSystem )->GetDeviceContext(); unsigned int stride = 0; unsigned int offset = 0; pDeviceContext->IASetVertexBuffers( 0, 1, &m_pVertexBuffer, &stride, &offset ); pDeviceContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); pDeviceContext->VSSetConstantBuffers( 0, 1, &m_pMatrixBuffer ); pDeviceContext->IASetInputLayout( m_pInputLayout ); pDeviceContext->VSSetShader( m_pVertexShader, nullptr, 0 ); pDeviceContext->PSSetShader( m_pPixelShader, nullptr, 0 ); pDeviceContext->Draw( m_vertexCount, 0 ); }
  5. I'm trying to render a simple triangle on screen using Direct3D 11, but nothing shows up. Here are my vertices: SimpleVertex vertices[] = { { XMFLOAT3(-1.0f, -1.0f, 0.0f) }, { XMFLOAT3( 1.0f, -1.0f, 0.0f) }, { XMFLOAT3( -1.0f, 1.0f, 0.0f) }, }; The expected output is a triangle with one point in the top left corner of the screen, one point in the top right corner of the screen, and one point in the bottom left corner of the screen. However, nothing is being rendered anywhere. I'm not performing any matrix transformations, and the vertex shader just passes the input directly to the output. Everything seems to be set up correctly, and when I use the graphics debugger in Visual Studio 2012, the correct vertex position is being passed to the vertex shader. However, it skips directly from the vertex shader stage to the output merger stage in the pipeline. I assume this means that nothing is being sent to the pixel shader, which would again mean that the vectors are being discarded in the rasterizer stage. Why is this happening? Here is my rasterizer state: D3D11_RASTERIZER_DESC rasterizerDesc; rasterizerDesc.AntialiasedLineEnable = false; rasterizerDesc.CullMode = D3D11_CULL_NONE; rasterizerDesc.DepthBias = 0; rasterizerDesc.DepthBiasClamp = 0.0f; rasterizerDesc.DepthClipEnable = true; rasterizerDesc.FillMode = D3D11_FILL_SOLID; rasterizerDesc.FrontCounterClockwise = false; rasterizerDesc.MultisampleEnable = false; rasterizerDesc.ScissorEnable = false; rasterizerDesc.SlopeScaledDepthBias = 0.0f; And my viewport (width/height are the window client area matching my back buffer, which are set to 1024x576 in my test setup): D3D11_VIEWPORT viewport; viewport.Height = static_cast< float >( height ); viewport.MaxDepth = 1.0f; viewport.MinDepth = 0.0f; viewport.TopLeftX = 0.0f; viewport.TopLeftY = 0.0f; viewport.Width = static_cast< float >( width ); Can anyone see what is making the rasterize stage skip my vertices? Or are there any other parts of my D3D setup that could be causing this?
  6. TL;DR: skip the first 3 paragraphs.   Hi! I've been toying around with building a 2D engine from scratch using Direct3D 11 for about a week, but I feel I'm in pretty deep water now and I could use some help. I'm very new to D3D, and I never used D3D9 for example, so most of what I've been able to accomplish is from looking at RasterTek's tutorials, and reading the MSDN documentation. Since 2D has been the plan all the way, I've ignored (and completely forgotten about) the Z dimension, but I feel it could come in handy again now for the rendered order of sprites, as my current approach seems very convoluted and inefficient.   First off, I have a stack of Scene objects to control the game state, inspired by the ScreenManager sample from XNA a while back. The scenes are updated from the top down, and when a Scene is closed (such as a menu for example) it is popped off the stack so the focus drops down to the next Scene, which could be the actual game in this example. Pointers to these Scene objects are then sent to my render subsystem and stacked in reverse order, as these will need to be rendered from the bottom up. This part works, and the scenes are rendered in the correct order.   However, I would also like to be able to give different layers to the renderables in a Scene, such as setting text on top of sprites for menus. This is where it currently gets iffy. Currently, I have a std::map with the Scene pointer as its key, and then a std::set of Renderable objects as the value. This set is sorted by a functor that compares a Z index value set for each individual Renderable object. Lower indices are rendered below the higher ones. The good thing about this system is that it works; it does what it's supposed to. The bad thing is that it'll probably become incredibly slow once I get to a certain number of Renderables in the set, because of the logarithmic insert/removes. Since the set doesn't sort itself, it's very impractical to change a Renderable's Z value as well, because I then have to remove it and add it to the set again.   What struck me after quite a while of fighting with this problem, though, is... why am I reimplementing something that is already done natively by the graphics card in 3D applications? Instead of a set, why not just use a std::vector with the Renderables, set their Z position as well to represent their respective layering order, and let the graphics card handle the depth ordering of my vertices. So that's what I'm trying to do now, but I can't get it to work. At first I just tried to set the Z component of the position, but it just ignored that and rendered the Renderables in the order they were added to the vector instead. I hadn't set up a depth buffer, so I did that as well, but then I just get a blank screen. I'm too new with D3D to understand what's going on, and I'm not sure what information you guys might need to try and help me, so I'll just post what I think could be relevant.   The 2D orthographic view-projection matrix that's passed to my vertex shader: XMMATRIX viewMatrix = XMMatrixIdentity(); XMMATRIX projectionMatrix = XMMatrixOrthographicOffCenterLH( 0.0f, resX, resY, 0.0f, minZ, maxZ ); XMMATRIX viewProjectionMatrix = XMMatrixMultiplyTranspose( viewMatrix, projectionMatrix ); XMStoreFloat4x4( &mViewProjectionMatrix, viewProjectionMatrix );   MinZ and MaxZ are currently set to -100.0f and 100.0f respectively, and Renderables are by default placed at Z 0.0f. ResX and ResY are the screen resolution, 1024x576 with the current defaults.   My viewport: vp.Width = resX; vp.Height = resY; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; vp.TopLeftX = 0.0f; vp.TopLeftY = 0.0f;   My active rasterizer state: rasterizerDescs[ 0 ].AntialiasedLineEnable = true; rasterizerDescs[ 0 ].CullMode = D3D11_CULL_NONE; rasterizerDescs[ 0 ].DepthBias = 0; rasterizerDescs[ 0 ].DepthBiasClamp = 0.0f; rasterizerDescs[ 0 ].DepthClipEnable = true; rasterizerDescs[ 0 ].FillMode = D3D11_FILL_SOLID; rasterizerDescs[ 0 ].FrontCounterClockwise = false; rasterizerDescs[ 0 ].MultisampleEnable = true; rasterizerDescs[ 0 ].ScissorEnable = false; rasterizerDescs[ 0 ].SlopeScaledDepthBias = 0.0f;   My attempted, but non-working, depth stencil state/view: D3D11_TEXTURE2D_DESC depthTextureDesc; depthTextureDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; depthTextureDesc.Height = backBufferDesc.Height; depthTextureDesc.Width = backBufferDesc.Width; depthTextureDesc.MipLevels = 1; depthTextureDesc.ArraySize = 1; depthTextureDesc.Format = DXGI_FORMAT_D32_FLOAT_S8X24_UINT; depthTextureDesc.SampleDesc.Count = 1; depthTextureDesc.SampleDesc.Quality = 0; depthTextureDesc.Usage = D3D11_USAGE_DEFAULT; depthTextureDesc.CPUAccessFlags = 0; depthTextureDesc.MiscFlags = 0; D3D11_DEPTH_STENCIL_DESC stencilDesc; stencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; stencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR; stencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; stencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS; stencilDesc.DepthEnable = true; stencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; stencilDesc.DepthFunc = D3D11_COMPARISON_LESS; stencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; stencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR; stencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; stencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; stencilDesc.StencilEnable = true; stencilDesc.StencilReadMask = 0xFF; stencilDesc.StencilWriteMask = 0xFF; D3D11_DEPTH_STENCIL_VIEW_DESC svd; svd.Flags = 0; svd.Format = DXGI_FORMAT_D32_FLOAT_S8X24_UINT; svd.Texture2D.MipSlice = 0; svd.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;   They're all created in the correct order by the device, and throw no errors. I've also set the depth stencil view together with the render target view in the OMSetRenderTargets function, and I do the ClearDepthStencilView together with the ClearRenderTargetView, but to no avail. Just a blank screen.   If you'd like to peek at more of the code, it's all on https://github.com/Wedvich/Untopia (since it's an ongoing project, there are some obsolete classes and code in there). The game loop is in the Game class, while the render calls are in the RenderSystem class.   So, does anyone have any ideas as to what I'm doing wrong? Why can't I get the depth to work properly for this?   Sorry for the rambling wall of text, but I'm new to this and I'm not sure how to formulate it into a concise question. Please ask if I need to clear up anything.   I've also attached a Graphics Debugger log (basically PIX for VS2012) with a frame from the failed depth test, where nothing renders. I'm not sure what to make out of it myself, but here it is: [attachment=13256:graphicslog.zip]
  7. Eventually I figured it out; I was inserting bad vertex data. Changed to this: [source lang="cpp"] Vector3f vertices[] = { Vector3f( -0.5f, 0.5f, 0.5f ), Vector3f( 0.5f, 0.5f, 0.5f ), Vector3f( -0.5f, -0.5f, 0.5f ) };[/source] And everything is fine.
  8. Hi guys! I've been playing around with making games for a little while now, using SDL at first and then SFML. It's been nice to have the basics done for me, but now I'd like to take another step and learn how to do the graphics from the ground up. So I'm trying to learn the ropes of Direct3D, and have been reading a couple of tutorials on D3D 11 to get started. I'm just trying to get the absolute basics going by drawing a white triangle on a dark background... but I can't get it to work. I'm using the Visual Studio 2012 RC and the Windows 8 SDK, so there's some C++11 syntax in here, plus there's no D3DX. I've managed to set up the window and the initialization of Direct3D seems to go just fine. It runs the rendering part of the main loop, as it clears the screen in the color I specify. However, my fancy white triangle just won't show up. I've gone through my code several times, and with my lack of experience I can't tell what is wrong with it. I've cut out the window initialization/d3d shutdown and other irrelevant parts, but I'm afraid to cut off too much in case some of it is relevant to my problem, so... big-wall-of-code-warning. I think I have all the required steps in place; I create the device, device context, swap chain and render target. Then I create a vertex shader+input layout and a pixel shader. After that I create a vertex buffer, add the vertices for my triangle and set the primitive topology to TRIANGLELIST, and that's it for the initialization. In my main loop, I point D3D to my vertex/pixel shaders, and tell it to draw the 3 vertices i inserted into the buffer. But only the dark blue background from the call to ClearRenderTargetView shows up; no triangle. Have I missed any steps, or done anything wrong on the way? Here is the code I have (I'll shamefully admit to have slacked a bit with the code conventions on this one, so no [b]p[/b] before pointer variables etc.): Main loop: [source lang="cpp"] while ( msg.message != WM_QUIT ) { if ( PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) { TranslateMessage( &msg ); DispatchMessage( &msg ); } else { g_d3dContext->ClearRenderTargetView( g_renderTarget, clearColor ); g_d3dContext->VSSetShader( g_vertexShader, nullptr, 0 ); g_d3dContext->PSSetShader( g_pixelShader, nullptr, 0 ); g_d3dContext->Draw( 3, 0 ); g_swapChain->Present( 0, 0 ); } }[/source] D3D init code: [source lang="cpp"]HRESULT hr = S_OK; RECT rc; GetClientRect( g_hWnd, &rc ); float width = static_cast< float >( rc.right - rc.left ); float height = static_cast< float >( rc.bottom - rc.top ); uint createDeviceFlags = 0; #ifdef _DEBUG createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; #endif const uint numDriverTypes = 3; D3D_DRIVER_TYPE driverTypes[ numDriverTypes ] = { D3D_DRIVER_TYPE_HARDWARE, D3D_DRIVER_TYPE_WARP, D3D_DRIVER_TYPE_REFERENCE }; const uint numFeatureLevels = 3; D3D_FEATURE_LEVEL featureLevels[ numFeatureLevels ] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0 }; DXGI_SWAP_CHAIN_DESC sd = { 0 }; sd.BufferCount = 1; sd.BufferDesc.Width = static_cast< uint >( width ); sd.BufferDesc.Height = static_cast< uint >( height ); sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; sd.BufferDesc.RefreshRate.Numerator = 60; sd.BufferDesc.RefreshRate.Denominator = 1; sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; sd.OutputWindow = g_hWnd; sd.SampleDesc.Count = 1; sd.SampleDesc.Quality = 0; sd.Windowed = true; for( uint driverTypeIndex : driverTypes ) { g_driverType = driverTypes[ driverTypeIndex ]; hr = D3D11CreateDeviceAndSwapChain( nullptr, g_driverType, nullptr, createDeviceFlags, featureLevels, numFeatureLevels, D3D11_SDK_VERSION, &sd, &g_swapChain, &g_d3d, &g_featureLevel, &g_d3dContext ); if( SUCCEEDED( hr )) break; } if( FAILED( hr )) return hr; // Create a render target view ID3D11Texture2D* backBuffer = nullptr; hr = g_swapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), reinterpret_cast< void** >( &backBuffer )); if( FAILED( hr )) return hr; hr = g_d3d->CreateRenderTargetView( backBuffer, nullptr, &g_renderTarget ); backBuffer->Release(); if( FAILED( hr )) return hr; g_d3dContext->OMSetRenderTargets( 1, &g_renderTarget, nullptr ); // Setup the viewport D3D11_VIEWPORT vp = { 0 }; vp.Width = width; vp.Height = height; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; vp.TopLeftX = 0; vp.TopLeftY = 0; g_d3dContext->RSSetViewports( 1, &vp ); // Create vertex shader and input layout ID3DBlob* vsBlob = nullptr; ID3DBlob* errorBlob = nullptr; hr = D3DCompileFromFile( L"VertexShader.hlsl", nullptr, nullptr, "main", "vs_4_0", 0, 0, &vsBlob, &errorBlob ); if ( FAILED( hr )) return hr; hr = g_d3d->CreateVertexShader( vsBlob->GetBufferPointer(), vsBlob->GetBufferSize(), nullptr, &g_vertexShader ); if ( FAILED( hr )) { vsBlob->Release(); return hr; } D3D11_INPUT_ELEMENT_DESC ied = { 0 }; ied.AlignedByteOffset = 0; ied.Format = DXGI_FORMAT_R32G32B32_FLOAT; ied.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; ied.InputSlot = 0; ied.InstanceDataStepRate = 0; ied.SemanticIndex = 0; ied.SemanticName = "POSITION"; hr = g_d3d->CreateInputLayout( &ied, 1, vsBlob->GetBufferPointer(), vsBlob->GetBufferSize(), &g_inputLayout ); vsBlob->Release(); if ( FAILED ( hr )) return hr; g_d3dContext->IASetInputLayout( g_inputLayout ); // Create pixel shader ID3DBlob* psBlob = nullptr; errorBlob = nullptr; hr = D3DCompileFromFile( L"PixelShader.hlsl", nullptr, nullptr, "main", "ps_4_0", 0, 0, &psBlob, &errorBlob ); if ( FAILED( hr )) return hr; hr = g_d3d->CreatePixelShader( psBlob->GetBufferPointer(), psBlob->GetBufferSize(), nullptr, &g_pixelShader ); psBlob->Release(); if ( FAILED( hr )) return hr; // Put some vertices up in this bitch Vector3f vertices[] = { Vector3f( 0.5f, -0.5f, 0.5f ), Vector3f( 0.5f, -0.5f, 0.5f ), Vector3f( -0.5f, -0.5f, 0.5f ) }; D3D11_BUFFER_DESC bd = { 0 }; bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; bd.ByteWidth = sizeof( Vector3f ) * 3; bd.CPUAccessFlags = 0; bd.MiscFlags = 0; bd.StructureByteStride = 0; bd.Usage = D3D11_USAGE_DEFAULT; D3D11_SUBRESOURCE_DATA initData = { 0 }; initData.pSysMem = vertices; initData.SysMemPitch = 0; initData.SysMemSlicePitch = 0; hr = g_d3d->CreateBuffer( &bd, &initData, &g_vertexBuffer ); if ( FAILED( hr )) return hr; uint stride = sizeof( Vector3f ); uint offset = 0; g_d3dContext->IASetVertexBuffers( 0, 1, &g_vertexBuffer, &stride, &offset ); g_d3dContext->IASetPrimitiveTopology( D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); return S_OK;[/source] My vertex struct: [source lang="cpp"]struct Vector3f { Vector3f( float ix, float iy, float iz ) : x( ix ), y( iy ), z( iz ) {} float x; float y; float z; };[/source] My vertex shader: [source lang="cpp"]float4 main( float4 pos : POSITION ) : SV_POSITION { return pos; }[/source] My pixel shader: [source lang="cpp"]float4 main() : SV_TARGET { return float4( 1.0f, 1.0f, 1.0f, 1.0f ); }[/source]