• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Daniel Bowler

Changing Screen Resolution and Windowed<->Full Screen Toggle

9 posts in this topic

Hi,

Long time admirer, first time poster.

Im currently in the process of making my own 2D DirectX9 / Direct3D Game Engine based off the one in Beginning Game Programming book. So far so good, but I have hit a bit of a brick wall with this one. Despite my googling, I cant seem to find much on these topics despite the fact that an awful lot of games allow the player the option to A) Toggle full screen mode (Alt+Enter) and B) Change the screen resolution.

A)

I understand how to easily set up my game to initially run in full screen mode or windowed mode by changing the D3DPRESENT PARAMS and changing a few settings in the CreateWindow function... But what I cant seem to do is give the user the option to press Alt+Enter in game to change to full screen.

I have read that I need to change the D3DPRESENT PARAMS and call Reset() via the Direct3D Device object... But this blew up my game and im not sure why.

To be honest, I may just force the player to use full screen mode for my game anyway... but it would be nice to have this option implemented within the game engine for future projects.

B)

This is the feature I really think I need to implement - and yet, I cant seem to find anything out there to help.

Currently I have a global const int that represents my Screen Height and Width. This is then used when creating the window and also in the D3DPRESENT PARAMS when creating the back buffer.

One other thing that has bugged me regarding resolution changes - How do you guys handle rendering? For example, say my window is of size 1024 by 768. Lets say I render my Texture (with the transformation matrix) at point 1024, 768 (centred) - This obviously renders right at the bottom right of the screen... but lets say the user changes the resolution settings to 1920 by 1080. That image is no longer rendered at the bottom right of the screen.

How would you guys suggest solving this problem? Do you change your rendering code so that you render at a percentage along X and down Y? EG: You render the same Texture at (100,100) and this would happily render the image at the bottom right of the screen no matter how the user has set his/her settings. Of course, this brings about another issue - the texture would still remain the same size in pixels as before the resolution change so you would end up with blank spaces in between textures (I plan to use tile maps)...

Or should I draw to a back buffer that is 1920 by 1080 and scale the surface down when rendering on screen??

