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

Bash Mills

Members
  • Content count

    6
  • Joined

  • Last visited

Community Reputation

108 Neutral

About Bash Mills

  • Rank
    Newbie
  1. Ahha! Thank you. Works a treat. :)
  2. Well I just converted my index buffer to a dynamic rather than immutable and updated every frame using the same indices (0, 1, 2, 0, 2, 3) along with the vertex buffer and now it works? Must be something wrong with my creation of the immutable index buffer then?
  3. I've also just tried using a LookAt view matrix using a look vector that should be pointing directly at the central sprite position (400, 300, 0.5f) and it still doesn't show anything!   I think something is aiming to misbehave!
  4. Oh and the Z value of the sprite I'm trying to draw is set to 0.5f although I have tried setting this to different values but this is the one that I was expecting to work with it.
  5. Hi. Thanks for your reply. I was made aware that DirectX 11 uses row major matrices but HLSL uses column major matrices so this transpose was necessary for this version of DirectX unlike previous versions. I have the same code in my 3D application that works fine. I did also try commenting them three lines out just in case but still no luck whatsoever. I am using a XMMatrixLookTo to calculate my view matrix from position, look and up vectors. But I've also tried setting each component manually using an additional right vector. No luck there either.   Thanks for your help though :)
  6. Long time reader. First time poster. I got a problem that has been destroying brain cells for some hours now and getting no where fast. So I thought I'd shove it on here to get a fresh pair of eyes on it...   Basically I'm trying to create a 2D game using C++ and DirectX 11. I've used C# and XNA before and I've made a few 3D things in DirectX but nothing this big.   I'm trying to draw a sprite on the center of my screen using a basic camera and basic sprite batch for now but not a thing is showing up and I can't for the life of me figure out why. I'll post some code to give an idea.   This is where I'm setting all my matrices in the camera class and they stay that way (for now, will change later to move etc):   XMStoreFloat4x4(&m_world, XMMatrixIdentity()); XMStoreFloat4x4(&m_proj, XMMatrixOrthographicOffCenterLH(0.0f, width, height, 0.0f, 0.0f, 1.0f)); m_position = XMFLOAT3(width / 2, height / 2, 0); m_look = XMFLOAT3(0, 0, 1); m_up = XMFLOAT3(0, 1, 0); XMVECTOR p = XMLoadFloat3(&m_position); XMVECTOR l = XMLoadFloat3(&m_look); XMVECTOR u = XMLoadFloat3(&m_up); XMStoreFloat4x4(&m_view, XMMatrixLookToLH(p, l, u));   This then gets passed into the sprite batch begin method which passes the info to the shader:   D3D11_MAPPED_SUBRESOURCE data; ZeroMemory(&data, sizeof(data)); m_deviceContext->Map(m_cBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &data); ConstantBuffer* cb = (ConstantBuffer*)data.pData; XMMATRIX w = XMLoadFloat4x4(&world); XMMATRIX v = XMLoadFloat4x4(&view); XMMATRIX p = XMLoadFloat4x4(&proj); w = XMMatrixTranspose(w); v = XMMatrixTranspose(v); p = XMMatrixTranspose(p); XMStoreFloat4x4(&world, w); XMStoreFloat4x4(&view, v); XMStoreFloat4x4(&proj, p); cb->World = world; cb->View = view; cb->Proj = proj; m_deviceContext->Unmap(m_cBuffer, 0);   And finally the shader itself:       cbuffer ConstantBuffer : register(b0)     {     float4x4 World;     float4x4 View;     float4x4 Proj;     };          SamplerState sam : register(s0);     Texture2D tex : register(t0);          struct VertexIn     {     float3 Position : POSITION;     float2 Texture : TEXCOORD;     float4 Color : COLOR;     };          struct PixelIn     {     float4 Position : SV_POSITION;         float2 Texture : TEXCOORD;     float4 Color : COLOR;     };          PixelIn VS(VertexIn vin)     {     float4 position = float4(vin.Position, 1.0f);     position = mul(position, World);     position = mul(position, View);     position = mul(position, Proj);          PixelIn vout;     vout.Position = position;     vout.Texture = vin.Texture;     vout.Color = vin.Color;         return vout;     }          float4 PS(PixelIn pin) : SV_Target     {     float4 textureColor = tex.Sample(sam, pin.Texture);          return pin.Color * textureColor;        }   As you can see, pretty simple stuff. But nothing gets drawn to the screen at all. I've tried not bothering with the matrices at all, leaving out the world matrix, using a perspective projection matrix, using look at rather than look to matrix, using (0, 0, 0) as center via XMMatrixOrthographicLH and converting sprite positions to screen space.   I have even greatly simplified the sprite batch to restricting it to only draw one sprite at a time!   I'm using an immutable index buffer (0, 1, 2, 0, 2, 3) and a dynamic vertex buffer which gets updated as follows:   D3D11_MAPPED_SUBRESOURCE data; ZeroMemory(&data, sizeof(data)); m_deviceContext->Map(m_vBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &data); Vertex* vertex = (Vertex*)data.pData; for(UINT i = 0; i < sprite->Vertices.size(); ++i) { vertex[i] = sprite->Vertices[i]; } m_deviceContext->Unmap(m_vBuffer, 0); m_deviceContext->DrawIndexed(6, 0, 0);   I used similar methods for rendering 3D models. In fact that was harder because I had a dynamic index buffer and a lot more constant buffer data and the shader was a lot more complicated.   I thought it might be a problem with data getting lost somewhere but it all seems to get passed round and through properly right up to the DrawIndexed method call. I've double checked buffer creation and states and currently have it on CULL_NONE just to make sure it's just not being culled.   I'll post buffer creation and sprite creation for clarity:   HRESULT result = S_OK; device->GetImmediateContext(&m_deviceContext); D3D11_BUFFER_DESC cbd; ZeroMemory(&cbd, sizeof(cbd)); cbd.ByteWidth = sizeof(ConstantBuffer); cbd.Usage = D3D11_USAGE_DYNAMIC; cbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; cbd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; cbd.MiscFlags = 0; cbd.StructureByteStride = 0; result = device->CreateBuffer(&cbd, 0, &m_cBuffer); if (FAILED(result)) { return 0; } vector<short> indices; indices.push_back(0); indices.push_back(1); indices.push_back(2); indices.push_back(0); indices.push_back(2); indices.push_back(3); D3D11_SUBRESOURCE_DATA indexData; ZeroMemory(&indexData, sizeof(indexData)); indexData.pSysMem = &indices; D3D11_BUFFER_DESC ibd; ZeroMemory(&ibd, sizeof(ibd)); ibd.ByteWidth = 6 * sizeof(short); ibd.Usage = D3D11_USAGE_IMMUTABLE; ibd.BindFlags = D3D11_BIND_INDEX_BUFFER; ibd.CPUAccessFlags = 0; ibd.MiscFlags = 0; ibd.StructureByteStride = 0; result = device->CreateBuffer(&ibd, &indexData, &m_iBuffer); if (FAILED(result)) { return 0; } D3D11_BUFFER_DESC vbd; ZeroMemory(&vbd, sizeof(vbd)); vbd.ByteWidth = 4 * sizeof(Vertex); vbd.Usage = D3D11_USAGE_DYNAMIC; vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER; vbd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; vbd.MiscFlags = 0; vbd.StructureByteStride = 0; result = device->CreateBuffer(&vbd, 0, &m_vBuffer); if (FAILED(result)) { return 0; } return 1;   Sprite:   ID3D11Resource* resource; ZeroMemory(&resource, sizeof(resource)); texture->GetResource(&resource); ID3D11Texture2D* tex = (ID3D11Texture2D*)resource; D3D11_TEXTURE2D_DESC t; ZeroMemory(&t, sizeof(t)); tex->GetDesc(&t); Vertex v[4]; ZeroMemory(&v, sizeof(v)); v[0].Position = XMFLOAT3((float)destinationRectangle.value.left, (float)destinationRectangle.value.top, z); v[1].Position = XMFLOAT3((float)destinationRectangle.value.right, (float)destinationRectangle.value.top, z); v[2].Position = XMFLOAT3((float)destinationRectangle.value.right, (float)destinationRectangle.value.bottom, z); v[3].Position = XMFLOAT3((float)destinationRectangle.value.left, (float)destinationRectangle.value.bottom, z); v[0].Texture = XMFLOAT2((float)(sourceRectangle.value.left / t.Width), (float)(sourceRectangle.value.top / t.Height)); v[1].Texture = XMFLOAT2((float)(sourceRectangle.value.right / t.Width), (float)(sourceRectangle.value.top / t.Height)); v[2].Texture = XMFLOAT2((float)(sourceRectangle.value.right / t.Width), (float)(sourceRectangle.value.bottom / t.Height)); v[3].Texture = XMFLOAT2((float)(sourceRectangle.value.left / t.Width), (float)(sourceRectangle.value.bottom / t.Height)); v[0].Color = color; v[1].Color = color; v[2].Color = color; v[3].Color = color; Sprite* sprite = new Sprite(); sprite->Vertices.push_back(v[0]); sprite->Vertices.push_back(v[1]); sprite->Vertices.push_back(v[2]); sprite->Vertices.push_back(v[3]); sprite->Texture = texture; m_sprites.push_back(sprite);   Am I going mad? Am I being stupid? Or is there just simply an easier way to do this? Thanks. Any help is appreciated!   Also just like to point out that the sprite I'm drawing has a rectangle (left = 300, right = 500, top = 350, bottom = 450) on a 800x600 screen with an all white color. The texture is being loaded correctly and I've even tried just outputting color in the shader just to make sure with no luck.