Coordinate system and basic elements (8)

Source: Internet
Author: User
Coordinate system and basic elements (8)

Full Screen Display

Games are usually running in full screen mode. The key to full screen display is to use a full screen rendering device. The device that creates the full-screen rendering mode is basically the same as the rendering device in the window mode. The difference is to set d3dpp. javaswed to false, telling the direct3d system that a full-screen rendering device will be created. In addition, you must specify the size and format of the background buffer, which is different from that of the rendering device in the window mode, when creating a window-mode rendering device, you can set the background buffer format to d3dfmt_unknown. You can also set the background buffer size to the default value, which must be explicitly specified when creating a full-screen rendering device.

First, call the getadapterdisplaymode () function to obtain the current display mode of the display:

Retrieves the current display mode of the adapter.

HRESULT GetAdapterDisplayMode(
UINT Adapter,
D3DDISPLAYMODE * pMode
);
Parameters
Adapter
[In] ordinal number that denotes the display adapter to query. d3dadapter_default is always the primary display adapter.
Pmode
[In, out] pointer to a d3ddisplaymode structure, to be filled with information describing the current adapter's mode.
Return valuesif the method succeeds, the return value is d3d_ OK.

If adapter is out of range or pmode is invalid, this method returns d3derr_invalidcall.

Remarks

Idirect3d9: getadapterdisplaymode will not return the correct format when the display is in an extended format, such as 2: 10: 10: 10. Instead, it returns the format x8r8g8b8.

Describes the display mode.

typedef struct D3DDISPLAYMODE {
UINT Width;
UINT Height;
UINT RefreshRate;
D3DFORMAT Format;
} D3DDISPLAYMODE, *LPD3DDISPLAYMODE;
Members
Width
Screen width, in pixels.
Height
Screen height, in pixels.
Refreshrate
Refresh rate. The value of 0 indicates an adapter default.
Format
Member of the d3dformat enumerated type, describing the surface format of the display mode.

 

Run:

 

Complete source code:

 

# Include <d3d9. h>

# Define class_name "gameapp"

# Define release_com (p) do {If (p) {(P)-> release (); (p) = NULL ;}} while (0)

Idirect3d9 * g_d3d;
Idirect3ddevice9 * g_device;
Idirect3dvertexbuffer9 * g_vertex_buffer;

Struct scustomvertex
{
Float X, Y, Z, rhw;
DWORD color;
};

# Define d3dfvf_custom_vertex (d3dfvf_xyzrhw | d3dfvf_diffuse)

Void init_vertices ()
{
Scustomvertex vertices [] =
{
{1000000f, 00000000f, 0.5f, 1.0f, 0xffff0000 ,},
{5000000f, 1000000f, 0.5f, 1.0f, 0xff00ff00 ,},
{9000000f, 00000000f, 0.5f, 1.0f, 0xff0000ff ,},
};

// Push vertex data into vertex buffer

G_device-> createvertexbuffer (sizeof (vertices), 0, d3dfvf_custom_vertex, d3dpool_default, & g_vertex_buffer, null );

Void * PTR;

G_vertex_buffer-> lock (0, sizeof (vertices), (void **) & PTR, 0 );
Memcpy (PTR, vertices, sizeof (vertices ));
G_vertex_buffer-> unlock ();
}

Bool init_d3d (hwnd)
{
G_d3d = direct3dcreate9 (d3d_sdk_version );

If (g_d3d = NULL)
Return false;

D3dpresent_parameters d3dpp;
Zeromemory (& d3dpp, sizeof (d3dpp ));

D3ddisplaymode display_mode;
G_d3d-> getadapterdisplaymode (d3dadapter_default, & display_mode );

D3dpp. incluwed = false;
D3dpp. swapeffect = d3dswapeffect_discard;
D3dpp. backbufferwidth = display_mode.width;
D3dpp. backbufferheight = display_mode.height;
D3dpp. backbufferformat = display_mode.format;

If (failed (g_d3d-> createdevice (d3dadapter_default, d3ddevtype_hal, hwnd, d3dcreate_software_vertexprocessing,
& D3dpp, & g_device )))
{
Return false;
}

Init_vertices ();

Return true;
}

Void cleanup ()
{
Release_com (g_vertex_buffer );
Release_com (g_device );
Release_com (g_d3d );
}

Void render ()
{
G_device-> clear (0, null, d3dclear_target, d3dcolor_xrgb (5, 5, 5), 1.0f, 0 );

G_device-> beginscene ();

G_device-> setstreamsource (0, g_vertex_buffer, 0, sizeof (scustomvertex ));
G_device-> setfvf (d3dfvf_custom_vertex );
G_device-> drawprimitive (d3dpt_trianglelist, 0, 1 );

G_device-> endscene ();

G_device-> present (null, null );
}

Lresult winapi winproc (hwnd, uint MSG, wparam, lparam)
{
Switch (MSG)
{
Case wm_keydown:
Switch (wparam)
{
Case vk_escape:
Destroywindow (hwnd );
Break;
}
Break;

Case wm_destroy:
Postquitmessage (0 );
Return 0;
}

Return defwindowproc (hwnd, MSG, wparam, lparam );
}

Int winapi winmain (hinstance inst, hinstance, lpstr, INT)
{
Wndclassex WC;

WC. cbsize = sizeof (wndclassex );
WC. Style = cs_classdc;
WC. lpfnwndproc = winproc;
WC. cbclsextra = 0;
WC. cbwndextra = 0;
WC. hinstance = inst;
WC. hicon = NULL;
WC. hcursor = NULL;
WC. hbrbackground = NULL;
WC. lpszmenuname = NULL;
WC. lpszclassname = class_name;
WC. hiconsm = NULL;

If (! Registerclassex (& WC ))
Return-1;

Hwnd = createwindow (class_name, "direct3d app", ws_overlappedwindow, 200,100,600,500,
Null, null, WC. hinstance, null );

If (hwnd = NULL)
Return-1;

If (init_d3d (hwnd ))
{
Showwindow (hwnd, sw_showdefault );
Updatewindow (hwnd );

MSG;
Zeromemory (& MSG, sizeof (MSG ));

While (msg. message! = Wm_quit)
{
If (peekmessage (& MSG, null, 0, 0, pm_remove ))
{
Translatemessage (& MSG );
Dispatchmessage (& MSG );
}

Render ();
}
}

Cleanup ();

Unregisterclass (class_name, WC. hinstance );

Return 0;
}

 

Coordinate system and basic elements (8)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.