Anyway... thanks for any help [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

EDIT1: Im also looking for some good open source DX9 Direct3D Game engines to have a look at - Afterall, this is the best way to learn a new tecnology. Ive been looking arround the forum and have seen some references to engine developed and available on the forum - but I cant seem to find any :(

EDIT2:This is GameMain - Handles directX init and the game loop.

[source lang="cpp"]#include "GameMain.h"
#include <iostream>

//Direct3D variables
LPDIRECT3D9 d3d = NULL;
LPDIRECT3DDEVICE9 d3ddev = NULL;
LPDIRECT3DSURFACE9 backbuffer = NULL;
LPD3DXSPRITE spriteHandler = NULL;

const string APPTITLE = "Game Engine - Windowed";
const int SCREENW = 1024;
const int SCREENH = 768;

//Game Loop
#define MAXIMUM_FRAME_RATE 60
#define MINIMUM_FRAME_RATE 15
#define UPDATE_INTERVAL (1.0 / MAXIMUM_FRAME_RATE)
#define MAX_CYCLES_PER_FRAME (MAXIMUM_FRAME_RATE / MINIMUM_FRAME_RATE)

//DX9 rendering engine set up
bool DirectXRenderingEngineInit(HWND window)
{
//initialize Direct3D
d3d = Direct3DCreate9(D3D_SDK_VERSION);
if (!d3d) return false;

//set Direct3D presentation parameters
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferWidth = SCREENW;
d3dpp.BackBufferHeight = SCREENH;
d3dpp.hDeviceWindow = window;

//create Direct3D device
d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);

if (!d3ddev) return false;

//get a pointer to the back buffer surface
d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
//Clear to black
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
//Init the sprite handler
D3DXCreateSprite(d3ddev, &spriteHandler);
return true;
}


void GameRun(HWND window)
{
//Game Loop will be handled here
//It is a Time based, fixed interval system
//Based off the system located here:
//sacredsoftware.net/tutorials/Animation/TimeBasedAnimation.xhtml

static double lastFrameTime = 0.0;
static double cyclesLeftOver = 0.0;
double currentTime;
double updateIterations;

//Get instance of the sharedInputManager - Basically init it here
static InputManager* sharedInputManager = InputManager::GetInstance(window);
//Get instance of the sharedGameController
static GameController* sharedGameController = GameController::GetInstance();
//Set initial scene if this is the first run through.
static bool hasInitialSceneBeenSet = false;
if (!hasInitialSceneBeenSet)
{
sharedGameController->SetInitialScene();
hasInitialSceneBeenSet = true;
}

//GAME LOOP
LARGE_INTEGER queryLargeInt;
QueryPerformanceCounter(&queryLargeInt);

currentTime = (double)queryLargeInt.QuadPart;

updateIterations = ((currentTime - lastFrameTime) + cyclesLeftOver);

if (updateIterations > (MAX_CYCLES_PER_FRAME * UPDATE_INTERVAL))
updateIterations = (MAX_CYCLES_PER_FRAME * UPDATE_INTERVAL);

while (updateIterations > UPDATE_INTERVAL)
{
updateIterations -= UPDATE_INTERVAL;
//Ask current scene to update logic
sharedGameController->UpdateCurrentSceneWithDelta(UPDATE_INTERVAL/MAX_CYCLES_PER_FRAME);
}

cyclesLeftOver = updateIterations;
lastFrameTime = currentTime;
//Render current scene
sharedGameController->RenderCurrentScene();
}

void GameEnd()
{
//Clean up DX
if (spriteHandler) spriteHandler->Release();
if (d3ddev) d3ddev->Release();
if (d3d) d3d->Release();
}[/source] Edited by Dbowler92
0

Share this post


Link to post
Share on other sites
Hi I'll try to answer your question

[quote name='Dbowler92' timestamp='1347171217' post='4978190']
I have read that I need to change the D3DPRESENT PARAMS and call Reset() via the Direct3D Device object... But this blew up my game and im not sure why.
[/quote]

That's true you have to call Reset(), but you have to keep some things in mind. Take a look at my enableFullScreen() function:
[source lang="cpp"]void D3DApp::enableFullScreenMode()
{

// Are we already in fullscreen mode?
if( !md3dPP.Windowed )
return;

int width = GetSystemMetrics(SM_CXSCREEN);
int height = GetSystemMetrics(SM_CYSCREEN);

md3dPP.BackBufferFormat = D3DFMT_X8R8G8B8;
md3dPP.BackBufferWidth = width;
md3dPP.BackBufferHeight = height;
md3dPP.Windowed = false;

// Reset the device with the changes.
onLostDevice();
HR(gd3dDevice->Reset(&md3dPP));
onResetDevice();
}[/source]
md3dPP is a D3DPRESENT_PARAMETERS (like the one you use to create the device).
Notice that before calling device->Reset() I call a method named onLostDevice() and after calling device->Reset() I call onResetDevice().
What onLostDevice() does is to prepare all your game assets (textures, meshes, etc) for a device resetting, for instance, any D3DAsset has to placed in what is called a memory pool, let's say you create a texture and you specify you're going to use de D3DPOOL_DEFAULT, in that case, objects placed in that pool need to be destroyed before calling device->Reset() and reinitialized after that. Some other objects like dynamic renderTargets need to be destroyed too. I suppose that's why you're game is crashing when you call Reset(), because you're not taking this into account. (In the previous example you can place your texture in the D3DPOOL_MANAGED so that you don't have to destroy the texture)

[quote name='Dbowler92' timestamp='1347171217' post='4978190']
How do you guys handle rendering? For example, say my window is of size 1024 by 768. Lets say I render my Texture (with the transformation matrix) at point 1024, 768 (centred) - This obviously renders right at the bottom right of the screen... but lets say the user changes the resolution settings to 1920 by 1080. That image is no longer rendered at the bottom right of the screen
[/quote]

That's true, for 2D objects you have to take into account the window size when you're rendering them, so if you were drawing your texture like this:
texture->Draw(0,0,1024,768)
Now you have to draw like this:
texture->Draw(0,0,1920,1080)

(The same goes with other 2D objects like plain Text)

