关于DX游戏编程中设置分辨率和全屏窗口切换的问题
这是我目前最棘手的问题,就是设置分辨率和全屏窗口切换的问题
我想在自己创建的窗口实现以上功能,我记得在DXSDK中提供的函数和类好像有能实现这种功能的,不知道是哪一个。
而且我也想知道,在自己的主菜单界面的“设置”界面中如何显示这些选项。
我看了看资料,在D3D设备全屏与窗口的转换的实现中,leon hong先生指出需要修改D3DPRESENTATION_PARAMETERS中的windowed为true或false,就能实现切换。
但是我需要的是动态的切换,也就是在D3D设备(或者说程序)运行中设置这些选项,而不是通过代码中的全局变量或常量。
另外,关于这个问题,我需要一个完整的例子,让我知道这项功能应该添加到代码中的什么位置。
我的代码的简易结构如下:
//main.h#ifndef _UGP_MAIN_H_#define _UGP_MAIN_H_#define WINDOW_CLASS "StrandedGame"#define WINDOW_NAME "Stranded"#define WIN_WIDTH 800#define WIN_HEIGHT 600#define FULLSCREEN 1// Function Prototypes...bool InitializeEngine();void ShutdownEngine();// Main game functions.bool GameInitialize();void GameLoop();void GameShutdown();#endif
//main.cpp#include"main.h"HWND g_hwnd;CRenderInterface *g_Render = NULL;LRESULT WINAPI MsgProc(HWND hd, 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(hd, msg, wp, lp);}int WINAPI WinMain(HINSTANCE h, HINSTANCE p, LPSTR cmd, int show){ //注册窗口类 WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, WINDOW_CLASS, NULL }; RegisterClassEx(&wc); //创建应用程序窗口 if(FULLSCREEN) { g_hwnd = CreateWindowEx(NULL, WINDOW_CLASS, WINDOW_NAME, WS_POPUP | WS_SYSMENU | WS_VISIBLE, 0, 0, WIN_WIDTH, WIN_HEIGHT, NULL, NULL, h, NULL); } else { g_hwnd = CreateWindowEx(NULL, WINDOW_CLASS, WINDOW_NAME, WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, WIN_WIDTH, WIN_HEIGHT, NULL, NULL, h, NULL); } if(g_hwnd) { // Show the window ShowWindow(g_hwnd, SW_SHOWDEFAULT); UpdateWindow(g_hwnd); } //初始化引擎 if(InitializeEngine()) { // Initialize Stranded game. if(GameInitialize()) { // Enter the message loop MSG msg; ZeroMemory(&msg, sizeof(msg)); SetCursorPos(0, 0); while(msg.message != WM_QUIT) { if(PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else GameLoop(); } } } //释放资源 GameShutdown(); ShutdownEngine(); UnregisterClass(WINDOW_CLASS, wc.hInstance); return 0;}bool InitializeEngine(){ if(!CreateD3DRenderer(&g_Render)) return false; if(!g_Render->Initialize(WIN_WIDTH, WIN_HEIGHT, g_hwnd, FULLSCREEN)) return false; g_Render->SetClearCol(0, 0, 0); return true;}void ShutdownEngine(){ if(g_Render) { g_Render->Shutdown(); delete g_Render; g_Render = NULL; }}bool GameInitialize(){ return true;}void GameLoop(){ if(!g_Render) return; g_Render->StartRender(1, 1, 0); g_Render->EndRendering();}void GameShutdown(){}
http://www.directxtutorial.com/tutorial9/B-Direct3DBasics/dx9B2.aspx