Alright, well here's where I'm at. This is a picture of me making simple block in the map maker GTKRadiant:
https://drive.google.com/open?id=16HVyFVXzbqPNuaWtyWIE9QkFaDmj15fO
and as a result from d3d11DevCon->Draw(24, 0); I get what you see in the dead center, and as a result of d3d11DevCon->DrawIndexed( bsp.m_nNumMeshIndices, 0, 0 ); I get what you see in the top right:
https://drive.google.com/open?id=10UufSF7gNrRJgnwmd6c-5SXYkx4gCTA1
and this is the code:
//Include and link appropriate libraries and headers//
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "d3dx11.lib")
#pragma comment(lib, "d3dx10.lib")
#include <windows.h>
#include <d3d11.h>
#include <d3dx11.h>
#include <d3dx10.h>
#include <xnamath.h>
#include "bspread.h"
//Global Declarations - Interfaces//
IDXGISwapChain* SwapChain;
ID3D11Device* d3d11Device;
ID3D11DeviceContext* d3d11DevCon;
ID3D11RenderTargetView* renderTargetView;
ID3D11Buffer* squareIndexBuffer;
ID3D11DepthStencilView* depthStencilView;
ID3D11Texture2D* depthStencilBuffer;
ID3D11Buffer* squareVertBuffer;
ID3D11VertexShader* VS;
ID3D11PixelShader* PS;
ID3D10Blob* VS_Buffer;
ID3D10Blob* PS_Buffer;
ID3D11InputLayout* vertLayout;
ID3D11Buffer* cbPerObjectBuffer;
///////////////**************new**************////////////////////
ID3D11ShaderResourceView* CubesTexture;
ID3D11SamplerState* CubesTexSamplerState;
///////////////**************new**************////////////////////
////////////////
//BSP
////////////////
CBSP bsp("dxtest.bsp");
struct stBSPVertex
{
D3DXVECTOR3 p; // Position Vertice
D3DXVECTOR3 n; // Vertice Normal
DWORD colour; // ARGB
float tu1, tv1; // Texture Coordinates
float lu2, lv2; // Light Tex Coords
};
int m_nNumVerts = bsp.m_nNumVerts;
stBSPVertex pVB[100000];
int m_nNumFaces = 0;
int m_nNumMeshIndices = 0;
int m_nNumTextures = 0;
int m_nNumNodes = 0;
int m_nNumLeafs = 0;
int m_nNumPlanes = 0;
int m_nNumLeafFaces = 0;
int m_nNumVisData = 0;
int m_nNumTrisDraw = 0;
int m_nNumBrushes = 0;
int m_nNumBrushSides = 0;
int m_nNumLeafBrushes = 0;
// Always initialise pointers to NULL
stFace *m_pFaces = NULL;
stVertex* m_pVerts = NULL;
int *m_pMeshIndices = NULL;
//m_pTextures = NULL;
stNode *m_pNodes = NULL;
//m_pLeafs = NULL;
//m_pPlanes = NULL;
//m_pLeafFaces = NULL;
//m_VisData.pBits = NULL;
//m_pBrushes = NULL;
//m_pBrushSides = NULL;
//m_pLeafBrushes = NULL;
void GetBSPData(void)
{
//pVB = new stBSPVertex;
m_nNumVerts = bsp.verts();
//m_nNumFaces = bsp.m_nNumFaces;
m_nNumMeshIndices = bsp.indices();
m_nNumTextures = 0;
m_nNumNodes = 0;
m_nNumLeafs = 0;
m_nNumPlanes = 0;
m_nNumLeafFaces = 0;
m_nNumVisData = 0;
m_nNumTrisDraw = 0;
m_nNumBrushes = 0;
m_nNumBrushSides = 0;
m_nNumLeafBrushes = 0;
// Always initialise pointers to NULL
m_pFaces = NULL;
stVertex* m_pVerts = bsp.pVerts();
m_pMeshIndices = bsp.pIndices();
/*m_pTextures = NULL;
m_pNodes = NULL;
m_pLeafs = NULL;
m_pPlanes = NULL;
m_pLeafFaces = NULL;
m_VisData.pBits = NULL;
m_pBrushes = NULL;
m_pBrushSides = NULL;
m_pLeafBrushes = NULL;*/
for (static int i = 0; i < m_nNumVerts; i++)
{
// The put the y ans z the wrong way around!
pVB[i].p.x = m_pVerts[i].vPoint[0];
pVB[i].p.y = m_pVerts[i].vPoint[1];
pVB[i].p.z = m_pVerts[i].vPoint[2];
// tv is inverted!
pVB[i].tu1 = m_pVerts[i].Tex[0];
pVB[i].tv1 = m_pVerts[i].Tex[1];
pVB[i].lu2 = m_pVerts[i].LightTexCoord[0];
pVB[i].lv2 = m_pVerts[i].LightTexCoord[1];
pVB[i].n.x = m_pVerts[i].vNormal[0];
pVB[i].n.y = m_pVerts[i].vNormal[1];
pVB[i].n.z = m_pVerts[i].vNormal[2];
// Alpha hack - so our alpha value isn't 100% anymore
//pVB[i].colour = 0x10ffffff & bsp.m_pVerts->RGBA; // ARGB
}
//bsp.~bsp();
}
//Global Declarations - Others//
LPCTSTR WndClassName = L"firstwindow";
HWND hwnd = NULL;
HRESULT hr;
const int Width = 1024;
const int Height = 768;
XMMATRIX WVP;
XMMATRIX cube1World;
XMMATRIX cube2World;
XMMATRIX camView;
XMMATRIX camProjection;
XMVECTOR camPosition;
XMVECTOR camTarget;
XMVECTOR camUp;
XMMATRIX Rotation;
XMMATRIX Scale;
XMMATRIX Translation;
float rot = 0.01f;
//Function Prototypes//
bool InitializeDirect3d11App(HINSTANCE hInstance);
void CleanUp();
bool InitScene();
void UpdateScene();
void DrawScene();
bool InitializeWindow(HINSTANCE hInstance,
int ShowWnd,
int width, int height,
bool windowed);
int messageloop();
LRESULT CALLBACK WndProc(HWND hWnd,
UINT msg,
WPARAM wParam,
LPARAM lParam);
//Create effects constant buffer's structure//
struct cbPerObject
{
XMMATRIX WVP;
};
cbPerObject cbPerObj;
///////////////**************new**************////////////////////
//Vertex Structure and Vertex Layout (Input Layout)//
struct Vertex //Overloaded Vertex Structure
{
Vertex(){}
Vertex(float x, float y, float z,
float u, float v)
: pos(x,y,z), texCoord(u, v){}
XMFLOAT3 pos;
XMFLOAT2 texCoord;
};
//Above was the original Vertex struct that the tutorial used to draw two cubes, I'm using stBSPVertex to read the BSP map
D3D11_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
UINT numElements = ARRAYSIZE(layout);
///////////////**************new**************////////////////////
int WINAPI WinMain(HINSTANCE hInstance, //Main windows function
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
GetBSPData();
if(!InitializeWindow(hInstance, nShowCmd, Width, Height, true))
{
MessageBox(0, L"Window Initialization - Failed",
L"Error", MB_OK);
return 0;
}
if(!InitializeDirect3d11App(hInstance)) //Initialize Direct3D
{
MessageBox(0, L"Direct3D Initialization - Failed",
L"Error", MB_OK);
return 0;
}
if(!InitScene()) //Initialize our scene
{
MessageBox(0, L"Scene Initialization - Failed",
L"Error", MB_OK);
return 0;
}
messageloop();
CleanUp();
return 0;
}
bool InitializeWindow(HINSTANCE hInstance,
int ShowWnd,
int width, int height,
bool windowed)
{
typedef struct _WNDCLASS {
UINT cbSize;
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HANDLE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
} WNDCLASS;
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = NULL;
wc.cbWndExtra = NULL;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 2);
wc.lpszMenuName = NULL;
wc.lpszClassName = WndClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if (!RegisterClassEx(&wc))
{
MessageBox(NULL, L"Error registering class",
L"Error", MB_OK | MB_ICONERROR);
return 1;
}
hwnd = CreateWindowEx(
NULL,
WndClassName,
L"Lesson 4 - Begin Drawing",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
width, height,
NULL,
NULL,
hInstance,
NULL
);
if (!hwnd)
{
MessageBox(NULL, L"Error creating window",
L"Error", MB_OK | MB_ICONERROR);
return 1;
}
ShowWindow(hwnd, ShowWnd);
UpdateWindow(hwnd);
return true;
}
bool InitializeDirect3d11App(HINSTANCE hInstance)
{
//Describe our SwapChain Buffer
DXGI_MODE_DESC bufferDesc;
ZeroMemory(&bufferDesc, sizeof(DXGI_MODE_DESC));
bufferDesc.Width = Width;
bufferDesc.Height = Height;
bufferDesc.RefreshRate.Numerator = 60;
bufferDesc.RefreshRate.Denominator = 1;
bufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
bufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
bufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
//Describe our SwapChain
DXGI_SWAP_CHAIN_DESC swapChainDesc;
ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
swapChainDesc.BufferDesc = bufferDesc;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.BufferCount = 1;
swapChainDesc.OutputWindow = hwnd;
swapChainDesc.Windowed = TRUE;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
//Create our SwapChain
hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL,
D3D11_SDK_VERSION, &swapChainDesc, &SwapChain, &d3d11Device, NULL, &d3d11DevCon);
//Create our BackBuffer
ID3D11Texture2D* BackBuffer;
hr = SwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), (void**)&BackBuffer );
//Create our Render Target
hr = d3d11Device->CreateRenderTargetView( BackBuffer, NULL, &renderTargetView );
BackBuffer->Release();
//Describe our Depth/Stencil Buffer
D3D11_TEXTURE2D_DESC depthStencilDesc;
depthStencilDesc.Width = Width;
depthStencilDesc.Height = Height;
depthStencilDesc.MipLevels = 1;
depthStencilDesc.ArraySize = 1;
depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthStencilDesc.SampleDesc.Count = 1;
depthStencilDesc.SampleDesc.Quality = 0;
depthStencilDesc.Usage = D3D11_USAGE_DEFAULT;
depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
depthStencilDesc.CPUAccessFlags = 0;
depthStencilDesc.MiscFlags = 0;
//Create the Depth/Stencil View
d3d11Device->CreateTexture2D(&depthStencilDesc, NULL, &depthStencilBuffer);
d3d11Device->CreateDepthStencilView(depthStencilBuffer, NULL, &depthStencilView);
//Set our Render Target
d3d11DevCon->OMSetRenderTargets( 1, &renderTargetView, depthStencilView );
return true;
}
void CleanUp()
{
//Release the COM Objects we created
SwapChain->Release();
d3d11Device->Release();
d3d11DevCon->Release();
renderTargetView->Release();
squareVertBuffer->Release();
squareIndexBuffer->Release();
VS->Release();
PS->Release();
VS_Buffer->Release();
PS_Buffer->Release();
vertLayout->Release();
depthStencilView->Release();
depthStencilBuffer->Release();
cbPerObjectBuffer->Release();
}
bool InitScene()
{
//Compile Shaders from shader file
hr = D3DX11CompileFromFile(L"Effects.fx", 0, 0, "VS", "vs_4_0", 0, 0, 0, &VS_Buffer, 0, 0);
hr = D3DX11CompileFromFile(L"Effects.fx", 0, 0, "PS", "ps_4_0", 0, 0, 0, &PS_Buffer, 0, 0);
//Create the Shader Objects
hr = d3d11Device->CreateVertexShader(VS_Buffer->GetBufferPointer(), VS_Buffer->GetBufferSize(), NULL, &VS);
hr = d3d11Device->CreatePixelShader(PS_Buffer->GetBufferPointer(), PS_Buffer->GetBufferSize(), NULL, &PS);
//Set Vertex and Pixel Shaders
d3d11DevCon->VSSetShader(VS, 0, 0);
d3d11DevCon->PSSetShader(PS, 0, 0);
///////////////**************new**************////////////////////
//Create the vertex buffer
Vertex v[] =
{
// Front Face
Vertex(pVB[0].p.x, pVB[0].p.y, pVB[0].p.z, pVB[0].tu1, pVB[0].tv1),
Vertex(pVB[1].p.x, pVB[1].p.y, pVB[1].p.z, pVB[1].tu1, pVB[1].tv1),
Vertex(pVB[2].p.x, pVB[2].p.y, pVB[2].p.z, pVB[2].tu1, pVB[2].tv1),
Vertex(pVB[3].p.x, pVB[3].p.y, pVB[3].p.z, pVB[3].tu1, pVB[3].tv1),
// Back Face
Vertex(pVB[4].p.x, pVB[4].p.y, pVB[4].p.z, pVB[4].tu1, pVB[4].tv1),
Vertex(pVB[5].p.x, pVB[5].p.y, pVB[5].p.z, pVB[5].tu1, pVB[5].tv1),
Vertex(pVB[6].p.x, pVB[6].p.y, pVB[6].p.z, pVB[6].tu1, pVB[6].tv1),
Vertex(pVB[7].p.x, pVB[7].p.y, pVB[7].p.z, pVB[7].tu1, pVB[7].tv1),
// Top Face
Vertex(pVB[8].p.x, pVB[8].p.y, pVB[8].p.z, pVB[8].tu1, pVB[8].tv1),
Vertex(pVB[9].p.x, pVB[9].p.y, pVB[9].p.z, pVB[9].tu1, pVB[9].tv1),
Vertex(pVB[10].p.x, pVB[10].p.y, pVB[10].p.z, pVB[10].tu1, pVB[10].tv1),
Vertex(pVB[11].p.x, pVB[11].p.y, pVB[11].p.z, pVB[11].tu1, pVB[11].tv1),
// Bottom Face
Vertex(pVB[12].p.x, pVB[12].p.y, pVB[12].p.z, pVB[12].tu1, pVB[12].tv1),
Vertex(pVB[13].p.x, pVB[13].p.y, pVB[13].p.z, pVB[13].tu1, pVB[13].tv1),
Vertex(pVB[14].p.x, pVB[14].p.y, pVB[14].p.z, pVB[14].tu1, pVB[14].tv1),
Vertex(pVB[15].p.x, pVB[15].p.y, pVB[15].p.z, pVB[15].tu1, pVB[15].tv1),
// Left Face
Vertex(pVB[16].p.x, pVB[16].p.y, pVB[16].p.z, pVB[16].tu1, pVB[16].tv1),
Vertex(pVB[17].p.x, pVB[17].p.y, pVB[17].p.z, pVB[17].tu1, pVB[17].tv1),
Vertex(pVB[18].p.x, pVB[18].p.y, pVB[18].p.z, pVB[18].tu1, pVB[18].tv1),
Vertex(pVB[19].p.x, pVB[19].p.y, pVB[19].p.z, pVB[19].tu1, pVB[19].tv1),
// Right Face
Vertex(pVB[20].p.x, pVB[20].p.y, pVB[20].p.z, pVB[20].tu1, pVB[20].tv1),
Vertex(pVB[21].p.x, pVB[21].p.y, pVB[21].p.z, pVB[21].tu1, pVB[21].tv1),
Vertex(pVB[22].p.x, pVB[22].p.y, pVB[22].p.z, pVB[22].tu1, pVB[22].tv1),
Vertex(pVB[23].p.x, pVB[23].p.y, pVB[23].p.z, pVB[23].tu1, pVB[23].tv1),
Vertex(pVB[24].p.x, pVB[24].p.y, pVB[24].p.z, pVB[24].tu1, pVB[24].tv1),
Vertex(pVB[25].p.x, pVB[25].p.y, pVB[25].p.z, pVB[25].tu1, pVB[25].tv1),
Vertex(pVB[26].p.x, pVB[26].p.y, pVB[26].p.z, pVB[26].tu1, pVB[26].tv1),
Vertex(pVB[27].p.x, pVB[27].p.y, pVB[27].p.z, pVB[27].tu1, pVB[27].tv1),
Vertex(pVB[28].p.x, pVB[28].p.y, pVB[28].p.z, pVB[28].tu1, pVB[28].tv1),
Vertex(pVB[29].p.x, pVB[29].p.y, pVB[29].p.z, pVB[29].tu1, pVB[29].tv1),
Vertex(pVB[30].p.x, pVB[30].p.y, pVB[30].p.z, pVB[30].tu1, pVB[30].tv1),
Vertex(pVB[31].p.x, pVB[31].p.y, pVB[31].p.z, pVB[31].tu1, pVB[31].tv1),
Vertex(pVB[32].p.x, pVB[32].p.y, pVB[32].p.z, pVB[32].tu1, pVB[32].tv1),
Vertex(pVB[33].p.x, pVB[33].p.y, pVB[33].p.z, pVB[33].tu1, pVB[33].tv1),
Vertex(pVB[34].p.x, pVB[34].p.y, pVB[34].p.z, pVB[34].tu1, pVB[34].tv1),
Vertex(pVB[35].p.x, pVB[35].p.y, pVB[35].p.z, pVB[35].tu1, pVB[35].tv1),
Vertex(pVB[36].p.x, pVB[36].p.y, pVB[36].p.z, pVB[36].tu1, pVB[36].tv1),
Vertex(pVB[37].p.x, pVB[37].p.y, pVB[37].p.z, pVB[37].tu1, pVB[37].tv1),
Vertex(pVB[38].p.x, pVB[38].p.y, pVB[38].p.z, pVB[38].tu1, pVB[38].tv1),
Vertex(pVB[39].p.x, pVB[39].p.y, pVB[39].p.z, pVB[39].tu1, pVB[39].tv1),
Vertex(pVB[40].p.x, pVB[40].p.y, pVB[40].p.z, pVB[40].tu1, pVB[40].tv1),
// Vertex(pVB[41].p.x, pVB[41].p.y, pVB[41].p.z, pVB[41].tu1, pVB[41].tv1),
};
DWORD indices[] = {
// Front Face
bsp.m_pMeshIndices[0], bsp.m_pMeshIndices[1], bsp.m_pMeshIndices[2],
bsp.m_pMeshIndices[3], bsp.m_pMeshIndices[4], bsp.m_pMeshIndices[5],
// Back Face
bsp.m_pMeshIndices[6], bsp.m_pMeshIndices[7], bsp.m_pMeshIndices[8],
bsp.m_pMeshIndices[9], bsp.m_pMeshIndices[10], bsp.m_pMeshIndices[11],
// Top Face
bsp.m_pMeshIndices[12], bsp.m_pMeshIndices[13], bsp.m_pMeshIndices[14],
bsp.m_pMeshIndices[15], bsp.m_pMeshIndices[16], bsp.m_pMeshIndices[17],
// Bottom Face
bsp.m_pMeshIndices[18], bsp.m_pMeshIndices[19], bsp.m_pMeshIndices[20],
bsp.m_pMeshIndices[21], bsp.m_pMeshIndices[22], bsp.m_pMeshIndices[23],
// Left Face
bsp.m_pMeshIndices[24], bsp.m_pMeshIndices[25], bsp.m_pMeshIndices[26],
bsp.m_pMeshIndices[27], bsp.m_pMeshIndices[28], bsp.m_pMeshIndices[29],
// Right Face
bsp.m_pMeshIndices[30], bsp.m_pMeshIndices[31], bsp.m_pMeshIndices[32],
bsp.m_pMeshIndices[33], bsp.m_pMeshIndices[34], bsp.m_pMeshIndices[35],
bsp.m_pMeshIndices[36], bsp.m_pMeshIndices[37], bsp.m_pMeshIndices[38],
bsp.m_pMeshIndices[39], bsp.m_pMeshIndices[40], bsp.m_pMeshIndices[41],
bsp.m_pMeshIndices[42], bsp.m_pMeshIndices[43], bsp.m_pMeshIndices[44],
bsp.m_pMeshIndices[45], bsp.m_pMeshIndices[46], bsp.m_pMeshIndices[47],
bsp.m_pMeshIndices[48], bsp.m_pMeshIndices[49], bsp.m_pMeshIndices[50],
bsp.m_pMeshIndices[51], bsp.m_pMeshIndices[52], bsp.m_pMeshIndices[53],
bsp.m_pMeshIndices[52], bsp.m_pMeshIndices[53], bsp.m_pMeshIndices[54],
bsp.m_pMeshIndices[55], bsp.m_pMeshIndices[56], bsp.m_pMeshIndices[57],
bsp.m_pMeshIndices[58], bsp.m_pMeshIndices[59], bsp.m_pMeshIndices[60],
};
D3D11_BUFFER_DESC indexBufferDesc;
ZeroMemory(&indexBufferDesc, sizeof(indexBufferDesc));
indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
indexBufferDesc.ByteWidth = sizeof(WORD)* bsp.m_nNumMeshIndices;
indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
indexBufferDesc.CPUAccessFlags = 0;
indexBufferDesc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA iinitData;
iinitData.pSysMem = indices;
d3d11Device->CreateBuffer(&indexBufferDesc, &iinitData, &squareIndexBuffer);
d3d11DevCon->IASetIndexBuffer(squareIndexBuffer, DXGI_FORMAT_R32_UINT, 0);
D3D11_BUFFER_DESC vertexBufferDesc;
ZeroMemory(&vertexBufferDesc, sizeof(vertexBufferDesc));
vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
vertexBufferDesc.ByteWidth = sizeof(Vertex)* bsp.m_nNumVerts;
vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vertexBufferDesc.CPUAccessFlags = 0;
vertexBufferDesc.MiscFlags = 0;
char buf[100];
sprintf(buf, "%d", bsp.m_nNumVerts);
MessageBoxA(NULL, buf, buf, MB_OK);
///////////////**************new**************////////////////////
D3D11_SUBRESOURCE_DATA vertexBufferData;
ZeroMemory( &vertexBufferData, sizeof(vertexBufferData) );
vertexBufferData.pSysMem = v;
//hr = d3d11Device->CreateBuffer( &vertexBufferDesc, &vertexBufferData, &squareVertBuffer);
hr = d3d11Device->CreateBuffer(&vertexBufferDesc, &vertexBufferData, &squareVertBuffer);
//Set the vertex buffer
UINT stride = sizeof(Vertex);
UINT offset = 0;
d3d11DevCon->IASetVertexBuffers( 0, 1, &squareVertBuffer, &stride, &offset );
//Create the Input Layout
hr = d3d11Device->CreateInputLayout( layout, numElements, VS_Buffer->GetBufferPointer(),
VS_Buffer->GetBufferSize(), &vertLayout );
//Set the Input Layout
d3d11DevCon->IASetInputLayout( vertLayout );
//Set Primitive Topology
d3d11DevCon->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
//Create the Viewport
D3D11_VIEWPORT viewport;
ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = Width;
viewport.Height = Height;
viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f;
//Set the Viewport
d3d11DevCon->RSSetViewports(1, &viewport);
//Create the buffer to send to the cbuffer in effect file
D3D11_BUFFER_DESC cbbd;
ZeroMemory(&cbbd, sizeof(D3D11_BUFFER_DESC));
cbbd.Usage = D3D11_USAGE_DEFAULT;
cbbd.ByteWidth = sizeof(cbPerObject);
cbbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
cbbd.CPUAccessFlags = 0;
cbbd.MiscFlags = 0;
hr = d3d11Device->CreateBuffer(&cbbd, NULL, &cbPerObjectBuffer);
//Camera information
camPosition = XMVectorSet( 0.0f, 350.0f, -8.0f, 0.0f );
camTarget = XMVectorSet( 0.0f, 0.0f, 0.0f, 0.0f );
camUp = XMVectorSet( 0.0f, 0.0f, 1.0f, 0.0f );
//Set the View matrix
camView = XMMatrixLookAtLH( camPosition, camTarget, camUp );
//Set the Projection matrix
camProjection = XMMatrixPerspectiveFovLH( 0.4f*3.14f, Width/Height, 1.0f, 1000.0f);
///////////////**************new**************////////////////////
// strcat(bsp.m_pTextures[0].Name, ".jpg");
hr = D3DX11CreateShaderResourceViewFromFile(d3d11Device, L"textures\\gothic_floor\\largeblockfloor3.jpg",
NULL, NULL, &CubesTexture, NULL );
//if (hr != S_OK)
// MessageBoxA(NULL, "Something went wrong reading the texture", (LPCSTR)bsp.m_pTextures[0].Name, MB_OK);
// Describe the Sample State
D3D11_SAMPLER_DESC sampDesc;
ZeroMemory( &sampDesc, sizeof(sampDesc) );
sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
sampDesc.MinLOD = 0;
sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
//Create the Sample State
hr = d3d11Device->CreateSamplerState( &sampDesc, &CubesTexSamplerState );
///////////////**************new**************////////////////////
return true;
}
void UpdateScene()
{
//Keep the cubes rotating
rot += .0005f;
if(rot > 6.26f)
rot = 0.0f;
//Reset cube1World
cube1World = XMMatrixIdentity();
//Define cube1's world space matrix
XMVECTOR rotaxis = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
Rotation = XMMatrixRotationAxis( rotaxis, rot);
Translation = XMMatrixTranslation( -5.0f, 0.0f, 4.0f );
//Set cube1's world space using the transformations
cube1World = Translation * Rotation;
//Reset cube2World
cube2World = XMMatrixIdentity();
//Define cube2's world space matrix
Rotation = XMMatrixRotationAxis( rotaxis, -rot);
Scale = XMMatrixScaling( 1.3f, 1.3f, 1.3f );
//Set cube2's world space matrix
cube2World = Rotation * Scale;
}
void DrawScene()
{
//Clear our backbuffer
float bgColor[4] = {(0.0f, 0.0f, 0.0f, 0.0f)};
d3d11DevCon->ClearRenderTargetView(renderTargetView, bgColor);
//Refresh the Depth/Stencil view
d3d11DevCon->ClearDepthStencilView(depthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);
//Set the WVP matrix and send it to the constant buffer in effect file
WVP = cube1World * camView * camProjection;
cbPerObj.WVP = XMMatrixTranspose(WVP);
d3d11DevCon->UpdateSubresource( cbPerObjectBuffer, 0, NULL, &cbPerObj, 0, 0 );
d3d11DevCon->VSSetConstantBuffers( 0, 1, &cbPerObjectBuffer );
///////////////**************new**************////////////////////
d3d11DevCon->PSSetShaderResources( 0, 1, &CubesTexture );
d3d11DevCon->PSSetSamplers( 0, 1, &CubesTexSamplerState );
///////////////**************new**************////////////////////
//Draw the first cube
//d3d11DevCon->DrawIndexed( bsp.m_nNumMeshIndices, 0, 0 );
d3d11DevCon->Draw(24, 0);
WVP = cube2World * camView * camProjection;
cbPerObj.WVP = XMMatrixTranspose(WVP);
d3d11DevCon->UpdateSubresource( cbPerObjectBuffer, 0, NULL, &cbPerObj, 0, 0 );
d3d11DevCon->VSSetConstantBuffers( 0, 1, &cbPerObjectBuffer );
///////////////**************new**************////////////////////
d3d11DevCon->PSSetShaderResources( 0, 1, &CubesTexture );
d3d11DevCon->PSSetSamplers( 0, 1, &CubesTexSamplerState );
///////////////**************new**************////////////////////
//Draw the second cube
d3d11DevCon->DrawIndexed( bsp.m_nNumMeshIndices, 0, 0 );
//Present the backbuffer to the screen
SwapChain->Present(0, 0);
}
int messageloop(){
MSG msg;
ZeroMemory(&msg, sizeof(MSG));
while(true)
{
BOOL PeekMessageL(
LPMSG lpMsg,
HWND hWnd,
UINT wMsgFilterMin,
UINT wMsgFilterMax,
UINT wRemoveMsg
);
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else{
// run game code
UpdateScene();
DrawScene();
}
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam)
{
switch( msg )
{
case WM_KEYDOWN:
if( wParam == VK_ESCAPE ){
DestroyWindow(hwnd);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,
msg,
wParam,
lParam);
}
As you can see the Draw() method that relies solely on the vertex buffer is showing the block much more sucessfully than the one relying on the index buffer. I've made this map several times, with walls/cubes, and the indexed one draws it only to a certain point.
Is it in fact reading the data sucessfully and drawing, could this just be a texture issue of somekind? Maybe the texture isn't being drawn on certain areas and is on others? Or am I screwing this up(well obviously I am) with the filling of the buffers still?
I really need some help here; If I get past this brick wall I can port my entire game engine to DX11, I just need to understand vertex/index buffers in 11 better.
Help!!! Will pay money!! For real! This is like medieval torture! I am trapped in a tower and need rescuing! DAMSEL IN DISTRESS!! CQD SOS CQD HAVE STRUCK BERG CQD SOS THIS IS MYG CQD SOS CQD SOS WATER IS RISING TO THE BOILERS CANNOT HEAR YOU OLD MAN AS A RESULT OF STEAM CQD SOS CQD SOS