For 3D objects you don't have to worry, the only thing you have to know is that when you change to a higher resolution you're going to see more things of your scene, i.e, your field of view is going to change to a bigger one (usually you specify a vertical field of view, so It's the horizontal field of view that changes). Edited by angelmu88
1

Share this post


Link to post
Share on other sites
[quote name='angelmu88' timestamp='1347179483' post='4978212']
Hi I'll try to answer your question

[quote name='Dbowler92' timestamp='1347171217' post='4978190']
I have read that I need to change the D3DPRESENT PARAMS and call Reset() via the Direct3D Device object... But this blew up my game and im not sure why.
[/quote]

That's true you have to call Reset(), but you have to keep some things in mind. Take a look at my enableFullScreen() function:
[source lang="cpp"]void D3DApp::enableFullScreenMode()
{

// Are we already in fullscreen mode?
if( !md3dPP.Windowed )
return;

int width = GetSystemMetrics(SM_CXSCREEN);
int height = GetSystemMetrics(SM_CYSCREEN);

md3dPP.BackBufferFormat = D3DFMT_X8R8G8B8;
md3dPP.BackBufferWidth = width;
md3dPP.BackBufferHeight = height;
md3dPP.Windowed = false;

// Reset the device with the changes.
onLostDevice();
HR(gd3dDevice->Reset(&md3dPP));
onResetDevice();
}[/source]
md3dPP is a D3DPRESENT_PARAMETERS (like the one you use to create the device).
Notice that before calling device->Reset() I call a method named onLostDevice() and after calling device->Reset() I call onResetDevice().
What onLostDevice() does is to prepare all your game assets (textures, meshes, etc) for a device resetting, for instance, any D3DAsset has to placed in what is called a memory pool, let's say you create a texture and you specify you're going to use de D3DPOOL_DEFAULT, in that case, objects placed in that pool need to be destroyed before calling device->Reset() and reinitialized after that. Some other objects like dynamic renderTargets need to be destroyed too. I suppose that's why you're game is crashing when you call Reset(), because you're not taking this into account. (In the previous example you can place your texture in the D3DPOOL_MANAGED so that you don't have to destroy the texture)

[quote name='Dbowler92' timestamp='1347171217' post='4978190']
How do you guys handle rendering? For example, say my window is of size 1024 by 768. Lets say I render my Texture (with the transformation matrix) at point 1024, 768 (centred) - This obviously renders right at the bottom right of the screen... but lets say the user changes the resolution settings to 1920 by 1080. That image is no longer rendered at the bottom right of the screen
[/quote]

That's true, for 2D objects you have to take into account the window size when you're rendering them, so if you were drawing your texture like this:
texture->Draw(0,0,1024,768)
Now you have to draw like this:
texture->Draw(0,0,1920,1080)

(The same goes with other 2D objects like plain Text)

For 3D objects you don't have to worry, the only thing you have to know is that when you change to a higher resolution you're going to see more things of your scene, i.e, your field of view is going to change to a bigger one (usually you specify a vertical field of view, so It's the horizontal field of view that changes).
[/quote]

Hi,

Many thanks for the detailed response :)

As you guessed, I had failed to release my game assets and that was causing the crash. I have, however, updraded my Texture2D and Surface2D classes so that they are all created in the MANAGED pool.

That has stopped the crashing - which is good, but right now when I press Alt+Tab, I end up with a white box that represents my drawing area. :/

[source lang="cpp"]void ChangeScreenMode(HWND window)
{
OutputDebugStringW(L"ChangeScreenmode\n");
if (isInWindowedMode)
{
OutputDebugStringW(L"To FS\n");
//Change to FS
spriteHandler->OnLostDevice();
d3dpp.Windowed = FALSE;
HRESULT hResult = d3ddev->Reset(&d3dpp);

SetWindowLong(d3dpp.hDeviceWindow, GWL_STYLE, WS_POPUPWINDOW);
SetWindowPos(d3dpp.hDeviceWindow, HWND_TOP, 0, 0, 0, 0,
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);

isInWindowedMode = false;
spriteHandler->OnResetDevice();
}
else
{
OutputDebugStringW(L"To Windowed\n");
//Change to Windowed
spriteHandler->OnLostDevice();
d3dpp.Windowed = TRUE;
d3ddev->Reset(&d3dpp);

SetWindowLong(d3dpp.hDeviceWindow, GWL_STYLE, WS_OVERLAPPEDWINDOW);
SetWindowPos(d3dpp.hDeviceWindow, HWND_TOP, 0, 0, SCREENW, SCREENH,
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);

isInWindowedMode = true;
spriteHandler->OnResetDevice();
}
}[/source]

This is the current function...

