posts - 16,  comments - 81,  trackbacks - 0
 

Lesson 2: 走向全屏

From

http://www.directxtutorial.com/tutorial9/b-direct3dbasics/dx9b2.aspx#still

Translated By----Double One(王大宝)   dfghj77777@gmail.com
Finished At 20101215

笔者:自第一篇发出以来,已过一月。最近忙,翻译有些耽搁,接下来我会保证一周至少一篇 ,谢谢大家的支持。

课程概述

Making your game fullscreen is easy, but requires changing a few details of the program, as well as adding a couple lines of code.

In this lesson we will cover two things.  First, we will go over how to globalize your screen resolution and why you would do this.  Second, we'll cover the mechanics of making a window go into fullscreen mode.

其实全屏化很容易,改几行代码就好,来死狗(Let’s Go)。

在这一课中我们将介绍两件事情。首先,我们将研究怎样改变你的屏幕分辨率以及为什么要这么做。其次呢,我们捎带介绍一下使窗口进入全屏模式的机制原理。

设置屏幕尺寸

Throughout your DirectX experience and in game programming you will come across many functions and structs that demand to know your screen size.  This can become a hassle when you decide to change the resolution later, and especially when you decide to change it during run-time.  For right now, we will cover a simple method to standardize your screen size across your program.

在你的DirectX或者游戏编程经历里你一定会碰到许多函数和结构体管你要屏幕尺寸,是的,这也许并不困难。可是当你要更改分辨率时麻烦就来了,尤其是你非得在运行的时候这么干。现在,哥将给你介绍一个简单的方法来规范你的程序的屏幕大小,这个方法非常简单,但是非常的实用,而且,它只要九——百——九——十——八,还犹豫什么,赶紧往下看吧。

 

First, we must add two directives to the top of our program.  These represent the screen width and the screen height.

首先,我们在程序开头添加两个指令。这些代表了屏幕的宽度和屏幕的高度。

1// define the screen resolution
2#define SCREEN_WIDTH  800
3#define SCREEN_HEIGHT 600
4

 

The next step is to go through your program to where you indicate the width and height of your window.  Up to this point in the tutorial, you only have one, although we will come across another in a minute.  Do this to the code (changes in bold):

接下来,来到声明窗口宽度和高度的地方。本教程到目前为止,只有一个声明的地方,注意粗体那行:

 1hWnd = CreateWindowEx(NULL,
 2                          L"WindowClass",
 3                          L"Our Direct3D Program",
 4                          WS_OVERLAPPEDWINDOW,
 5                          300300,
 6                     SCREEN_WIDTH, SCREEN_HEIGHT,    // 设置新的尺寸 
 7NULL,
 8                          NULL,
 9                          hInstance,
10                          NULL);
11
 

In a later lesson we will cover how to maintain screen size throughout your game after changing it during runtime.

There are specific resolutions that are available on most PCs, the most common of which can be seen in this table.

在后面的课上,我们将讨论如在运行过程中改变屏幕尺寸后继续游戏。
这儿有张常见的分辨率表可以参考一下。

 

[Table 2.1 - Common Screen Resolutions]更多信息请猛击我

Resolution

Pixels

Widescreen

800 x 600

480,000

No

1024 x 768

786,432

No

1152 x 864

995,328

No

1280 x 1024

1,310,720

No

1600 x 1200

1,920,000

No

1440 x 900

1,296,000

Yes

1680 x 1050

1,764,000

Yes

1920 x 1080

2,073,600

Yes

1920 x 1200

2,304,000

Yes



 

变成全屏模式

When changing to full screen you are doing several things.  First, your are telling Windows not to apply any of the standard Windows borders to your window.  Second, you are telling Windows to have your window overlap all other things on the screen, including the start menu.  Third, you are telling DirectX to change the resolution of the monitor to your set preference.  Finally, although less importantly, you are telling Windows to leave the window background color up to you.

The first two of these are handled by changing some CreateWindowEx() parameters.  The changes we need to make are shown here.

切换到全屏的时候你要做这么几件事儿。首先,你告诉Windows不要添加任何标准的Windows窗口边框。其次,你告诉不要把其他Windows窗口盖在我们的全屏游戏上,包括开始菜单。再次,你告诉DirectX的把显示器的分辨率设置成我们要的值。最后,尽管这条不是那么重要,你得告诉Windows离开窗口时的背景色。
前两个处理通过改变一些CreateWindowEx()的参数。改动如下。

 1hWnd = CreateWindowEx(NULL,
 2                          L"WindowClass",
 3                          L"Our Direct3D Program",
 4                          WS_EX_TOPMOST | WS_POPUP,    // fullscreen values
 5                          00,    // the starting x and y positions should be 0
 6                          SCREEN_WIDTH, SCREEN_HEIGHT,
 7                          NULL,
 8                          NULL,
 9                          hInstance,
10                          NULL);
11

 

Here we set the starting x and y positions to 0.  We also changed the previous parameter to "WS_EX_TOPMOST | WS_POPUP".  The WS_EX_TOPMOST is self-explanatory, and makes the window overlap everything else.  The WS_POPUP is less self-explanatory, but what it does is tell Windows to remove all borders of any kind, including the rounded-edge top that you see in Windows XP.

