Jump to content
  • Advertisement
Sign in to follow this  
Cronusuk

Full screen Query

This topic is 3014 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

All,
I've been playing about with some directX tutorials and have a query regarding fullscreen. In windowed mode my app displays a blue background, however when switched to fullscreen the background is black. Could anyone point me to the reason why?

Thanks


// include the basic windows header files and the Direct3D header file
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>

// include the Direct3D Library file
#pragma comment (lib, "d3d9.lib")

//global variables
bool bFullScreen = false;

// global declarations
LPDIRECT3D9 d3d; // the pointer to our Direct3D interface
LPDIRECT3DDEVICE9 d3ddev; // the pointer to the device class

// function prototypes
bool initD3D(HWND hWnd); // sets up and initializes Direct3D
void render_frame(void); // renders a single frame
void cleanD3D(void); // closes Direct3D and releases memory

// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);


// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// put up a messagebox requesting the user to chose between a
// fullscreen or windowed application
if (MessageBox(NULL, L"Would you like fullscreen?", L"INFORMATION", MB_YESNO) == IDYES)
{
// we set a bool to true if the user wants fullscreen
bFullScreen = true;
}

HWND hWnd;
WNDCLASSEX wc;

ZeroMemory(&wc, sizeof(WNDCLASSEX));

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = L"WindowClass";

RegisterClassEx(&wc);

hWnd = CreateWindowEx(NULL,
L"WindowClass",
L"Fullscreen Choice",
WS_OVERLAPPEDWINDOW,
300, 300,
800, 600,
NULL,
NULL,
hInstance,
NULL);

ShowWindow(hWnd, nCmdShow);

// set up and initialize Direct3D
initD3D(hWnd);

// enter the main loop:

MSG msg;

while(TRUE)
{
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

if(msg.message == WM_QUIT)
break;

render_frame();
}

// clean up DirectX and COM
cleanD3D();

return msg.wParam;
}


// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_KEYUP:
if(wParam == VK_ESCAPE)
PostQuitMessage(0);
break;

case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
} break;
}

return DefWindowProc (hWnd, message, wParam, lParam);
}


// this function initializes and prepares Direct3D for use
bool initD3D(HWND hWnd)
{
d3d = Direct3DCreate9(D3D_SDK_VERSION); // create the Direct3D interface

D3DDISPLAYMODE DisplayMode; // This object will allow us to set the display mode of the screen.

D3DPRESENT_PARAMETERS d3dpp; // create a struct to hold various device information

D3DCAPS9 D3DCaps; // Get capabilities of the hardware

ZeroMemory(&d3dpp, sizeof(d3dpp)); // clear out the struct for use

// Error checking. Make sure that it was successful.
if(d3d == NULL)
{
MessageBox(NULL, L"Error, couldn't initialize DirectX!?!",
L"Error!", MB_OK);
return false;
}

// This function will get the display mode of the device and place it in DisplayMode.
if(FAILED(d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &DisplayMode)))
{
MessageBox(NULL, L"Error setting the display mode.", L"Error!", MB_OK);
return false;
}

// Get the capabilities of the hardware.
if(FAILED(d3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &D3DCaps)))
{
return false;
}

// Test which is supported, hardware or software vertex processing.
DWORD VertexProcessing = 0;

if(D3DCaps.VertexProcessingCaps != 0)
VertexProcessing |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
else
VertexProcessing |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;

if(bFullScreen)
{
d3dpp.Windowed = FALSE;
d3dpp.BackBufferWidth = 800;
d3dpp.BackBufferHeight = 600;
d3dpp.BackBufferFormat = DisplayMode.Format;// Render to the area of the screen.
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // discard old frames
d3dpp.hDeviceWindow = hWnd; // set the window to be used by Direct3D

}
else

d3dpp.Windowed = TRUE; // program windowed, not fullscreen
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // discard old frames
d3dpp.BackBufferFormat = DisplayMode.Format;// Render to the area of the screen.
d3dpp.hDeviceWindow = hWnd; // set the window to be used by Direct3D


// create a device class using this information and the info from the d3dpp stuct
d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
VertexProcessing,
&d3dpp,
&d3ddev);
}


// this is the function used to render a single frame
void render_frame(void)
{
// clear the window to a deep blue
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);

d3ddev->BeginScene(); // begins the 3D scene

// do 3D rendering on the back buffer here

d3ddev->EndScene(); // ends the 3D scene

d3ddev->Present(NULL, NULL, NULL, NULL); // displays the created frame on the screen
}


// this is the function that cleans up Direct3D and COM
void cleanD3D(void)
{
d3ddev->Release(); // close and release the 3D device
d3d->Release(); // close and release Direct3D
}

Share this post


Link to post
Share on other sites
Advertisement
This is gonna be little help, I'm afraid. Made a project of your code and it goes fullscreen with blue background for me.

I haven't a clue if this will help but I also made a modification to your code to take it actual fullscreen:

// global variables
int nWidth = 800;
int nHeight = 600;
// in your winmain immediately after RegisterClassEx
if( bFullScreen )
{
RECT r;
GetClientRect(GetDesktopWindow(),&r);
nWidth = r.right-r.left;
nHeight = r.bottom-r.top;
}
// note changes to x,y,cx,cy
hWnd = CreateWindowEx(NULL,
"WindowClass",
"Fullscreen Choice",
WS_OVERLAPPEDWINDOW,
0, 0,
nWidth, nHeight,
NULL,
NULL,
hInstance,
NULL);
// in initD3D
// change if(bFullScreen) ..
d3dpp.BackBufferWidth = nWidth;
d3dpp.BackBufferHeight = nHeight;

EDIT:
Also, I think you intended curly brackets around:

else
{
d3dpp.Windowed = TRUE; // program windowed, not fullscreen
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // discard old frames
d3dpp.BackBufferFormat = DisplayMode.Format;// Render to the area of the screen.
d3dpp.hDeviceWindow = hWnd; // set the window to be used by Direct3D
}

Turns out it doesn't make a difference. Just letting you know.

Does the Debug Runtime tell you anything?

Share this post


Link to post
Share on other sites
Buckeye,
Thanks for having a look through my code for me. Your modifications work, and the program does what I expect it to now. Thanks, I can stop pulling my hair out now :).

Still a little puzzled as to why it wouldn't work on my computer yet it would on yours. I've tried 3 or 4 other tutorials for going full screen and they produced the same problem as the code I was using.


if( bFullScreen )
{
RECT r;
GetClientRect(GetDesktopWindow(),&r);
SCREEN_WIDTH = r.right-r.left;
SCREEN_HEIGHT = r.bottom-r.top;
}



Seems this code corrects the fault on my PC.

Thanks again

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!