Ich versuche gerade mit Direct3D ein Dreieck darzustellen!!!!!!!!!11



  • Leider stürzt das Programm immer ab!!!!!!!!!!!!!!!!!!!!1

    [code]#define WINDOW_CLASS_NAME "freestyle-games"
    #define WIN32_LEAN_AND_MEAN

    #include <windows.h>
    #include <d3d9.h>

    LPDIRECT3D9 lp3D = NULL;
    LPDIRECT3DDEVICE9 lp3DD = NULL;

    IDirect3D9 *Szene;
    IDirect3DDevice9 *Szenegraphik;

    #define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
    #define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

    struct VERTEX
    {
    float x,y,z,rhw;
    DWORD color;
    };
    #define MY_FVF D3DFVF_XYZRHW|D3DFVF_DIFFUSE
    VERTEX verts[]=
    {
    {100.0f,300.0f,0.0f,1.0f,D3DCOLOR_XRGB(255,0,0)},
    {50.0f,500.0f,0.0f,1.0f,D3DCOLOR_XRGB(255,0,0)},
    {50.0f,500.0f,0.0f,1.0f,D3DCOLOR_XRGB(255,0,0)}
    };

    HWND main_window_handle = NULL;
    HINSTANCE hinstance_app = NULL;

    void Init_3D();
    void Render();

    IDirect3DVertexBuffer9 *m_pVertex;
    void Init_Scene();
    void Render2();

    LRESULT CALLBACK WindowProc(HWND hwnd,
    UINT msg,
    WPARAM wparam,
    LPARAM lparam)
    {

    PAINTSTRUCT ps;
    HDC hdc;

    switch(msg)
    {
    case WM_CREATE:
    {
    return(0);
    }
    break;

    case WM_PAINT:
    {
    hdc = BeginPaint(hwnd,&ps);
    EndPaint(hwnd,&ps);
    return(0);
    }
    break;

    case WM_DESTROY:
    {
    PostQuitMessage(0);
    return(0);
    }
    break;

    default:
    break;

    }
    return (DefWindowProc(hwnd, msg, wparam, lparam));

    }

    int WINAPI WinMain( HINSTANCE hinstance,
    HINSTANCE hprevinstance,
    LPSTR lpcmdline,
    int ncmdshow)

    {

    WNDCLASSEX winclass;
    HWND hwnd;
    MSG msg;

    winclass.cbSize = sizeof(WNDCLASSEX);
    winclass.style = CS_HREDRAW | CS_VREDRAW;
    winclass.lpfnWndProc = WindowProc;
    winclass.cbClsExtra = 0;
    winclass.cbWndExtra = 0;
    winclass.hInstance = hinstance;
    winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
    winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    winclass.lpszMenuName = NULL;
    winclass.lpszClassName = WINDOW_CLASS_NAME;
    winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

    hinstance_app = hinstance;

    if (!RegisterClassEx(&winclass))
    return(0);

    if (!(hwnd = CreateWindowEx(NULL,
    WINDOW_CLASS_NAME,
    "freestyle-games",
    WS_OVERLAPPEDWINDOW | WS_VISIBLE,
    0,0,
    1680,1050,
    NULL,
    NULL,
    hinstance,
    NULL)))
    return(0);

    main_window_handle = hwnd;

    Init_3D();
    Init_Scene();
    while(TRUE)
    {

    if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
    {

    if (msg.message == WM_QUIT)
    break;

    TranslateMessage(&msg);
    DispatchMessage(&msg);
    if(KEYDOWN(VK_ESCAPE))
    {
    SendMessage(hwnd,WM_CLOSE,0,0);
    }

    }

    }

    return(msg.wParam);

    }

    void Init_3D()
    {
    lp3D = Direct3DCreate9(D3D_SDK_VERSION);

    D3DPRESENT_PARAMETERS D3DPParams;
    ZeroMemory(&D3DPParams,sizeof(D3DPParams));

    D3DPParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
    D3DPParams.hDeviceWindow = main_window_handle;
    D3DPParams.BackBufferCount = 1;

    D3DPParams.Windowed = FALSE;
    D3DPParams.BackBufferWidth = 1680;
    D3DPParams.BackBufferHeight = 1050;
    D3DPParams.BackBufferFormat = D3DFMT_X8R8G8B8;

    lp3D->CreateDevice(D3DADAPTER_DEFAULT,
    D3DDEVTYPE_HAL,
    main_window_handle,
    D3DCREATE_SOFTWARE_VERTEXPROCESSING,
    &D3DPParams,
    &lp3DD);

    }

    void Render()
    {

    lp3DD->Clear(0,NULL,D3DCLEAR_TARGET,
    D3DCOLOR_XRGB(0,0,255),1.0f,0);

    Render2();
    if(FAILED(lp3DD->Present(NULL,NULL,NULL,NULL)))
    {
    SendMessage(main_window_handle,WM_CLOSE,0,0);
    }
    }

    void Init_Scene()
    {
    VERTEX verts[]=
    {
    {100.0f,300.0f,0.0f,1.0f,D3DCOLOR_XRGB(255,0,0)},
    {50.0f,500.0f,0.0f,1.0f,D3DCOLOR_XRGB(255,0,0)},
    {50.0f,500.0f,0.0f,1.0f,D3DCOLOR_XRGB(255,0,0)}
    };
    Szenegraphik->CreateVertexBuffer(3sizeof(VERTEX),NULL,MY_FVF,D3DPOOL_DEFAULT,&m_pVertex,NULL);
    void
    pVerts;
    m_pVertex->Lock(0,sizeof(verts),(void**)&pVerts,NULL);
    memcpy(pVerts,&verts,sizeof(verts));
    m_pVertex->Unlock();

    }
    void Render2()
    {
    Szenegraphik->BeginScene();
    Szenegraphik->SetStreamSource(0,m_pVertex,0,sizeof(VERTEX));
    Szenegraphik->SetFVF(MY_FVF);
    Szenegraphik->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
    Szenegraphik->EndScene();
    SendMessage(main_window_handle,WM_CLOSE,0,0);
    }



  • Erstmal Codetags richtig verwenden. Riecht verdächtig nach Trollversuch.



  • In der Doku ist es erklaert und es gibt auch genug Beispielcode zum SDK dazu. f'`8k

    Autocogito

    Gruß, TGGC (Was Gamestar sagt...)


Log in to reply