Ich habe ein Problem bei der 3D Programmierung



  • Leider bleigt der Bildschirm rot!!!!!!!!!

    [#define WINDOW_CLASS_NAME "Game Shell Window"
    #define WIN32_LEAN_AND_MEAN

    #include <windows.h>
    #include <d3dx9.h>

    LPDIRECT3D9 D3DGE = NULL;
    LPDIRECT3DDEVICE9 D3DGR = NULL;
    LPDIRECT3DVERTEXBUFFER9 rew = NULL;

    #define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
    #define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)
    #define D3D_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)
    struct CustomVertex
    {
    float x,y,z,rhw;
    DWORD color;
    };
    CustomVertex Tria[]=
    {
    {320.0f,150.0f,0.0f,1.0f,D3DCOLOR_XRGB(0,255,0)},
    {400.0f,330.0f,0.0f,1.0f,D3DCOLOR_XRGB(0,255,0)},
    {400.0f,330.0f,0.0f,1.0f,D3DCOLOR_XRGB(0,255,0)},

    };

    void Init_3D();
    void Render();
    void Init_Scene();

    HWND main_window_handle = NULL;
    HINSTANCE hinstance_app = NULL;

    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,
    "My Game Shell",
    WS_POPUP | 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(main_window_handle,WM_CLOSE,0,0);
    }
    Render();
    }

    }

    return(msg.wParam);

    }

    void Init_3D()
    {
    D3DGE = Direct3DCreate9(D3D_SDK_VERSION);
    D3DPRESENT_PARAMETERS dpp;
    ZeroMemory(&dpp,sizeof(dpp));
    dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    dpp.BackBufferCount = 1;
    dpp.BackBufferWidth = 1680;
    dpp.BackBufferHeight = 1050;
    dpp.Windowed = FALSE;
    dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    dpp.hDeviceWindow = main_window_handle;
    D3DGE->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,main_window_handle,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&dpp,&D3DGR);
    }

    void Render()
    {
    D3DGR->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(255,0,0),1.0f,0);
    D3DGR->BeginScene();
    D3DGR->SetStreamSource(0,rew,0,sizeof(CustomVertex));
    D3DGR->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
    D3DGR->EndScene();
    D3DGR->Present(NULL,NULL,NULL,NULL);
    }
    void Init_Scene()
    {
    void* VertexBufferStart;

    D3DGR->CreateVertexBuffer(3*sizeof(Tria),D3DUSAGE_WRITEONLY,D3D_CUSTOMVERTEX,D3DPOOL_MANAGED,&rew,NULL);
    rew->Lock(0,0,&VertexBufferStart,0);
    memcpy(VertexBufferStart,Tria,sizeof(Tria));
    rew->Unlock();
    D3DGR->SetFVF(D3D_CUSTOMVERTEX);
    }cpp]



  • Ist ja voll schlimm ey



  • Ich hab Dir doch schon im anderen Beitrag geantwortet.... meinen Rat scheinst Du ja angenommen zu haben mit ->Present(), aber wieder keine [ cpp ] - Tags und was genau willst Du denn jetzt?
    So langsam vergeht sogar mir die Lust Dir zu helfen.
    rya.



  • Probier mal die Antworten beim CreateDevice abzufangen (mit HRESULT bzw. FAILED und SUCCEEDED Makros), dann wirst Du wohl eine Fehlermeldung erhalten, die einen Hinweis gibt. Wahrscheinlich ein zu groß gewählter VideoBackbuffer. So sollte es gehen:

    void Init_3D()
    {
    	D3DGE = Direct3DCreate9(D3D_SDK_VERSION);
    	D3DPRESENT_PARAMETERS dpp;
    	ZeroMemory(&dpp,sizeof(dpp));
    	dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    	dpp.BackBufferCount = 1;
    	dpp.BackBufferWidth = 800;
    	dpp.BackBufferHeight = 600;
    	dpp.Windowed = TRUE;
    	dpp.BackBufferFormat = D3DFMT_UNKNOWN;//D3DFMT_X8R8G8B8;
    	dpp.hDeviceWindow = main_window_handle;
    	hr=D3DGE->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,main_window_handle,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&dpp,&D3DGR);
    	if(hr==D3DERR_INVALIDCALL)		SendMessage(main_window_handle,WM_CLOSE,0,0);//D3DERR_INVALIDCALL D3DERR_NOTAVAILABLE D3DERR_OUTOFVIDEOMEMORY
    }
    

Log in to reply