I Have Just Started Learning D3D and my code was working all fine till i implemented the D3D Shader Compiler Stuff to my code.
I am Using the tutorial on DirectXTutorials. if i just copy paste the code from there on to a new project, the program compiles fine.
However i have put my code in different classes unlike the tutorial. It is giving me error when i try to compile my saying: Syntax Error: "TextMetrica" (Compiling Direct3DRenderer.cpp).
Here is the Direct3DRenderer File:
#include "Window.h"
#include "Direct3DRenderer.h"
#include "Vertex.h"
Renderer::Renderer(HWND hw)
{
OutputDebugString("Direct3D Initializing\n");
DXGI_SWAP_CHAIN_DESC scd;
ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC)); // ZERO OUT SCD
scd.BufferCount = 1; // HOW MANY BACKBUFFERS WE WANT
scd.OutputWindow = hw; // HANDLE TO THE OUTPUT WINDOW
scd.Windowed = true; // SHOULD WINDOW BE IN WINDOWED MODE BY DEFAULT
scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // BUFFER FORMAT
scd.BufferDesc.Width = 800; // BUFFER WIDTH
scd.BufferDesc.Height = 600; // BUFFER HEIGHT
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; // USE SWAP CHAIN AS OUTPUT TARGET
scd.SampleDesc.Count = 4; // MSAA COUNT
scd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; // FLAGS
if (D3D11CreateDeviceAndSwapChain(
NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
NULL,
NULL,
NULL,
D3D11_SDK_VERSION,
&scd,
&swapchain,
&dev,
NULL,
&context
) == SEVERITY_SUCCESS)
{
OutputDebugString("SUCCESS\n");
// Get The Address of BackBuffer
ID3D11Texture2D* pbuffer;
swapchain->GetBuffer(0, _uuidof(ID3D11Texture2D), (LPVOID*)& pbuffer);
// Create a Render Target COM Object from the buffer
dev->CreateRenderTargetView(pbuffer, NULL, &RenderTarget);
pbuffer->Release();
// Set Our RenderTarget as the back buffer
context->OMSetRenderTargets(1, &RenderTarget, NULL);
// Create Our Viewport
viewport.Height = 800;
viewport.Width = 600;
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
context->RSSetViewports(1, &viewport);
InitPipeline();
InitGraphics();
}
else
{
OutputDebugString("ERROR\n");
}
}
Renderer::~Renderer()
{
OutputDebugString("Direct3D Cleanup Phase Started.\n");
swapchain->SetFullscreenState(FALSE, NULL);
swapchain->Release();
context->Release();
RenderTarget->Release();
VS->Release();
PS->Release();
dev->Release();
OutputDebugString("Direct3D Cleanup Phase Completed.\n");
}
void Renderer::InitPipeline()
{
// Compile Shaders from file
D3DX11CompileFromFile("shaders.shader", 0, 0, "VShader", "vs_4_0", 0, 0, 0, &compiled_vs, 0, 0);
D3DX11CompileFromFile("shaders.shader", 0, 0, "PShader", "ps_4_0", 0, 0, 0, &compiled_ps, 0, 0);
// Convert Compiled Shaders to COM Shader Objects
dev->CreateVertexShader(compiled_vs->GetBufferPointer(), compiled_vs->GetBufferSize(), NULL, &VS);
dev->CreatePixelShader(compiled_ps->GetBufferPointer(), compiled_ps->GetBufferSize(), NULL, &PS);
// Sets the shaders to the device / Activates the shader
context->VSSetShader(VS, 0, 0);
context->PSSetShader(PS, 0, 0);
// Create the Input Layout
D3D11_INPUT_ELEMENT_DESC VertexElementDesc[] = {
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0}
};
dev->CreateInputLayout(VertexElementDesc, 2, compiled_vs->GetBufferPointer(), compiled_vs->GetBufferSize(), &InputLayout);
context->IASetInputLayout(InputLayout);
}
void Renderer::InitGraphics() {
// Create Buffer so we can duplicate data from system memory to graphics memory
ZeroMemory(&VBufferDesc, sizeof(VBufferDesc));
VBufferDesc.ByteWidth = sizeof(Vertex) * 3;
VBufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
VBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
VBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
dev->CreateBuffer(&VBufferDesc, NULL, &VBuffer);
Vertex OurVertices[] =
{
{0.0f, 0.5f, 0.0f, D3DXCOLOR(1.0f, 0.0f, 0.0f, 1.0f)},
{0.45f, -0.5, 0.0f, D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f)},
{-0.45f, -0.5f, 0.0f, D3DXCOLOR(0.0f, 0.0f, 1.0f, 1.0f)}
};
// we need to map to avoid issues
D3D11_MAPPED_SUBRESOURCE mapRes;
context->Map(VBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &mapRes);
memcpy(mapRes.pData, OurVertices, sizeof(OurVertices));
context->Unmap(VBuffer, NULL);
}
void Renderer::RenderFrame()
{
context->ClearRenderTargetView(RenderTarget, D3DXCOLOR(0.2, 0.4, 0.6, 1.0));
// We can do the rendering here
UINT stride = sizeof(Vertex);
UINT offset = 0;
context->IASetVertexBuffers(0, 1, &VBuffer, &stride, &offset);
context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
context->Draw(3, 0);
// Swap Buffer
swapchain->Present(0, 0);
}
The TEXTMETRICA Identifier error is actually in D3DX10Core.h. i have peeked in the definition and that file seems to be giving me the error. this identifier's definition should be in gdi file.
I have added the include paths and lib paths to the directx(June 2010) SDK and also tried specifying d3dx10.lib, d3dx11.lib, d3d11.lib in the project's addition dependency on the all configurations setting. I am new so i dont know what i am doing wrong. if any more code is required please comment about it.