创建win32应用程序空工程

//main.cpp
//time: 01/08/2013

#include<d3d9.h>
#include <d3dx9.h>

#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9.lib")

#define WINDOW_CLASS "UGPDX"
#define WINDOW_NAME  "Template"
#define WINDOW_WIDTH  640
#define WINDOW_HEIGHT 480

bool InitializeD3D(HWND hWnd,bool fullscreen);
bool InitializeObjects();
void RenderScene();
void Shutdown();

//Direct3D object and device
LPDIRECT3D9 g_D3D=NULL;
LPDIRECT3DDEVICE9 g_D3DDevice=NULL;

//Matrices  矩阵
D3DXMATRIX g_projection;
D3DXMATRIX g_ViewMatrix;
D3DXMATRIX g_WorldMatrix;

LRESULT WINAPI MsgProc(HWND hWnd,UINT msg,WPARAM wp,LPARAM lp)
{
 switch(msg)
 {
 case WM_DESTROY:
  PostQuitMessage(0);
  return 0;
  break;

case WM_KEYUP:
  if(wp == VK_ESCAPE) PostQuitMessage(0);
  break;
 }
    return DefWindowProc(hWnd,msg,wp,lp);
}

int WINAPI WinMain(HINSTANCE hInst,HINSTANCE ph,LPSTR cmd,int s)
{
 WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
  GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
  WINDOW_CLASS, NULL };

RegisterClassEx(&wc);
 HWND hWnd = CreateWindow(WINDOW_CLASS, WINDOW_NAME,
  WS_OVERLAPPEDWINDOW, 100, 100, WINDOW_WIDTH, WINDOW_HEIGHT,
  GetDesktopWindow(), NULL, wc.hInstance, NULL);

// Initialize Direct3D
 if(InitializeD3D(hWnd, false))
 {
  // Show the window
  ShowWindow(hWnd, SW_SHOWDEFAULT);
  UpdateWindow(hWnd);

// Enter the message loop
  MSG msg;
  ZeroMemory(&msg, sizeof(msg));

while(msg.message != WM_QUIT)
  {
   if(PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
   {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
   }
   else
    RenderScene();
  }
 }

// Release any and all resources.
 Shutdown();

// Unregister our window.
 UnregisterClass(WINDOW_CLASS, wc.hInstance);
 return 0;
}

bool InitializeD3D(HWND hWnd, bool fullscreen)
{
 D3DDISPLAYMODE displayMode;

// Create the D3D object.
 g_D3D = Direct3DCreate9(D3D_SDK_VERSION);
 if(g_D3D == NULL) return false;

// Get the desktop display mode.
 if(FAILED(g_D3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,
  &displayMode))) return false;

// Set up the structure used to create the D3DDevice
 D3DPRESENT_PARAMETERS d3dpp;
 ZeroMemory(&d3dpp, sizeof(d3dpp));

if(fullscreen)
 {
  d3dpp.Windowed = FALSE;
  d3dpp.BackBufferWidth = WINDOW_WIDTH;
  d3dpp.BackBufferHeight = WINDOW_HEIGHT;
 }
 else
  d3dpp.Windowed = TRUE;
 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
 d3dpp.BackBufferFormat = displayMode.Format;

// Create the D3DDevice
 if(FAILED(g_D3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
  hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE,
  &d3dpp, &g_D3DDevice))) return false;

// Initialize any objects we will be displaying.
 if(!InitializeObjects()) return false;

return true;
}

bool InitializeObjects()
{
 // Set the projection matrix.
 D3DXMatrixPerspectiveFovLH(&g_projection, 45.0f,
  WINDOW_WIDTH/WINDOW_HEIGHT, 0.1f, 1000.0f);

g_D3DDevice->SetTransform(D3DTS_PROJECTION, &g_projection);

// Set default rendering states.
 g_D3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);

// Define camera information.
 D3DXVECTOR3 cameraPos(0.0f, 0.0f, -1.0f);
 D3DXVECTOR3 lookAtPos(0.0f, 0.0f, 0.0f);
 D3DXVECTOR3 upDir(0.0f, 1.0f, 0.0f);

// Build view matrix.
 D3DXMatrixLookAtLH(&g_ViewMatrix, &cameraPos,
  &lookAtPos, &upDir);

return true;
}

void RenderScene()
{
 // Clear the back buffer.
 g_D3DDevice->Clear(0, NULL, D3DCLEAR_TARGET,
  D3DCOLOR_XRGB(0,0,0), 1.0f, 0);

// Begin the scene.  Start rendering.
 g_D3DDevice->BeginScene();

// Apply the view (camera).
 g_D3DDevice->SetTransform(D3DTS_VIEW, &g_ViewMatrix);

// End the scene.  Stop rendering.
 g_D3DDevice->EndScene();

// Display the scene.
 g_D3DDevice->Present(NULL, NULL, NULL, NULL);
}

void Shutdown()
{
 if(g_D3DDevice != NULL) g_D3DDevice->Release();
 if(g_D3D != NULL) g_D3D->Release();

g_D3DDevice = NULL;
 g_D3D = NULL;
}

