OK so i am compiling my code and i consistently get these errors and no matter what i do they are there. Here is my code:
Code:
#include <windows.h>
#include <WindowsX.h>
#include <d3d9.h>
#include <d3dx9.h>
#pragma comment (lib, "d3d9.lib")
#define width 800
#define height 600
int r, g, b;
#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
struct CUSTOMVERTEX // Vertices struct
{
FLOAT x, y, z, rhw;
DWORD color;
};
HDC hdc;
RECT rect;
LPDIRECT3D9 d3d = NULL;
LPDIRECT3DDEVICE9 d3ddev = NULL;
LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL;
bool tri = false;
void init_d3d(HWND hwnd);
void render_frame();
void clean_up();
void init_graphics();
void PrintText();
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("HelloWin") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) COLOR_WINDOW ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, // window class name
TEXT ("The Hello Program"), // window caption
WS_OVERLAPPEDWINDOW, // window style
0, // initial x position
0, // initial y position
width, // initial x size
height, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
ShowWindow (hwnd, iCmdShow) ;
init_d3d(hwnd);
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
render_frame();
}
return msg.wParam ;
clean_up();
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_KEYDOWN:
switch(wParam)
{
case VK_SHIFT:
if(r<255-25){
r+=25;
}
else
break;
case VK_HOME:
if(g<255-25){
g+=25;
}
else
break;
case VK_NUMPAD1:
if(b<255 - 25 ){
b+= 25;
}
else
break;
default:
break;
}
return 0;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
void init_d3d(HWND hwnd)
{
d3d = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hwnd;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferWidth = width;
d3dpp.BackBufferHeight = height;
d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
}
void render_frame()
{
d3ddev->Clear(0, 0, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,196,50), 0.0f, NULL);
d3ddev->BeginScene();
init_graphics();
hdc = GetDC(0);
GetClientRect(NULL, &rect);
DrawTextA(hdc, "HELLO", -1, &rect, NULL);
d3ddev->SetFVF(CUSTOMFVF);
d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
d3ddev->EndScene();
d3ddev->Present(NULL, NULL, NULL, NULL);
}
void init_graphics()
{
CUSTOMVERTEX triangle[] =
{
{400.0f, 100.0f, .5f, 1.0f, D3DCOLOR_XRGB(r,g,b), } ,
{650.0f, 200.0f, .5f, 1.0f, D3DCOLOR_XRGB(r,g,b),},
{100.0f, 200.0f, .5f, 1.0f, D3DCOLOR_XRGB(r,g,b),},
};
d3ddev->CreateVertexBuffer(3 * sizeof(CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, 0);
VOID* buffer;
v_buffer->Lock(0,0,&buffer, 0);
memcpy(buffer, triangle, sizeof(triangle));
v_buffer->Unlock();
}
void clean_up()
{
v_buffer->Release();
d3d->Release();
d3ddev->Release();
}