First things first - It should be noted that this function is ugly... ive yet to clear it up. Persoanlly, I prefer things to work before I make them look good/optimized. Second, the SetWindowsLong & Pos functions... I copied and pasted from google and as a result, far from finished.

Any idea why my beutiful black Direct3D window is replaced by an ugly white box??
0

Share this post


Link to post
Share on other sites
[quote name='Dbowler92' timestamp='1347187186' post='4978246']
[quote name='angelmu88' timestamp='1347179483' post='4978212']
Hi I'll try to answer your question

[quote name='Dbowler92' timestamp='1347171217' post='4978190']
I have read that I need to change the D3DPRESENT PARAMS and call Reset() via the Direct3D Device object... But this blew up my game and im not sure why.
[/quote]

That's true you have to call Reset(), but you have to keep some things in mind. Take a look at my enableFullScreen() function:
[source lang="cpp"]void D3DApp::enableFullScreenMode()
{

// Are we already in fullscreen mode?
if( !md3dPP.Windowed )
return;

int width = GetSystemMetrics(SM_CXSCREEN);
int height = GetSystemMetrics(SM_CYSCREEN);

md3dPP.BackBufferFormat = D3DFMT_X8R8G8B8;
md3dPP.BackBufferWidth = width;
md3dPP.BackBufferHeight = height;
md3dPP.Windowed = false;

// Reset the device with the changes.
onLostDevice();
HR(gd3dDevice->Reset(&md3dPP));
onResetDevice();
}[/source]
md3dPP is a D3DPRESENT_PARAMETERS (like the one you use to create the device).
Notice that before calling device->Reset() I call a method named onLostDevice() and after calling device->Reset() I call onResetDevice().
What onLostDevice() does is to prepare all your game assets (textures, meshes, etc) for a device resetting, for instance, any D3DAsset has to placed in what is called a memory pool, let's say you create a texture and you specify you're going to use de D3DPOOL_DEFAULT, in that case, objects placed in that pool need to be destroyed before calling device->Reset() and reinitialized after that. Some other objects like dynamic renderTargets need to be destroyed too. I suppose that's why you're game is crashing when you call Reset(), because you're not taking this into account. (In the previous example you can place your texture in the D3DPOOL_MANAGED so that you don't have to destroy the texture)

[quote name='Dbowler92' timestamp='1347171217' post='4978190']
How do you guys handle rendering? For example, say my window is of size 1024 by 768. Lets say I render my Texture (with the transformation matrix) at point 1024, 768 (centred) - This obviously renders right at the bottom right of the screen... but lets say the user changes the resolution settings to 1920 by 1080. That image is no longer rendered at the bottom right of the screen
[/quote]

That's true, for 2D objects you have to take into account the window size when you're rendering them, so if you were drawing your texture like this:
texture->Draw(0,0,1024,768)
Now you have to draw like this:
texture->Draw(0,0,1920,1080)

(The same goes with other 2D objects like plain Text)