Template的更多相关文章

  1. 为.NET Core项目定义Item Template

    作为这个星球上最强大的IDE,Visual Studio不仅仅提供了很多原生的特性,更重要的是它是一个可定制的IDE,比如自定义Project Template和Item Template就是一个非常 ...

  2. jQuery.template.js 简单使用

    之前看了一篇文章<我们为什么要尝试前后端分离>,深有同感,并有了下面的评论: 我最近也和前端同事在讨论这个问题,比如有时候前端写好页面给后端了,然后后端把这些页面拆分成很多的 views, ...

  3. 2000条你应知的WPF小姿势 基础篇<69-73 WPF Freeze机制和Template>

    在正文开始之前需要介绍一个人:Sean Sexton. 来自明尼苏达双城的软件工程师.最为出色的是他维护了两个博客:2,000ThingsYou Should Know About C# 和 2,00 ...

  4. tornado template

    若果使用Tornado进行web开发可能会用到模板功能,页面继承,嵌套... 多页应用模板的处理多半依赖后端(SPA就可以动态加载局部视图),就算是RESTfull的API设计,也不妨碍同时提供部分模 ...

  5. 设计模式(九): 从醋溜土豆丝和清炒苦瓜中来学习"模板方法模式"(Template Method Pattern)

    今天是五.四青年节,祝大家节日快乐.看着今天这标题就有食欲,夏天到了,醋溜土豆丝和清炒苦瓜适合夏天吃,好吃不上火.这两道菜大部分人都应该吃过,特别是醋溜土豆丝,作为“鲁菜”的代表作之一更是为大众所熟知 ...

  6. C++泛型编程:template模板

    泛型编程就是以独立于任何特定类型的方式编写代码,而模板是C++泛型编程的基础. 所谓template,是针对“一个或多个尚未明确的类型”所编写的函数或类. 使用template时,可以显示的或隐示的将 ...

  7. 新手入门Underscore.js 中文(template)

    Underscore.js是一个很精干的库,压缩后只有4KB.它提供了几十种函数式编程的方法,弥补了标准库的不足,大大方便了javaScript的编程.MVC框架Backbone.js就将这个库作为自 ...

  8. knockoutjs如何动态加载外部的file作为component中的template数据源

    玩过knockoutjs的都知道,有一个强大的功能叫做component,而这个component有个牛逼的地方就是拥有自己的viewmodel和template, 比如下面这样: ko.compon ...

  9. JavaScript模板引擎artTemplate.js——template.helper()方法

    上一篇文章我们已经讲到了helper()方法,但是上面的例子只是一个参数的写法,如果是多个参数,写法就另有区别了. <div id="user_info"></d ...

  10. linux下, 再次遇到使用thinkphp的模板标签时,报错used undefined function \Think\Template\simplexml_load_string() 是因为没有安装 php-xml包

    linux下, 使用thinkphp的模板标签,如 eq, gt, volist defined, present , empty等 标签时, 报错: used undefined function ...

随机推荐

  1. MVC4.0 利用IActionFilter实现简单的后台操作日志功能

    首先我们要了解MVC提供了4种常用的拦截器:IActionFilter(Action拦截器接口).IExceptionFilter(异常拦截器接口).IResultFilter(Result拦截器接口 ...

  2. [转]gdb结合coredump定位崩溃进程

    [转]gdb结合coredump定位崩溃进程 http://blog.sina.com.cn/s/blog_54f82cc201013tk4.html Linux环境下经常遇到某个进程挂掉而找不到原因 ...

  3. The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

    The ObjectContext instance has been disposed and can no longer be used for operations that require a ...

  4. R语言 如何为图片添加文字说明(转载)

    转载:(中文翻译者)[http://blog.csdn.net/chen790646223/article/details/49766659] (原文链接)[http://datascienceplu ...

  5. 用cmd命令合并N个文件

    今天早上朋友发我一篇小说(42个TXT文件),让我给他合并为一个文件.我首先想到的是“Copy”命令,它可以复制文件,也可以合并文件. 例如:合并1.txt和2.txt到12.txt(其为ASCII文 ...

  6. Struts2中的ModelDriven机制及其运用(转)

    所谓ModelDriven,意思是直接把实体类当成页面数据的收集对象.比如,有实体类User如下: package cn.com.leadfar.struts2.actions; public cla ...

  7. 《我是IT一只小小鸟》读后感

    <我是IT一只小小鸟>读后感 首先,非常感谢我的老师给我推荐了这么一本书,虽然刚开始因为这门课学分太低,所以我对老师布置了字数这么多的作业存在有很大的不满,但在看了这本书后我的不满立马得到 ...

  8. javascript去除首尾空白字符

    if ( twocode.replace(/^\s+|\s+$/g,"")=="" ) { alert("二维码不能为空"); docume ...

  9. 图片放大镜插件 Cloud Zoom v3.1

    Cloud Zoom是一个图像放大jQuery插件,效果堪比Magic Zoom.相对于流行jQZoom插件,Cloud Zoom体积小,有更多的功能和更强大的跨浏览器兼容性. 猛击这里查看演示DEM ...

  10. Tomcat漏洞说明与安全加固

    Tomcat是Apache软件基金会的一个免费的.开放源码的WEB应用服务器,可以运行在Linux和Windows等多个平台上,由于其性能稳定.扩展性好.免费等特点深受广大用户的喜爱.目前,互联网上绝 ...