游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2124|回复: 6

问题请教

[复制链接]

2

主题

11

帖子

11

积分

新手上路

Rank: 1

积分
11
发表于 2005-10-8 19:08:00 | 显示全部楼层 |阅读模式
#include<windows.h>
#include<d3d9.h>


LRESULT CALLBACK MsgProc(HWND,UINT,WPARAM,LPARAM);
INT WINAPI WinMain(HINSTANCE hInst,HINSTANCE,LPSTR,INT)
{
   //第1步 建立窗口对象和窗体 Register the window class
        WNDCLASSEX wc;
        wc.cbSize=sizeof(WNDCLASSEX);
        wc.style =CS_CLASSDC;
        wc.lpfnWndProc =MsgProc;
        wc.cbClsExtra =0;
        wc.cbWndExtra =0;
        wc.hInstance=GetModuleHandle(NULL);
        wc.lpszClassName=TEXT("WindowClass");
        wc.hbrBackground =NULL;
        wc.hCursor =NULL;
        wc.hIcon =NULL;
        wc.hIconSm =NULL;
        wc.lpszMenuName =NULL;

        RegisterClassEx(&wc);

        //Create the application's window
        HWND hWnd =CreateWindow(TEXT("WindowClass"),TEXT("Test"),WS_OVERLAPPEDWINDOW,
                                    100,100,512,512,GetDesktopWindow(),NULL,wc.hInstance ,NULL);

        //第2步 建立D3D对象
        IDirect3D9* g_pD3D=NULL;
        if(NULL==(g_pD3D=Direct3DCreate9(D3D_SDK_VERSION)))
                return E_FAIL;
   
       
        //第3步 建立D3D设备对象
        //Pointer to a Direct3D device
    IDirect3DDevice9 *g_pd3dDevice=NULL;

        D3DPRESENT_PARAMETERS d3dpp;
        ZeroMemory(&d3dpp,sizeof(d3dpp));
        d3dpp.Windowed=true;
        d3dpp.SwapEffect= D3DSWAPEFFECT_DISCARD ;
        d3dpp.BackBufferFormat=D3DFMT_UNKNOWN;
        d3dpp.EnableAutoDepthStencil=TRUE;
        d3dpp.AutoDepthStencilFormat=D3DFMT_D16;

        //Create the D3DDevice
        if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT ,
                                           D3DDEVTYPE_HAL,hWnd,
                                                                   D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                                                   &d3dpp,&g_pd3dDevice)))
        {
           return E_FAIL;
        }



        //第4步  进入消息循环
/* Windows默认的消息循环
        MSG msg;

        while(GetMessage(&msg,NULL,0,0))
        {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
        }
*/

        //游戏使用的消息循环

        MSG mssg;
        PeekMessage(&mssg,NULL,0,0,PM_NOREMOVE);
    //run till completed
        while(mssg.message!=WM_QUIT)
        {
           //is there a message to process?
                if(PeekMessage(&mssg,NULL,0,0,PM_REMOVE))
                {
                   //dispatch the message
          TranslateMessage(&mssg);
               DispatchMessage(&mssg);
                }

        //        else
                        //No message to process?
                        //Then do your game stuff here
                //        Render();
        }

        //第5步  渲染与绘制场景
   //Clear the back buffer and z buffer
        g_pd3dDevice->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
                                D3DCOLOR_XRGB(0,0,255),1.0f,0);

        //Begin the scene
        if(SUCCEEDED(g_pd3dDevice->BeginScene()))
        {
           //Draw stuff here

           //End the scene
                g_pd3dDevice->EndScene();

           //Present the back buffer contents to the display
                g_pd3dDevice-&gtresent(NULL,NULL,NULL,NULL);
        }

   //第6步 关闭D3D
        g_pD3D->Release();
        g_pd3dDevice->Release();

       
}


LRESULT CALLBACK MsgProc(HWND hWnd,UINT mssg,WPARAM wParam,LPARAM lParam)
{
        return DefWindowProc(hWnd,mssg,wParam,lParam);
}

2

主题

11

帖子

11

积分

新手上路

Rank: 1

积分
11
 楼主| 发表于 2005-10-8 19:10:00 | 显示全部楼层

Re:问题请教

这个程序在编译的时候没有出错,但是连接的时候却发生错误
显示
--------------------Configuration: Chapter2 - Win32 Debug--------------------
Linking...
game.obj : error LNK2001: unresolved external symbol _Direct3DCreate9@4
Debug/Chapter2.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Chapter2.exe - 2 error(s), 0 warning(s)

这是怎么回事啊?? 谢谢

2

主题

11

帖子

11

积分

新手上路

Rank: 1

积分
11
 楼主| 发表于 2005-10-8 19:11:00 | 显示全部楼层

Re:问题请教

另外还有一个问题,为什么我的VC编辑器在使用的过程中,输入了函数,而以前会自动跳出的各个参数浏览却没有了??
这是什么设置引起的?

77

主题

203

帖子

279

积分

中级会员

Rank: 3Rank: 3

积分
279
发表于 2005-10-9 11:29:00 | 显示全部楼层

Re:问题请教

应该是连接错误!

42

主题

418

帖子

418

积分

中级会员

Rank: 3Rank: 3

积分
418
发表于 2005-10-9 15:24:00 | 显示全部楼层

Re:问题请教

没有链接 d3d9.lib 库文件

2

主题

18

帖子

24

积分

注册会员

Rank: 2

积分
24
发表于 2005-10-9 16:30:00 | 显示全部楼层

Re:问题请教

#pragma comment(lib,"D3D9.lib")

2

主题

11

帖子

11

积分

新手上路

Rank: 1

积分
11
 楼主| 发表于 2005-10-9 20:38:00 | 显示全部楼层

Re:问题请教

啊,谢谢.我去试着看一下.
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-28 03:06

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表