游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3011|回复: 2

借地方,贴代码

[复制链接]

17

主题

24

帖子

26

积分

注册会员

Rank: 2

积分
26
发表于 2004-9-24 16:48:00 | 显示全部楼层 |阅读模式
  1. //////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // File: d3dinit.cpp
  4. //
  5. // Author: Frank Luna (C) All Rights Reserved
  6. //
  7. // System: AMD Athlon 1800+ XP, 512 DDR, Geforce 3, Windows XP, MSVC++ 7.0
  8. //
  9. // Desc: Demonstrates how to initialize Direct3D, how to use the book's framework
  10. //       functions, and how to clear the screen to black.  Note that the Direct3D
  11. //       initialization code is in the d3dUtility.h/.cpp files.
  12. //         
  13. //////////////////////////////////////////////////////////////////////////////////////////////////

  14. #include "d3dUtility.h"
  15. #include <strstream>
  16. /*#include <d3dx9tex.h>
  17. #include <d3dx9core.h>
  18. */

  19. //
  20. // Globals
  21. //

  22. IDirect3DDevice9* Device = 0;
  23. IDirect3DTexture9* Tex1 = 0;
  24. IDirect3DTexture9* Tex2 = 0;
  25. ID3DXSprite* Spr = 0;

  26. //
  27. // Framework Functions
  28. //

  29. bool Setup()
  30. {
  31.         // Nothing to setup in this sample.
  32.         D3DXCreateSprite(Device,&Spr);
  33.         Device->SetSamplerState(0,D3DSAMP_MIPFILTER,D3DTEXF_NONE);
  34.         D3DXCreateTextureFromFileEx(Device,".\\DATA\\1.tga",0,0,0,0,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,D3DX_FILTER_BOX,D3DX_DEFAULT,0xFF000000,0,0,&Tex1);
  35.         //D3DXCreateTextureFromFile(Device,".\\DATA\\1.tga",&Tex1);
  36.         //D3DXCreateTextureFromFileEx(Device,"1.tga",0,0,0,0,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,D3DX_FILTER_BOX,D3DX_DEFAULT,0xFFffffff,0,0,&Tex1);
  37.         D3DSURFACE_DESC desc;
  38.         Tex1->GetLevelDesc(0,&desc);
  39.                
  40.                
  41.         int height = desc.Height;
  42.         int width = desc.Width;
  43.         return true;
  44. }

  45. void Cleanup()
  46. {
  47.         // Nothing to cleanup in this sample.
  48. }

  49. bool Display(float timeDelta)
  50. {
  51.         if( Device ) // Only use Device methods if we have a valid device.
  52.         {
  53.                 // Instruct the device to set each pixel on the back buffer black -
  54.                 // D3DCLEAR_TARGET: 0x00000000 (black) - and to set each pixel on
  55.                 // the depth buffer to a value of 1.0 - D3DCLEAR_ZBUFFER: 1.0f.
  56.                 static float lastTime;
  57.                 static int   fps = 0;
  58.                 lastTime += timeDelta;
  59.                 if( lastTime > 1.0 )
  60.                 {
  61.                         std::ostrstream oss;
  62.                         oss << fps << "\n" << '\0' ;
  63.                         OutputDebugString( oss.str() );
  64.                         lastTime -= 1.0;
  65.                         fps = 0.0;
  66.                 }
  67.                 else
  68.                         ++fps;


  69.                 Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00ffffff, 1.0f, 0);
  70.                 Device->BeginScene();
  71.                 Spr->Begin(D3DXSPRITE_ALPHABLEND);
  72.                 Spr->Draw(Tex1,0,0,0,0xffffffff);
  73.                 Spr->End();
  74.                 Device->EndScene();
  75.                 // Swap the back and front buffers.
  76.                 Device->Present(0, 0, 0, 0);
  77.         }
  78.         return true;
  79. }

  80. //
  81. // WndProc
  82. //
  83. LRESULT CALLBACK d3d::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  84. {
  85.         switch( msg )
  86.         {
  87.         case WM_CREATE:
  88.                 SetTimer(hwnd,1,100,0);
  89.                 break;
  90.         case WM_DESTROY:
  91.                 ::PostQuitMessage(0);
  92.                 break;
  93.                
  94.         case WM_KEYDOWN:
  95.                 if( wParam == VK_ESCAPE )
  96.                         ::DestroyWindow(hwnd);
  97.                 break;
  98.         case WM_TIMER:
  99.                 int i = 1;
  100.                 break;
  101.         }
  102.         return ::DefWindowProc(hwnd, msg, wParam, lParam);
  103. }

  104. //
  105. // WinMain
  106. //
  107. int WINAPI WinMain(HINSTANCE hinstance,
  108.                                    HINSTANCE prevInstance,
  109.                                    PSTR cmdLine,
  110.                                    int showCmd)
  111. {
  112.         if(!d3d::InitD3D(hinstance,
  113.                 640, 480, true, D3DDEVTYPE_HAL, &Device))
  114.         {
  115.                 ::MessageBox(0, "InitD3D() - FAILED", 0, 0);
  116.                 return 0;
  117.         }
  118.                
  119.         if(!Setup())
  120.         {
  121.                 ::MessageBox(0, "Setup() - FAILED", 0, 0);
  122.                 return 0;
  123.         }

  124.         d3d::EnterMsgLoop( Display );

  125.         Cleanup();

  126.         Device->Release();

  127.         return 0;
  128. }
复制代码

139

主题

2005

帖子

2057

积分

金牌会员

Rank: 6Rank: 6

积分
2057
QQ
发表于 2004-9-30 19:44:00 | 显示全部楼层

Re:借地方,贴代码

做什么的代码?
哦哦我看明白了……
你这是水贴啊……

37

主题

727

帖子

740

积分

高级会员

Rank: 4

积分
740
发表于 2004-10-31 09:41:00 | 显示全部楼层

Re:借地方,贴代码

他可能想存些代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-12-23 02:12

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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