Hi, I am trying to learn to use DirectX and Direct 3d specifically, using various sources. I am working with c++ and I cannot figure out why this c++ code does not work, all I an trying to do is to draw a square. Instead it simply displays a black background with a slightly greenish tone (As its supposed to be).
This should be all relevant parts, thank you for any help.
while (TRUE)
{
RE.CreatePlane();
RE.RenderFrame();
}
void RatEngine::RenderFrame()
{
dxDev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 26, 0), 1.0f, 0);
dxDev->BeginScene();
dxDev->SetFVF(CUSTOMFVF);
// select the vertex buffer to display
dxDev->SetStreamSource(0, dxVB, 0, sizeof(VERTEXSTRUCT));
// copy the vertex buffer to the back buffer
dxDev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
dxDev->EndScene();
dxDev->Present(NULL, NULL, NULL, NULL);
return;
}
void RatEngine::CreatePlane()
{
//Define the plane
struct VERTEXSTRUCT vsPlane[] =
{
{ -3.0f, 3.0f, 0.0f, D3DCOLOR_XRGB(0, 0, 255),},// 1,0,},
{ 3.0f, 3.0f, 0.0f, D3DCOLOR_XRGB(0, 255, 0),},// 0,0,},
{ -3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(255, 0, 0),},// 1,1,},
{ 3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(0, 255, 255),},// 0,1,},
};
//Create the vertex buffer
dxDev->CreateVertexBuffer(4*sizeof(VERTEXSTRUCT),
0,
CUSTOMFVF,
D3DPOOL_MANAGED,
&dxVB,
NULL);
VOID* pVoid;
// lock t_buffer and load the vertices into it
dxVB->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, vsPlane, sizeof(vsPlane));
dxVB->Unlock();
return;
}
This is the top of the ratengine.h file.
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
#include <d3dx9.h>
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")
//Struct prototypes
struct VERTEXSTRUCT { FLOAT x, y, z, rhw; // from the D3DFVF_XYZRHW flag
DWORD color; // from the D3DFVF_DIFFUSE flag
};
struct CURRENTGAMESTATE {bool Menu; bool Game;};
//Definations
#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE) //| D3DFVF_TEX1)
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
// Global Pointers
LPDIRECT3D9 d3d; // D3D interface pointer
LPDIRECT3DDEVICE9 dxDev; // device class pointer
LPDIRECT3DVERTEXBUFFER9 dxVB = NULL; // vertex buffer pointer
// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
]