For 3D objects you don't have to worry, the only thing you have to know is that when you change to a higher resolution you're going to see more things of your scene, i.e, your field of view is going to change to a bigger one (usually you specify a vertical field of view, so It's the horizontal field of view that changes).
[/quote]

Hi,

Many thanks for the detailed response [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

As you guessed, I had failed to release my game assets and that was causing the crash. I have, however, updraded my Texture2D and Surface2D classes so that they are all created in the MANAGED pool.

That has stopped the crashing - which is good, but right now when I press Alt+Tab, I end up with a white box that represents my drawing area. :/

[source lang="cpp"]void ChangeScreenMode(HWND window)
{
OutputDebugStringW(L"ChangeScreenmode\n");
if (isInWindowedMode)
{
OutputDebugStringW(L"To FS\n");
//Change to FS
spriteHandler->OnLostDevice();
d3dpp.Windowed = FALSE;
HRESULT hResult = d3ddev->Reset(&d3dpp);

SetWindowLong(d3dpp.hDeviceWindow, GWL_STYLE, WS_POPUPWINDOW);
SetWindowPos(d3dpp.hDeviceWindow, HWND_TOP, 0, 0, 0, 0,
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);

isInWindowedMode = false;
spriteHandler->OnResetDevice();
}
else
{
OutputDebugStringW(L"To Windowed\n");
//Change to Windowed
spriteHandler->OnLostDevice();
d3dpp.Windowed = TRUE;
d3ddev->Reset(&d3dpp);

SetWindowLong(d3dpp.hDeviceWindow, GWL_STYLE, WS_OVERLAPPEDWINDOW);
SetWindowPos(d3dpp.hDeviceWindow, HWND_TOP, 0, 0, SCREENW, SCREENH,
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);

isInWindowedMode = true;
spriteHandler->OnResetDevice();
}
}[/source]

This is the current function...

First things first - It should be noted that this function is ugly... ive yet to clear it up. Persoanlly, I prefer things to work before I make them look good/optimized. Second, the SetWindowsLong & Pos functions... I copied and pasted from google and as a result, far from finished.

Any idea why my beutiful black Direct3D window is replaced by an ugly white box??
[/quote]

Turns out that I had lost the back buffer [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

So the solution is like this - Again, not a clean bit of code

[source lang="cpp"]void ChangeScreenMode(HWND window)
{
OutputDebugStringW(L"ChangeScreenmode\n");
backbuffer->Release();
if (isInWindowedMode)
{
OutputDebugStringW(L"To FS\n");
//Change to FS
spriteHandler->OnLostDevice();
d3dpp.Windowed = FALSE;
HRESULT hResult = d3ddev->Reset(&d3dpp);

SetWindowLong(d3dpp.hDeviceWindow, GWL_STYLE, WS_EX_TOPMOST | WS_VISIBLE | WS_POPUP);
SetWindowPos(d3dpp.hDeviceWindow, HWND_TOP, 0, 0, SCREENW, SCREENH,
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);

isInWindowedMode = false;
spriteHandler->OnResetDevice();
}
else
{
OutputDebugStringW(L"To Windowed\n");
//Change to Windowed
spriteHandler->OnLostDevice();
d3dpp.Windowed = TRUE;
d3ddev->Reset(&d3dpp);

SetWindowLong(d3dpp.hDeviceWindow, GWL_STYLE, WS_OVERLAPPEDWINDOW);
SetWindowPos(d3dpp.hDeviceWindow, HWND_TOP, 0, 0, SCREENW, SCREENH,
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);

isInWindowedMode = true;
spriteHandler->OnResetDevice();
}
d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
completedTransition = true;
}[/source]

One last question regarding full screen mode...

My Textures and such render perfectly happily in Windowed mode - yet in full screen mode, they dont render at all... :S Any ideas?? (The same applies even if I start the game in full screen mode and then Alt+Enter to windowed mode where the textures appear again) Edited by Dbowler92
0

Share this post


Link to post
Share on other sites
[quote name='Dbowler92' timestamp='1347189347' post='4978258']
One last question regarding full screen mode...

My Textures and such render perfectly happily in Windowed mode - yet in full screen mode, they dont render at all... :S Any ideas?? (The same applies even if I start the game in full screen mode and then Alt+Enter to windowed mode where the textures appear again)
[/quote]

Can you post your drawing texture code. The only thing I can think of without seeing the code is that you might be using invalid coordinates, i.e, if the texture rendering method is something like this:
drawTextures(originX, originY, sizeX, sizeY)

(originX +sizeX) is out of the window.

Anyway, is this only happening with textures or is it happening also with 3d models? Edited by angelmu88
0

Share this post


Link to post
Share on other sites
[quote name='angelmu88' timestamp='1347193151' post='4978280']
[quote name='Dbowler92' timestamp='1347189347' post='4978258']
One last question regarding full screen mode...

My Textures and such render perfectly happily in Windowed mode - yet in full screen mode, they dont render at all... :S Any ideas?? (The same applies even if I start the game in full screen mode and then Alt+Enter to windowed mode where the textures appear again)
[/quote]

Can you post your drawing texture code. The only thing I can think of without seeing the code is that you might be using invalid coordinates, i.e, if the texture rendering method is something like this:
drawTextures(originX, originY, sizeX, sizeY)

(originX +sizeX) is out of the window.

Anyway, is this only happening with textures or is it happening also with 3d
models?
[/quote]

Hi. Currently I have no support for 3D models - I havent got to that point in the book yet and to be honest, I dont see myself implementing support just yet (2D Game engine only at the moment) so I cant test that just yet.

So at the moment, just textures. Surfaces - well, they dont support POOL_MANAGED so im basically giving up on them [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]

Here is my rendering code for Textures - Makes use of the Transfrom Matrix:

[source lang="cpp"]void Texture2D::RenderAtPointWithTransformations(int locationX, int locationY,
float scaleHorizontal,
float scaleVerticle,
float rotation,
D3DCOLOR color)
{

ManipulateMatrix(locationX, locationY, rotation,scaleHorizontal, scaleVerticle);
spriteHandler->SetTransform(&matrix);
spriteHandler->Draw(texture, NULL, NULL, NULL, color);
}

void Texture2D::RenderSubImageAtPointWithTransformations(RECT *subImage,
int locationX, int locationY,
float scaleHorizontal, float scaleVerticle,
float rotation,
D3DCOLOR color)
{
ManipulateMatrix(locationX, locationY, rotation,scaleHorizontal, scaleVerticle);
spriteHandler->SetTransform(&matrix);
spriteHandler->Draw(texture, subImage, NULL, NULL, color);
}

void Texture2D::RenderWithMatrix(D3DCOLOR color)
{
spriteHandler->SetTransform(&matrix);
spriteHandler->Draw(texture, NULL, NULL, NULL, color);
}

void Texture2D::RenderSubImageWithMatrix(RECT *subImage, D3DCOLOR color)
{
spriteHandler->SetTransform(&matrix);
spriteHandler->Draw(texture, subImage, NULL, NULL, color);
}



void Texture2D::ManipulateMatrix(int transX, int transY,float rotation, float scaleHorizontal, float scaleVerticle)
{
//Scale
D3DXVECTOR2 scale(scaleHorizontal, scaleVerticle);
//Centre point
D3DXVECTOR2 cent((float)(imageWidth * scaleHorizontal) / 2,
(float)(imageHeight * scaleVerticle) / 2);
//Translate (position) (centered)
D3DXVECTOR2 trans((float)transX-cent.x, (float)transY-cent.y);
//Non centered
//D3DXVECTOR2 trans((float)transX, (float)transY);
//Update the location points
locationX = transX;
locationY = transY;
//Fill matrix
D3DXMatrixTransformation2D(&matrix,NULL,0,&scale,&cent,rotation,&trans);
}
[/source]

EDIT: No luck with the non centered D3DXVECTOR trans(...) either

EDIT 2: This "¢" is actually &cent

EDIT 3: The rest of the rendering is:

This is called from my game loop
[source lang="cpp"]void GameController::RenderCurrentScene()
{
//Function renders current scene (calling Scene->Render();)
//Rendering - Will clear the backbuffer, BeginScene for rendering
//pass over to the currrent scene to render its bits and bobs (Surface2D/
//Texture2D will handle the rendering for the game objects and such),
//regain control and present the view.
//
//Clear backbuffer (black) (0,0,0)
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
d3ddev->BeginScene();
//Current scene will render
currentScene->RenderScene();
d3ddev->EndScene();
//Present backbuffer.
d3ddev->Present(NULL,NULL,NULL,NULL);
}[/source]

This then calls Render() on my current and active scene here:

[source lang="cpp"]void TestScene::RenderScene()
{
//Put your rendering code in here
//Its best if you abstract and ask each object in your
//game (A class) to render itself. (Eg, whilst your player could be represented
//by a Texture2D object (and you can use the Texture2D->Render(), it would be MUCH
//better to make a new Player Class so you can keep the scene code nice and
//streamlined.
//Somethings (EG, the background - a surface2D object) images could be created
//and rendered here rather than via a class)
//OutputDebugStringW(L"Rendering Current Scene \n");
//
//***RENDER SURFACES***
//(Note it is possible to render surfaces whilst rendering the
//texture - just unlock (End();) Direct3D - render - and lock (Begin();) again)
//
//Set up spriteHandler to allow for textures to be rendered. (lock)
//Default to use ALPHABLEND
spriteHandler->Begin(D3DXSPRITE_ALPHABLEND);
//***RENDER TEXTURES***
//Rendering
shuttle->RenderAtPointWithTransformations(1024,768);
ss->RenderSubImageFromSpriteSheet(1,2,100,100,rotation,1,1);
//sf->RenderAtPointWithTransformations(250,250);
//Clean up spriteHandler (unlock)
spriteHandler->End();
}[/source]

ss is a spritesheet object... which does no rendering and rather lets the Texture class do this.

EDIT4: (Ill stop editing soon xD)

So I have done some testing...

Where I clear my back buffer, I changed the code to:

[source lang="cpp"] d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(100,100,100), 1.0f, 0);[/source]

Which gives a nice grey background. However, in full screen... I still see a black background - this must be where my issues lie? Edited by Dbowler92
0

Share this post


Link to post
Share on other sites
[quote name='Dbowler92' timestamp='1347195175' post='4978287']
So I have done some testing...

Where I clear my back buffer, I changed the code to:

[source lang="cpp"] d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(100,100,100), 1.0f, 0);[/source]

Which gives a nice grey background. However, in full screen... I still see a black background - this must be where my issues lie?
[/quote]

Do you call device->Present() after drawing the scene. Your main Drawing method should look like this:
dd3dDevice->BeginScene();
//Here you draws all your textures
dd3dDevice->EndScene();
dd3dDevice->Present(0, 0, 0, 0);

When you're drawing in D3D you're drawing into something called back buffer. If you want to show the back buffer content on your screen you have to call the Present() method so that the buffer that is currently displaying swaps with the backbuffer.

As you point out, if you clear the backbuffer that way you shoud see a Grey Screen, not a black one, so the problem has probably nothing to do with your textures.
0

Share this post


Link to post
Share on other sites
[quote name='angelmu88' timestamp='1347203913' post='4978313']
[quote name='Dbowler92' timestamp='1347195175' post='4978287']
So I have done some testing...

Where I clear my back buffer, I changed the code to:

[source lang="cpp"] d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(100,100,100), 1.0f, 0);[/source]

