标题:DirectX程序入门级的编译错误,头都大了
只看楼主
Nitpicker
Rank: 1
等 级:新手上路
帖 子:26
专家分:8
注 册:2012-3-28
结帖率:83.33%
已结贴  问题点数:10 回复次数:5 
DirectX程序入门级的编译错误,头都大了
#include <d3d9.h>
//下面的代码完全是按照别人的教程复制的,DirexctX环境也已经配置好了
//但是还是在下面红字那里出错了 怎么回事啊,求指教
LPDIRECT3D9 g_pD3D = NULL;
LPDIRECT3DDEVICE9 g_pD3DDevice = NULL;

HRESULT InitialiseD3D(HWND hWnd)
{
    //First of all, create the main D3D object. If it is created successfully we
    //should get a pointer to an IDirect3D9 interface.
    g_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
    if(g_pD3D == NULL)
    {
        return E_FAIL;
    }

    //Get the current display mode
    D3DDISPLAYMODE d3ddm;
    if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
    {
        return E_FAIL;
    }

    //Create a structure to hold the settings for our device
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory(&d3dpp, sizeof(d3dpp));

    //Fill the structure.
    //We want our program to be windowed, and set the back buffer to a format
    //that matches our current display mode
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;
    //Conversion to enumeration type requires an explicit cast
    //(static_cast, C-style cast or function-style cast)上面这句编译出错,那要怎么用explicit cast ????

     
    d3dpp.BackBufferFormat = d3ddm.Format;

    //Create a Direct3D device.
    if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                   D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp,
                                   &g_pD3DDevice)))
    {
        return E_FAIL;
    }
   
    return S_OK;
}

void Render()
{
    if(g_pD3DDevice == NULL)
    {
        return;
    }

    //Clear the back buffer to a green colour
    g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 255, 0), 1.0f, 0);
   
    //Begin the scene
    g_pD3DDevice->BeginScene();
   
    //Rendering of our game objects will go here
   
    //End the scene
    g_pD3DDevice->EndScene();
   
    //Filp the back and front buffers so that whatever has been rendered on the
    //back buffer will now be visible on screen (front buffer).
    g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}

void CleanUp()
{
    if(g_pD3DDevice != NULL)
    {
        g_pD3DDevice->Release();
        g_pD3DDevice = NULL;
    }

    if(g_pD3D != NULL)
    {
        g_pD3D->Release();
        g_pD3D = NULL;
    }
}

void GameLoop()
{
    //Enter the game loop
    MSG msg;
    BOOL fMessage;

    PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE);
   
    while(msg.message != WM_QUIT)
    {
        fMessage = PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE);

        if(fMessage)
        {
            //Process message
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else
        {
            //No message to process, so render the current scene
            Render();
        }

    }
}

//The windows message handler
LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
        break;
        case WM_KEYUP:
            switch (wParam)
            {
                case VK_ESCAPE:
                    //User has pressed the escape key, so quit
                    DestroyWindow(hWnd);
                    return 0;
                break;
            }
        break;

    }

    return DefWindowProc(hWnd, msg, wParam, lParam);
}

//Application entry point
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, INT)
{
    //Register the window class
    WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_CLASSDC, WinProc, 0L, 0L,
                     GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                     "DX Project 1", NULL};
    RegisterClassEx(&wc);

    //Create the application's window
    HWND hWnd = CreateWindow("DX Project 1", "www. Tutorial 1",
                              WS_OVERLAPPEDWINDOW, 50, 50, 500, 500,
                              GetDesktopWindow(), NULL, wc.hInstance, NULL);

    //Initialize Direct3D
    if(SUCCEEDED(InitialiseD3D(hWnd)))
    {
        //Show our window
        ShowWindow(hWnd, SW_SHOWDEFAULT);
        UpdateWindow(hWnd);

        //Start game running: Enter the game loop
        GameLoop();
    }
   
    CleanUp();

    UnregisterClass("DX Project 1", wc.hInstance);
   
    return 0;
}
搜索更多相关主题的帖子: pointer interface DirectX created 
2012-11-27 21:49
mmmmmmmmmmmm
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:8
帖 子:388
专家分:1809
注 册:2012-11-2
得分:3 
DirectX还没学呢

帮顶

我们的目标只有一个:消灭0回复!
while(1)
++money;
2012-11-27 23:11
w527705090
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:441
专家分:1882
注 册:2011-6-28
得分:4 
虽然是Dx入门级别的程序,对于我这个菜鸟来说就是大项目了。。。
不懂,只好帮顶了。。。

有心者,千方百计;无心者,千难万难。
2012-11-27 23:13
Nitpicker
Rank: 1
等 级:新手上路
帖 子:26
专家分:8
注 册:2012-3-28
得分:0 
没人在学DirectX吗?
2012-11-28 11:48
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:507
帖 子:8890
专家分:53117
注 册:2011-1-18
得分:3 
和DirectX屁关系都没有
就是 d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC; 这一句编译错误
你看看 d3dpp.SwapEffect 是什么类型,D3DSWAPEFFECT_COPY_VSYNC 又是什么类型
2012-11-28 11:57
Nitpicker
Rank: 1
等 级:新手上路
帖 子:26
专家分:8
注 册:2012-3-28
得分:0 
回复 5楼 rjsp
我知道怎么改了,原来是我把原本他代码里的8 都改成9了 本来以为DirectX9跟DirextX8 里面的数据结构应该都一样的
但是现在知道了,不是直接换一个版本号那么简单。 以后再好好了解 改回来就成功了
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;这句话本身没问题,可能是DirectX9.0 里的定义不太一样吧

[ 本帖最后由 Nitpicker 于 2012-11-28 12:35 编辑 ]
2012-11-28 12:33



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-388775-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.157671 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved