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.
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.
First, we must add two directives to the top of our program. These represent the screen width and the screen height.
// define the screen resolution
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
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):
hWnd = CreateWindowEx(NULL,
L"Our Direct3D Program",
SCREEN_WIDTH, SCREEN_HEIGHT, // set window to new resolution
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.
Some Common Screen Resolutions
|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.
hWnd = CreateWindowEx(NULL,
L"Our Direct3D Program",
WS_EX_TOPMOST | WS_POPUP, // fullscreen values
0, 0, // the starting x and y positions should be 0
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.
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).
// wc.hbrBackground = (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.
D3DPRESENT_PARAMETERS d3dpp; // create a struct to hold various device information
ZeroMemory(&d3dpp, sizeof(d3dpp)); // clear out the struct for use
d3dpp.Windowed = FALSE; // program fullscreen, not windowed
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // discard old frames
d3dpp.hDeviceWindow = hWnd; // set the window to be used by Direct3D
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; // set the back buffer format to 32-bit
d3dpp.BackBufferWidth = SCREEN_WIDTH; // set the width of the buffer
d3dpp.BackBufferHeight = SCREEN_HEIGHT; // set the height of the buffer
Let's examine these new back buffer related variables.
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).
A Couple Common 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).|
|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.|
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!
Next Lesson: An Overview of the Third Dimension
GO! GO! GO!
© 2006-2015 DirectXTutorial.com. All Rights Reserved. Expand