Which gives a nice grey background. However, in full screen... I still see a black background - this must be where my issues lie?
[/quote]

Do you call device->Present() after drawing the scene. Your main Drawing method should look like this:
dd3dDevice->BeginScene();
//Here you draws all your textures
dd3dDevice->EndScene();
dd3dDevice->Present(0, 0, 0, 0);

When you're drawing in D3D you're drawing into something called back buffer. If you want to show the back buffer content on your screen you have to call the Present() method so that the buffer that is currently displaying swaps with the backbuffer.

As you point out, if you clear the backbuffer that way you shoud see a Grey Screen, not a black one, so the problem has probably nothing to do with your textures.
[/quote]

Hi,

Yeah I call present() [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

My rendering code is like so:

Device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0)
Device->BeginScene()

SpriteObject->Begin(D3DXSPRITE_ALPHABLEND)
//Rendering Textures
SpriteObject -> End()

Device->EndScene()
Device->Present(NULL,NULL,NULL,NULL)

Still no luck :( Edited by Dbowler92
0

Share this post


Link to post
Share on other sites
[quote name='Dbowler92' timestamp='1347264374' post='4978509']
[quote name='angelmu88' timestamp='1347203913' post='4978313']
[quote name='Dbowler92' timestamp='1347195175' post='4978287']
So I have done some testing...

Where I clear my back buffer, I changed the code to:

[source lang="cpp"] d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(100,100,100), 1.0f, 0);[/source]

