title: triangle not showing up direct3d11
body: <p>I am trying to draw a triangle as the first step in a game engine I am developing, here is the code for the graphics system:</p>
  <p>graphics.hpp</p>
  <pre><code>#pragma once
  
  #include &quot;Engine.hpp&quot;
  
  #include &lt;type_traits&gt;
  #include &lt;codecvt&gt;
  
  #include &quot;Window.hpp&quot;
  #include &quot;Shader.hpp&quot;
  
  namespace engine::graphics
  {
      class GraphicsData final
      {
      public:
          logger::Logger* logger;
  
          Window* window;
          const std::string engineName;
          bool fullScreen;
      };
  
      class Graphics
      {
      public:
          virtual bool createGraphics(const GraphicsData&amp; data) = 0;
          virtual void destroyGraphics() = 0;
  
          virtual void clearFrame() = 0;
          virtual void drawVertexes(const std::vector&lt;std::any&gt;&amp; vertexes) = 0;
          virtual void presentFrame() = 0;
  
          virtual Graphics&amp; loadShader(const std::string&amp; shaderName, GraphicsShader* shader) = 0;
      };
  
  #ifdef _WIN32
      struct DxVertex
      {
          DirectX::XMFLOAT3 m_Pos;
      };
  
      class DxGraphics final : public Graphics
      {
          ID3D11Device* m_Device;
          ID3D11DeviceContext* m_Context;
          IDXGISwapChain* m_Swapchain;
          ID3D11RasterizerState* m_RState;
          ID3D11RenderTargetView* m_RenderTargetView;
          ID3D11InputLayout* m_InputLayout;
  
          D3D_FEATURE_LEVEL m_FeatureLevel;
          D3D11_VIEWPORT m_Viewport;
  
          std::map&lt;std::string, GraphicsShader*&gt; m_GraphicsShaders;
  
          std::shared_ptr&lt;logger::Logger&gt; m_Logger;
          
          DXGI_SWAP_CHAIN_DESC GetDesc(
              Window* window,
              bool windowed
          );
  
      public:
          bool createGraphics(const GraphicsData&amp; data) override;
          void destroyGraphics() override;
  
          void clearFrame() override;
          void drawVertexes(const std::vector&lt;std::any&gt;&amp; vertexes) override;
          void presentFrame() override;
  
          Graphics&amp; loadShader(const std::string&amp; shaderName, GraphicsShader* shader) override;
      };
  #endif
  }
  </code></pre>
  <p>graphics.cpp</p>
  <pre><code>#include &quot;Graphics.hpp&quot;
  
  DXGI_SWAP_CHAIN_DESC engine::graphics::DxGraphics::GetDesc(Window* window, bool windowed)
  {
      RECT rect{};
      GetClientRect(std::any_cast&lt;HWND&gt;(window-&gt;getWindowHandle()), &amp;rect);
  
      DXGI_SWAP_CHAIN_DESC desc{
          .BufferDesc = DXGI_MODE_DESC{
              .Width = static_cast&lt;unsigned int&gt;(rect.right - rect.left),
              .Height = static_cast&lt;unsigned int&gt;(rect.bottom - rect.top),
              .RefreshRate = DXGI_RATIONAL{
                  .Numerator = 60, // TODO: fix this
                  .Denominator = 1
              },
              .Format = DXGI_FORMAT::DXGI_FORMAT_R8G8B8A8_UNORM,
              .ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER::DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE,
              .Scaling = DXGI_MODE_SCALING::DXGI_MODE_SCALING_CENTERED
          },
          .SampleDesc = DXGI_SAMPLE_DESC{
              .Count = 1,
              .Quality = 0
          },
          .BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT,
          .BufferCount = 2,
          .OutputWindow = std::any_cast&lt;HWND&gt;(window-&gt;getWindowHandle()),
          .Windowed = windowed,
          .SwapEffect = DXGI_SWAP_EFFECT::DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL,
          .Flags = 0
      };
  
      return desc;
  }
  
  bool engine::graphics::DxGraphics::createGraphics(const GraphicsData&amp; data)
  {
      m_Logger.reset(data.logger);
  
      unsigned int flags = D3D11_CREATE_DEVICE_FLAG::D3D11_CREATE_DEVICE_BGRA_SUPPORT;
  #ifdef _DEBUG
      flags |= D3D11_CREATE_DEVICE_FLAG::D3D11_CREATE_DEVICE_DEBUG;
  #endif // _DEBUG
  
      D3D_FEATURE_LEVEL featureLevel[] = {
          D3D_FEATURE_LEVEL::D3D_FEATURE_LEVEL_11_0,
          D3D_FEATURE_LEVEL::D3D_FEATURE_LEVEL_11_1
      };
  
      DXGI_SWAP_CHAIN_DESC desc = GetDesc(data.window, !data.fullScreen);
  
      HRESULT hr;
  
      hr = D3D11CreateDeviceAndSwapChain(
          nullptr,
          D3D_DRIVER_TYPE::D3D_DRIVER_TYPE_HARDWARE,
          nullptr,
          flags,
          featureLevel,
          2,
          D3D11_SDK_VERSION,
          &amp;desc,
          &amp;m_Swapchain,
          &amp;m_Device,
          &amp;m_FeatureLevel,
          &amp;m_Context
      );
      if (FAILED(hr))
      {
          *m_Logger &lt;&lt; logger::Message{
              .type = logger::Message::Type::CLIENT,
              .severity = logger::Message::Severity::ERR,
              .data = &quot;Failed to create device and swapchain&quot;
          };
          return false;
      }
  
      ID3D11Texture2D* texture = nullptr;
      hr = m_Swapchain-&gt;GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast&lt;void**&gt;(&amp;texture));
      if (FAILED(hr))
      {
          *m_Logger &lt;&lt; logger::Message{
              .type = logger::Message::Type::CLIENT,
              .severity = logger::Message::Severity::ERR,
              .data = &quot;Failed to collect backbuffer used for rendering&quot;
          };
          return false;
      }
  
      hr = m_Device-&gt;CreateRenderTargetView(texture, nullptr, &amp;m_RenderTargetView);
  
      if (texture)
          texture-&gt;Release();
  
      if (FAILED(hr))
      {
          *m_Logger &lt;&lt; logger::Message{
              .type = logger::Message::Type::CLIENT,
              .severity = logger::Message::Severity::ERR,
              .data = &quot;Failed to set render target view&quot;
          };
          return false;
      }
  
      m_Context-&gt;OMSetRenderTargets(1, &amp;m_RenderTargetView, nullptr);
  
      m_Viewport = {
          .TopLeftX = 0,
          .TopLeftY = 0,
          .Width = static_cast&lt;float&gt;(desc.BufferDesc.Width),
          .Height = static_cast&lt;float&gt;(desc.BufferDesc.Height),
          .MinDepth = 0,
          .MaxDepth = 1
      };
  
      D3D11_RASTERIZER_DESC rsDesc{
          .FillMode = D3D11_FILL_MODE::D3D11_FILL_SOLID,
          .CullMode = D3D11_CULL_MODE::D3D11_CULL_BACK,
          .FrontCounterClockwise = true,
          .DepthBias = 0,
          .DepthBiasClamp = 1,
          .SlopeScaledDepthBias = 0,
          .DepthClipEnable = true,
          .ScissorEnable = false,
          .MultisampleEnable = false,
          .AntialiasedLineEnable = false
      };
  
      m_Device-&gt;CreateRasterizerState(
          &amp;rsDesc,
          &amp;m_RState
      );
  
      m_Context-&gt;RSSetState(
          m_RState
      );
      m_Context-&gt;RSSetViewports(1, &amp;m_Viewport);
  
      return true;
  }
  
  void engine::graphics::DxGraphics::clearFrame()
  {
      float color[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
      m_Context-&gt;ClearRenderTargetView(m_RenderTargetView, color);
  
      m_Context-&gt;RSSetState(m_RState);
      m_Context-&gt;RSSetViewports(1, &amp;m_Viewport);
  
      m_Context-&gt;OMSetRenderTargets(1, &amp;m_RenderTargetView, nullptr);
  }
  
  void engine::graphics::DxGraphics::drawVertexes(const std::vector&lt;std::any&gt;&amp; vertexes)
  {
      HRESULT hr;
  
      ID3D11Buffer* buffer;
  
      D3D11_INPUT_ELEMENT_DESC shaderInputLayout[] = {
          D3D11_INPUT_ELEMENT_DESC{
              .SemanticName = &quot;POSITION&quot;,
              .SemanticIndex = 0,
              .Format = DXGI_FORMAT::DXGI_FORMAT_R32G32B32_FLOAT,
              .InputSlot = 0,
              .AlignedByteOffset = 0,
              .InputSlotClass = D3D11_INPUT_CLASSIFICATION::D3D11_INPUT_PER_VERTEX_DATA,
              .InstanceDataStepRate = 0
          }
      };
      UINT numLayoutElements = ARRAYSIZE(shaderInputLayout);
  
      hr = m_Device-&gt;CreateInputLayout(
          shaderInputLayout,
          numLayoutElements,
          m_GraphicsShaders.at(&quot;vertex&quot;)-&gt;getShaderCode(),
          m_GraphicsShaders.at(&quot;vertex&quot;)-&gt;getShaderCodeSize(),
          &amp;m_InputLayout
      );
      if (FAILED(hr))
      {
          *m_Logger &lt;&lt; logger::Message{
              .type = logger::Message::Type::CLIENT,
              .severity = logger::Message::Severity::ERR,
              .data = &quot;Failed to create input layout&quot;
          };
          return;
      }
  
      m_Context-&gt;IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY::D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
      m_Context-&gt;IASetInputLayout(m_InputLayout);
  
      UINT byteWidth = sizeof(DxVertex) * vertexes.size();
  
      D3D11_BUFFER_DESC desc{};
      desc.Usage = D3D11_USAGE::D3D11_USAGE_DEFAULT;
      desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
      desc.ByteWidth = byteWidth;
      desc.StructureByteStride = sizeof(DxVertex);
  
      D3D11_SUBRESOURCE_DATA resource{};
      resource.pSysMem = vertexes.data();
  
      hr = m_Device-&gt;CreateBuffer(
          &amp;desc,
          &amp;resource,
          &amp;buffer
      );
      if (FAILED(hr))
      {
          if (buffer)
              buffer-&gt;Release();
  
          *m_Logger &lt;&lt; logger::Message{
                 .type = logger::Message::Type::CLIENT,
                 .severity = logger::Message::Severity::ERR,
                 .data = &quot;Failed to create vertex buffer&quot;
          };
          return;
      }
  
      UINT strides = sizeof(DxVertex);
      UINT offset = 0;
  
      m_Context-&gt;IASetVertexBuffers(0, 1, &amp;buffer, &amp;strides, &amp;offset);
  
      m_Context-&gt;VSSetShader(static_cast&lt;ID3D11VertexShader*&gt;(m_GraphicsShaders.at(&quot;vertex&quot;)-&gt;getShader()), nullptr, 0);
      m_Context-&gt;PSSetShader(static_cast&lt;ID3D11PixelShader*&gt;(m_GraphicsShaders.at(&quot;pixel&quot;)-&gt;getShader()), nullptr, 0);
  
      UINT numVertexes = vertexes.size();
  
      m_Context-&gt;Draw(numVertexes, 0);
  
      if (buffer)
          buffer-&gt;Release();
  
      if (m_InputLayout)
          m_InputLayout-&gt;Release();
  }
  
  void engine::graphics::DxGraphics::presentFrame()
  {
      m_Swapchain-&gt;Present(0, 0);
  }
  
  engine::graphics::Graphics&amp; engine::graphics::DxGraphics::loadShader(const std::string&amp; shaderName, GraphicsShader* shader)
  {
      DxGraphicsShaderData data{
          .device = m_Device,
          .context = m_Context
      };
      data.logger = m_Logger.get();
      shader-&gt;createShader(data);
      m_GraphicsShaders.insert(std::make_pair(shaderName, shader));
  
      return *this;
  }
  
  void engine::graphics::DxGraphics::destroyGraphics()
  {
      for (auto&amp; shader : m_GraphicsShaders)
      {
          shader.second-&gt;destroyShader();
          delete shader.second;
      }
      if (m_RenderTargetView)
      {
          m_RenderTargetView-&gt;Release();
      }
      if (m_Swapchain)
      {
          m_Swapchain-&gt;Release();
      }
      if (m_Context)
      {
          m_Context-&gt;Release();
      }
      if (m_Device)
      {
          m_Device-&gt;Release();
      }
  }
  </code></pre>
  <p>shader.hpp</p>
  <pre><code>#pragma once
  
  #include &quot;Engine.hpp&quot;
  
  #include &quot;Logger.hpp&quot;
  
  namespace engine::graphics
  {
      struct GraphicsShaderData
      {
          logger::Logger* logger;
      };
  
      class GraphicsShader
      {
      public:
          virtual bool createShader(const GraphicsShaderData&amp; data) = 0;
          virtual void destroyShader() = 0;
  
          virtual const char* getShaderCode() = 0;
          virtual size_t getShaderCodeSize() = 0;
  
          virtual void* getShader() = 0;
      };
  
  #ifdef _WIN32
      struct DxGraphicsShaderData final : public GraphicsShaderData
      {
          ID3D11Device* device;
          ID3D11DeviceContext* context;
      };
  
      template&lt;typename T&gt;
      class DxGraphicsShader final : public GraphicsShader
      {
      };
  
      template&lt;&gt;
      class DxGraphicsShader&lt;ID3D11VertexShader&gt; final : public GraphicsShader
      {
          ID3DBlob* m_Code;
          ID3D11VertexShader* m_Shader;
  
      public:
          bool createShader(const GraphicsShaderData&amp; data) override
          {
              const DxGraphicsShaderData&amp; dxdata = static_cast&lt;const DxGraphicsShaderData&amp;&gt;(data);
  
              int flags = D3DCOMPILE_ENABLE_STRICTNESS;
  #ifdef _DEBUG
              flags |= D3DCOMPILE_DEBUG;
  #endif // _DEBUG
              HRESULT hr;
              ID3DBlob* errBuff;
  
              hr = D3DCompileFromFile(
                  std::wstring_convert&lt;std::codecvt_utf8_utf16&lt;wchar_t&gt;&gt;().from_bytes(
                      &quot;vertex.hlsl&quot; // TODO: fix with resource manager
                  ).c_str(),
                  nullptr,
                  nullptr,
                  &quot;VMain&quot;,
                  &quot;vs_5_0&quot;,
                  flags,
                  0,
                  &amp;m_Code,
                  &amp;errBuff
              );
  
              if (FAILED(hr))
              {
                  if (errBuff)
                  {
                      *dxdata.logger &lt;&lt; logger::Message{
                          .type = logger::Message::Type::CLIENT,
                          .severity = logger::Message::Severity::ERR,
                          .data = static_cast&lt;char*&gt;(errBuff-&gt;GetBufferPointer())
                      };
                      errBuff-&gt;Release();
                  }
  
                  return false;
              }
  
              if (errBuff)
                  errBuff-&gt;Release();
  
              hr = dxdata.device-&gt;CreateVertexShader(
                  m_Code-&gt;GetBufferPointer(),
                  m_Code-&gt;GetBufferSize(),
                  0,
                  &amp;m_Shader
              );
              if (FAILED(hr))
              {
                  if (m_Code)
                      m_Code-&gt;Release();
  
                  return false;
              }
  
              dxdata.context-&gt;VSSetShader(
                  m_Shader,
                  nullptr,
                  0
              );
  
              return true;
          }
          void destroyShader() override
          {
              if (m_Shader)
                  m_Shader-&gt;Release();
  
              if (m_Code)
                  m_Code-&gt;Release();
          }
  
          const char* getShaderCode()
          {
              return static_cast&lt;char*&gt;(m_Code-&gt;GetBufferPointer());
          }
          size_t getShaderCodeSize()
          {
              return m_Code-&gt;GetBufferSize();
          }
  
          void* getShader() override
          {
              return m_Shader;
          }
      };
  
      template&lt;&gt;
      class DxGraphicsShader&lt;ID3D11PixelShader&gt; final : public GraphicsShader
      {
          ID3DBlob* m_Code;
          ID3D11PixelShader* m_Shader;
  
      public:
          bool createShader(const GraphicsShaderData&amp; data) override
          {
              const DxGraphicsShaderData&amp; dxdata = static_cast&lt;const DxGraphicsShaderData&amp;&gt;(data);
  
              int flags = D3DCOMPILE_ENABLE_STRICTNESS;
  #ifdef _DEBUG
              flags |= D3DCOMPILE_DEBUG;
  #endif // _DEBUG
              HRESULT hr;
              ID3DBlob* errBuff;
  
              hr = D3DCompileFromFile(
                  std::wstring_convert&lt;std::codecvt_utf8_utf16&lt;wchar_t&gt;&gt;().from_bytes(
                      &quot;pixel.hlsl&quot; // TODO: fix with resource manager
                  ).c_str(),
                  nullptr,
                  nullptr,
                  &quot;PMain&quot;,
                  &quot;ps_5_0&quot;,
                  flags,
                  0,
                  &amp;m_Code,
                  &amp;errBuff
              );
  
              if (FAILED(hr))
              {
                  if (errBuff)
                  {
                      *dxdata.logger &lt;&lt; logger::Message{
                          .type = logger::Message::Type::CLIENT,
                          .severity = logger::Message::Severity::ERR,
                          .data = static_cast&lt;char*&gt;(errBuff-&gt;GetBufferPointer())
                      };
                      errBuff-&gt;Release();
                  }
  
                  return false;
              }
  
              if (errBuff)
                  errBuff-&gt;Release();
  
              hr = dxdata.device-&gt;CreatePixelShader(
                  m_Code-&gt;GetBufferPointer(),
                  m_Code-&gt;GetBufferSize(),
                  0,
                  &amp;m_Shader
              );
              if (FAILED(hr))
              {
                  if (m_Code)
                      m_Code-&gt;Release();
  
                  return false;
              }
  
              dxdata.context-&gt;PSSetShader(
                  m_Shader,
                  nullptr,
                  0
              );
  
              return true;
          }
          void destroyShader() override
          {
              if (m_Shader)
                  m_Shader-&gt;Release();
  
              if (m_Code)
                  m_Code-&gt;Release();
          }
  
          const char* getShaderCode()
          {
              return static_cast&lt;char*&gt;(m_Code-&gt;GetBufferPointer());
          }
          size_t getShaderCodeSize()
          {
              return m_Code-&gt;GetBufferSize();
          }
  
          void* getShader() override
          {
              return m_Shader;
          }
      };
  #endif // _WIN32
  }
  </code></pre>
  <p>This is just a template before abstraction, it has a hardware based renderer, and a default rasterizer for later specification</p>
  <p>I have already checked the memory data of the vertex buffer in gpu memory and it does indeed contain data, i get no errors from function outputs, and have tried flipping the order of triangle vertexes in source.</p>