Ich habe ein Problem bei der 3D Programmierung



  • Ich versuche gerade ein 3D Dreieck darzustellen leider bleibt der Bildschirm blau.

    Falls ihr keinen Fehler entdecken könnt, könnt ihr mir dann bitte einen Funktionierenden code schreiben, fände ich nett.

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

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

    LPDIRECT3D9 lp3D = NULL;
    LPDIRECT3DDEVICE9 lp3DD = NULL;

    #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();

    LPDIRECT3DVERTEXBUFFER9 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)

    {

    ........//Fenster

    main_window_handle = hwnd;

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

    ...........//Spielschleife

    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[]=
    {
    { 400.0f, 330.0f, 0.0f, 1.0f, 0xFFFF0000 },
    { 240.0f, 330.0f, 0.0f, 1.0f, 0xFF00FF00 },
    { 320.0f, 150.0f, 0.0f, 1.0f, 0xFF0000FF }
    };
    if(FAILED(lp3DD->CreateVertexBuffer(sizeof(VERTEX),NULL,MY_FVF,D3DPOOL_DEFAULT,&m_pVertex,NULL)))
    {
    SendMessage(main_window_handle,WM_CLOSE,0,0);
    }
    void* pVerts;
    if(FAILED(m_pVertex->Lock(0,sizeof(verts),(void**)&pVerts,NULL)))
    {
    SendMessage(main_window_handle,WM_CLOSE,0,0);
    }
    if(FAILED(memcpy(pVerts,&verts,sizeof(verts))))
    {
    SendMessage(main_window_handle,WM_CLOSE,0,0);
    }
    m_pVertex->Unlock();
    }
    void Render2()
    {

    lp3DD->BeginScene();
    if(FAILED(lp3DD->SetStreamSource(0,m_pVertex,0,3*sizeof(VERTEX))))
    {SendMessage(main_window_handle,WM_CLOSE,0,0);
    }
    if(FAILED(lp3DD->SetFVF(MY_FVF)))
    {
    SendMessage(main_window_handle,WM_CLOSE,0,0);
    }
    if(FAILED(lp3DD->DrawPrimitive(D3DPT_TRIANGLELIST,0,1)))
    {
    SendMessage(main_window_handle,WM_CLOSE,0,0);
    }
    lp3DD->EndScene();

    }



  • Bei der DirectX-SDK snd dutzende Beispiele und Tutorials dazu dabei, les die doch mal.
    rya.



  • Habs nochmal angesehen, dir fehlt scheinbar das lp3DD->Present(NULL, NULL, 0, NULL);
    Undd nutze bitte die [ cpp ] -Tags!
    rya.



  • Gibt's dann hier auch 20€? 😃


Log in to reply