在这里,我们设置xy的初始位置为0。我们还改变了第四个参数,将其设置为了“WS_EX_TOPMOST | WS_POPUP” WS_EX_TOPMOST顾名思义就是让我们的全屏程序在桌面最顶层。WS_POPUP的作用是告诉Windows以消除任何形式的所有边界,包括圆形的边缘等窗口边框,总之就是你所看到过的全屏游戏那样。

 

There is also a member of the WINDOWCLASSEX struct that we need to take out.  This leaves the background color untouched, which means it won't be visible as window for a second or two before the game starts (important to making your game look professional).

还有一个WINDOWCLASSEX结构的成员,我们需要把它拿掉。它的作用是设置窗口背景色不,而这会使游戏全屏时屏幕闪烁几下(把它拿掉会让您的游戏看起来专业得多)。

1 wc.hbrBackground = NULL;//(HBRUSH)COLOR_WINDOW;
 

Next, we have to tell DirectX about our new screen resolution.  We do this by making a few changes to the d3dpp struct we built in the last lesson.  Let's look at what they are before we see what they do.

下一步,我们来告诉DirectX一个新的屏幕分辨率。我们通过对上一课中创建的d3dpp结构体进行一些小小的改变来完成这项工作。下面让我们看看具体代码吧

 

 1D3DPRESENT_PARAMETERS d3dpp;    // create a struct to hold various device information
 2
 3    ZeroMemory(&d3dpp, sizeof(d3dpp));    // clear out the struct for use
 4    d3dpp.Windowed = FALSE;    // program fullscreen, not windowed
 5    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames
 6    d3dpp.hDeviceWindow = hWnd;    // set the window to be used by Direct3D
 7    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;    // set the back buffer format to 32-bit
 8    d3dpp.BackBufferWidth = SCREEN_WIDTH;    // set the width of the buffer
 9    d3dpp.BackBufferHeight = SCREEN_HEIGHT;    // set the height of the buffer
10


 

Let's examine these new back buffer related variables.

下面我来解释一下这些新的后台缓冲相关变量

 

d3dpp.BackBufferFormat

This member is used to tell Direct3D what kind of pixels should be displayed.  There are six types that can be used here, but two of them are older types (16-bit) and not generally used anymore.  There are several 32-bit types that we can use.  We'll use the D3DFMT_X8R8G8B8.  See the table for a description along with some other values than can be used here (definitely not all of them).

这个成员变量是用来告诉Direct3D什么样的像素会被显示。可分为六种 ,但其中两大类型太老了(16),一般不到。有432位的类型,我们可以使用。本课将使用D3DFMT_X8R8G8B8。想知道具体这个四个类型,可以看看下面的表。

 

[Table 2.2 - Some Back Buffer Formats]

描述

D3DFMT_A8R8G8B8

This is a 32-Bit pixel format, with 256 levels (8 bits) of red, green, blue and alpha (semi-transparency).

这是一个32位的像素格式。有256(8bit)的红,绿,蓝以及透明通道。

D3DFMT_X8R8G8B8

This is similar to A8R8G8B8, with the one difference being that it does not support alpha, even though there are 8 bits to represent this.

这个和上一个很类似,唯一的不同就是这个不支持透明

D3DFMT_A2R10G10B10

This is a 32-Bit pixel format, with only two bits of alpha, but 10 bits (1024 levels) of each red, green and blue.

还是一个32位的像素格式。2bit的透明通道,10bit1024级)的红绿蓝通道。

D3DFMT_A16B16G16R16

64-BIT COLOR!  If you have the capability to run 64-bit color, I'd recommend playing around with this to see how it works.
64bit
的!哦这太棒了。如果你可以运行64位的颜色,我强烈推荐你使用这个
This value has 16 bits for each component (65536 levels compared to the current measly 256!)

红绿蓝加透明各占16bit65536级)。

 

BackBufferWidth and BackBufferHeight

These two members indicate the width and height of the back buffer.  Painfully simple.

这两个成员变量表明后备缓冲区的宽度和高度。相当简单

最终成品

So, there isn't much to change.  Let's take a look at the whole picture and see what is different and what is the same.

所以,其实没改动多少。让我们看一看整个代码,并对比上一课什么是不同的,什么是一样的。


 

There isn't really a point in me showing a screenshot of this program's result, because it would just be a blue rectangle.  Your program should look like that: a blue rectangle with a mouse pointer in the middle.

我没有做截图,因为它只是一个蓝色的长方形。你的程序应该也看起来像他一样:蓝色的长方形充鼠标指针在中间。

总结

Great!  We now have a simple platform on which to build games.

Before you go on, I recommend doing the following exercise to gain familiarity with the code in this program:

Change the resolution of the program until you are familiar with the various resolutions selectable.

When you're ready to go on, let's hit the next lesson!

太棒了!我们现在有一个简单的平台做游戏。  

在你接着干之前,我建议做做这几个练习一遍更好地熟悉Direct3D:  

改变程序的分辨率,直到你熟悉各种各样可选择的分辨率。

当你准备好了,我们开始下一个教程。

 

Next Lesson:  An Overview of the Third Dimension

下一课:三维的概述

 

GO! GO! GO!

 

posted on 2010-12-15 23:54 叫我老王吧 阅读(2338) 评论(0)  编辑 收藏 引用 所属分类: DierectXC++

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2010年12月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(4)

随笔分类

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