Which gives a nice grey background. However, in full screen... I still see a black background - this must be where my issues lie?
[/quote]

Do you call device->Present() after drawing the scene. Your main Drawing method should look like this:
dd3dDevice->BeginScene();
//Here you draws all your textures
dd3dDevice->EndScene();
dd3dDevice->Present(0, 0, 0, 0);

When you're drawing in D3D you're drawing into something called back buffer. If you want to show the back buffer content on your screen you have to call the Present() method so that the buffer that is currently displaying swaps with the backbuffer.

As you point out, if you clear the backbuffer that way you shoud see a Grey Screen, not a black one, so the problem has probably nothing to do with your textures.
[/quote]

Hi,

Yeah I call present() [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

My rendering code is like so:

Device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0)
Device->BeginScene()

SpriteObject->Begin(D3DXSPRITE_ALPHABLEND)
//Rendering Textures
SpriteObject -> End()

Device->EndScene()
Device->Present(NULL,NULL,NULL,NULL)

Still no luck [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img]
[/quote]

Found a solution to the issue...

At home I use a two monitor set up - When I unplug one from the PC and run the program, everything happily renders both in windowed mode and full screen. So the issue is with the second monitor.

I havnt had chance to search for a fix yet (will do so now), but if anyone has any experience in fixing this particular issue - please feel free to share :)
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0