Rysowanie trójkąta - DirectX 10

0

Witam.
Ostatnio zacząłem (w ramach ćwiczeń) przerabiać sample z DirectX SDK i napotkałem problem z rysowaniem trójkąta.
Jeżeli mógłby ktoś (jeżeli to nie problem) to tu wstawiam cały kod https://github.com/HawkDeath/DirectX10-Framework---Shader.git .
Może problem wynika jednak z samej klasy dlatego też podrzucam całą klasę. :)

//Polygon.h
#include <D3D10.h>
#include <D3DX10.h>

#include <string>

struct Vertex
{
	D3DXVECTOR3 position;
};

namespace hd
{
	class Polygon
	{
	public:
		Polygon();
		~Polygon();


		void loadShader(ID3D10Device *device, std::string filename);
		void draw(ID3D10Device *device, IDXGISwapChain* swch);

	private:

		ID3D10Effect*           m_pEffect;
		ID3D10EffectTechnique*  m_pTechnique;
		ID3D10InputLayout*      m_pVertexLayout;
		ID3D10Buffer*           m_pVertexBuffer;
	};
};

//Polygon.cpp

#include "Polygon.h"

#include "App.h"

using namespace hd;

Polygon::Polygon() : m_pEffect(nullptr), m_pTechnique(nullptr), m_pVertexLayout(nullptr), m_pVertexBuffer(nullptr)
{
}

Polygon::~Polygon()
{
	if (m_pVertexBuffer) m_pVertexBuffer->Release();
	if (m_pVertexLayout) m_pVertexLayout->Release();
	if (m_pEffect) m_pEffect->Release();
}


void Polygon::loadShader(ID3D10Device *device, std::string filename)
{
	HRESULT hr;

	//create effect
	DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
	dwShaderFlags |= D3D10_SHADER_DEBUG;
#endif

	hr = D3DX10CreateEffectFromFileA(filename.c_str(), nullptr, nullptr, "fx_4_0", dwShaderFlags, 0, device, nullptr, nullptr, &m_pEffect, nullptr, nullptr);
	if (FAILED(hr))
	{
		App::Message("The FX file cannot be located. Please run this executable from the directory that contains the FX file.");
		return;
	}
	m_pTechnique = m_pEffect->GetTechniqueByName("Render");

	//define input layout
	D3D10_INPUT_ELEMENT_DESC layout[] = 
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
	};

	UINT numElements = sizeof(layout) / sizeof(layout[0]);

	// Create the input layout
	D3D10_PASS_DESC PassDesc;
	m_pTechnique->GetPassByIndex(0)->GetDesc(&PassDesc);
	hr = device->CreateInputLayout(layout, numElements, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &m_pVertexLayout);
	if (FAILED(hr))
	{
		App::Message("Input layout cannot be create.");
		return;
	}
	// Set the input layout
	device->IASetInputLayout(m_pVertexLayout);

	Vertex mpVertex[] =
	{
		D3DXVECTOR3(0.0f, 0.5f, 0.5f),
		D3DXVECTOR3(0.5f, -0.5f, 0.5f),
		D3DXVECTOR3(-0.5f, -0.5f, 0.5f),
	};

	D3D10_BUFFER_DESC bd;
	bd.Usage = D3D10_USAGE_DEFAULT;
	bd.ByteWidth = sizeof(Vertex) * 3;
	bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
	bd.CPUAccessFlags = 0;
	bd.MiscFlags = 0;
	D3D10_SUBRESOURCE_DATA InitData;
	InitData.pSysMem = mpVertex;

	hr = device->CreateBuffer(&bd, &InitData, &m_pVertexBuffer);
	if (FAILED(hr))
	{
		App::Message("Buffer cannot be create.");
		return;
	}

	// Set vertex buffer
	UINT stride = sizeof(Vertex);
	UINT offset = 0;
	device->IASetVertexBuffers(0, 1, &m_pVertexBuffer, &stride, &offset);

	// Set primitive topology
	device->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
	return;
}

void Polygon::draw(ID3D10Device *device, IDXGISwapChain* swch)
{
	D3D10_TECHNIQUE_DESC techDesc;
	m_pTechnique->GetDesc(&techDesc);

	for (UINT p = 0; p < techDesc.Passes; ++p)
	{
		m_pTechnique->GetPassByIndex(p)->Apply(0);
		device->Draw(3, 0);
	}
	swch->Present(0, 0);
}

 
0

Fajnie.
Jakie jest pytanie?

0

W gruncie rzeczy to dlaczego nie działa. :)

0

A co to znaczy, że nie działa?

0

Powinienem uzyskać taki rezultat
user image
No i niestety jest bez tego żółtego trójkąta. :( I nie wiem w którym miejscu popełniłem błąd w kodzie.

1

Ale że jaki rezultat otrzymujesz?
Czarny ekran?
Ciemnoniebieski ekran?
Czarny ekran i kontury?
Ciemnoniebieski ekran i kontury?
Zielony trójkąt?
Brak czegokolwiek?

2

Spróbuj zmienić input layout format na DXGI_FORMAT_R32G32B32_FLOAT.

Tak na boku, dlaczego uczysz się DX10? Nawet jeśli Twoja karta nie obsługuje DX11 to nadal jesteś w stanie go używać (bez featurów DX11). Generalnie warto zawsze się uczyć najnowszych api.

1 użytkowników online, w tym zalogowanych: 0, gości: 1