anfängerregnäfna
Mitglied
Hallo,
ich bin ein Anfänger in der Programmierung mit DirectX und habe gerade mein erstes Programm geschrieben.
Es soll ein einfaches Dreieck darstellen.
Als IDE habe ich CodeBlocks verwendet, die Kompilierung funktionierte problemlos.
Aber bei der Ausführung meldet sich Windows "Dreieck.exe hat ein Problem festgestellt und muss beendet werden".
Die Datei "TriBase.h" bindet eine 3D Engine ein, die in dem Buch, mit dem ich DirectX lerne verwendet wird. Die Klassen tbVector3 und tbColor stammen aus dieser Engine und stellen einfach einen 3DVektor, bzw. eine Farbe dar.
Auch nach eingehender Suche kann ich den Fehler nicht finden,
hier mein Quellcode
Kann mir jemand helfen?
ich bin ein Anfänger in der Programmierung mit DirectX und habe gerade mein erstes Programm geschrieben.
Es soll ein einfaches Dreieck darstellen.
Als IDE habe ich CodeBlocks verwendet, die Kompilierung funktionierte problemlos.
Aber bei der Ausführung meldet sich Windows "Dreieck.exe hat ein Problem festgestellt und muss beendet werden".
Die Datei "TriBase.h" bindet eine 3D Engine ein, die in dem Buch, mit dem ich DirectX lerne verwendet wird. Die Klassen tbVector3 und tbColor stammen aus dieser Engine und stellen einfach einen 3DVektor, bzw. eine Farbe dar.
Auch nach eingehender Suche kann ich den Fehler nicht finden,
hier mein Quellcode
Code:
#include <d3d9.h>
#include<d3dx9.h>
#include <tribase.h>
#include <windows.h>
PDIRECT3D9 g_pd3d=0;
PDIRECT3DDEVICE9 g_pd3ddev=0;
int g_width=1000;
int g_height=1000;
HWND hwnd; /* This is the handle for our window */
MSG messages;
int g_anzdreiecke=1;
struct SVertex
{tbVector3 vPosition;
tbColor dwColor;
};
SVertex g_tv[3];
init(HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow);
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
void initdx();
void Render();
void Move();
int WINAPI WinMain(HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
init(hThisInstance,hPrevInstance,lpszArgument,nCmdShow);
initdx();
g_pd3ddev->SetRenderState(D3DRS_LIGHTING,FALSE);
g_pd3ddev->SetRenderState(D3DRS_SHADEMODE,D3DSHADE_GOURAUD);
g_pd3ddev->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);
g_pd3ddev->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
g_pd3ddev->SetRenderState(D3DRS_ZENABLE,TRUE);
g_pd3ddev->SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE);
g_tv[0].vPosition=tbVector3(1.0f,1.0f,1.0f);
g_tv[1].vPosition=tbVector3(2.0f,1.0f,1.0f);
g_tv[2].vPosition=tbVector3(1.5f,2.0f,1.0f);
g_tv[0].dwColor=tbColor(1.0f,0.0f,0.0f);
g_tv[1].dwColor=tbColor(1.0f,0.0f,0.0f);
g_tv[2].dwColor=tbColor(1.0f,0.0f,0.0f);
while(messages.message!=WM_QUIT){
while(PeekMessage(&messages,NULL,0,0,PM_REMOVE))
{TranslateMessage(&messages);
DispatchMessage(&messages);}
Render();
Move();
}
return 0;
}
init(HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = "szClassName";
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
"szClassName", /* Classname */
"Code::Blocks Template Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
g_width, /* The programs width */
g_height, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
ShowWindow (hwnd, nCmdShow);
return 0;};
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
void Render()
{
g_pd3ddev->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(200,200,200),1.0,(DWORD)0.0f);
g_pd3ddev->BeginScene();
g_pd3ddev->DrawPrimitiveUP(D3DPT_TRIANGLELIST,1,g_tv,sizeof(g_tv));
g_pd3ddev->EndScene();
g_pd3ddev->Present(NULL,NULL,NULL,NULL);
};
void Move(){};
void initdx()
{
g_pd3d=Direct3DCreate9(D3D_SDK_VERSION);
D3DDISPLAYMODE d;
g_pd3d->GetAdapterDisplayMode(0,&d);
D3DPRESENT_PARAMETERS pParam;
ZeroMemory(&pParam,sizeof(pParam));
pParam.BackBufferWidth=d.Width;
pParam.BackBufferHeight=d.Height;
pParam.BackBufferFormat=d.Format;
pParam.BackBufferCount=1;
pParam.MultiSampleType=D3DMULTISAMPLE_NONE;
//pParam.MultiSampleQuality=1;
pParam.SwapEffect=D3DSWAPEFFECT_COPY;
pParam.hDeviceWindow=hwnd;
pParam.Windowed=TRUE;
pParam.EnableAutoDepthStencil=false;
//pParam.Flags=D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
pParam.FullScreen_RefreshRateInHz=d.RefreshRate;
pParam.PresentationInterval=D3DPRESENT_INTERVAL_DEFAULT;
g_pd3d->CreateDevice(0,D3DDEVTYPE_HAL,hwnd,D3DCREATE_MIXED_VERTEXPROCESSING,&pParam,&g_pd3ddev);
};