In keeping with what I believe Mr Bigglesworth is referring to, here's some sample code with a ton of comments to explain what's happening when...
First, it sets the game's window size to match the current screen resolution. It does not use dbSetWindowOff() because that causes other problems that (to me anyway) you're not ready for. Unless you already have a means to detect and handle a user that uses alt+tab to switch to some other program during your game, you should avoid using dbSetWindowOff(). This sample provides an alternative to avoid those headaches...
Anyway, it then loads an image (currently set to "media\\background.jpg" but can be set to whatever image you want) and follows that with several calculations based on a few assumptons, the loaded image size and the full screen size...
After the calculations are complete, a 3D-Plane (plain) object is created, position and textured using the loaded image.
Finally, some global commands are used to satisfy the *assumptions* used during the calculations before entering the main loop (which itself simply plasters the image to the screen until the escape key is pressed)...
#include "DarkGDK.h"
// the main entry point for the application is this function
void DarkGDK ( void )
{
dbSyncOn();
dbSyncRate(0);
int display_width = GetSystemMetrics(0); /* Taking up the full desktop: how wide? */
int display_height = GetSystemMetrics(1); /* Taking up the full desktop: how tall? */
HDC hdc = GetDC(NULL); /* Current HDC of the GDK System Window */
int display_depth = GetDeviceCaps(hdc,12); /* What Pixel-Format (bit-depth) is it? */
ReleaseDC(NULL,hdc); /* Clean-up a little-bit */
dbSetWindowPosition(0,0); /* Move the Window to Top/Left Corner */
dbSetWindowLayout(0,0,0); /* Remove Border, Caption and Icon */
/* Set the display mode to match the current configuration of the desktop */
dbSetDisplayMode(display_width, display_height, display_depth);
/* Load the image you want to plaster across the screen */
dbLoadImage("media\\backdrop.jpg",1001);
/* Calculate the field-of-view (how wide of view angle) that the camera can see */
float cameraFOV=D3DXToDegree(D3DX_PI/2.905f); // ~62-degrees
/* Convert the display width/height values from int to float */
float screen_height=static_cast<float>(display_height);
float screen_width=static_cast<float>(display_width);
/* The ratio between the screen's width / height settings */
float aspect_ratio=screen_width / screen_height;
/* Now that we know the screen's height and camera's field-of-view, we can */
/* calculate how far away from the image the camera needs to be placed in */
/* order for the image to take up the entire screen-size */
float camera_distance=((screen_height*0.5f)/dbTan(cameraFOV*0.5f));
/* Retrieve the image's width and height values */
float img_width=static_cast<float>(dbGetImageWidth(1001));
float img_height=static_cast<float>(dbGetImageHeight(1001));
/* Calculate the scaled size values. Note: we will not be scaling the image */
/* directly. As you will see below, we use these values to define a 3D-Plane */
/* object using these calculated values */
float xsize_1001= img_width * (screen_width/img_width);
float ysize_1001= img_height * (screen_height/img_height);
/* On-Screen coordinates where to place the 3D-plane object */
float xpos_1001=0.0f, ypos_1001=0.0f;
/* Since we originally specified "on-screen" coordinates, they need to be */
/* converted from "screen-space" into "world-space" values. Here, we define */
/* the x/y-axis values and the camera_distance (above) defines the z-axis */
xpos_1001=(xpos_1001 - (screen_width/2.0f)) + (xsize_1001/2.0f);
ypos_1001=((ypos_1001 * -1) + (screen_height/2.0f)) - (ysize_1001/2.0f);
/* Make the 3D-plane that will take up the entire screen */
dbMakeObjectPlain(1001,xsize_1001,ysize_1001);
/* Place it at the world-coordinates so that it displays across the entire screen */
dbPositionObject(1001, xpos_1001, ypos_1001, camera_distance);
/* Texture it with the image that was loaded */
dbTextureObject(1001,1001);
/* Many of the calculations above were based upon a few assumptions */
/* about the camera. Those assumptions are as follows: */
/* -> It is at world-coordinate <x=0,y=0,z=0> (the origin) */
/* -> It is looking straight down the z-axis (into the monitor) */
/* -> Its field-of-view is what we have specified */
/* -> Its aspect ratio matches the screen's aspect ratio */
/* */
/* Set some global settings to coincide with those assumptions */
dbPositionCamera(0,0,0); /* Position camera at origin <0,0,0> */
dbRotateCamera(0,0,0); /* Look down z-axis (into monitor) */
dbSetCameraFOV(cameraFOV); /* field-of-view is ~62-degrees */
dbSetCameraAspect(aspect_ratio); /* aspect ratio matches the screen */
/* And finally, since the image is texturing a 3D-plane, we need to provide at */
/* least *some* light so that we can see the 3D-plane object when it is actually */
/* rendered. For this, we set the ambient-light to full strength (100%) */
dbSetAmbientLight(100);
while (LoopGDK())
{
dbSync();
}
return;
}
I know it may seem a bit overwhelming but it really isn't that bad once you understand what's happening. It illustrates two points from the posts above:
- How to set the game screen size to the player's current configuration, and;
- How to stretch an image (using 3D-Plains) across the full screen.
You can just copy/paste this code into a new project, change the image to be loaded and trace through the code using the debugger to get a better understanding of what's actually happening under-the-hood.
Hope this helps,
JTK