The Ultimate DirectX Tutorial
Sign In
Lesson 2: Going Fullscreen
Lesson Overview

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.

Setting Up the Screen Size

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",
                          300, 300,
                          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 600480,000No
1024 x 768786,432No
1152 x 864995,328No
1280 x 10241,310,720No
1600 x 12001,920,000No
1440 x 9001,296,000Yes
1680 x 10501,764,000Yes
1920 x 10802,073,600Yes
1920 x 12002,304,000Yes
Changing to Fullscreen Mode

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

                          SCREEN_WIDTH, SCREEN_HEIGHT,

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_A8R8G8B8This is a 32-Bit pixel format, with 256 levels (8 bits) of red, green, blue and alpha (semi-transparency).
D3DFMT_X8R8G8B8This is similar to A8R8G8B8, with the one difference being that it does not support alpha, even though there are 8 bits to represent this.

BackBufferWidth and BackBufferHeight

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

The Finished Program

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