Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Changing Screen Resolution and Windowed<->Full Screen Toggle


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 Dbowler92   Members   -  Reputation: 166

Like
0Likes
Like

Posted 09 September 2012 - 12:13 AM

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 Posted Image

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 variablesLPDIRECT3D9 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 upbool 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, 09 September 2012 - 01:01 AM.


Sponsor:

#2 angelmu88   Members   -  Reputation: 228

Like
1Likes
Like

Posted 09 September 2012 - 02:31 AM

Hi I'll try to answer your question

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.


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)

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


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, 09 September 2012 - 02:35 AM.


#3 Dbowler92   Members   -  Reputation: 166

Like
0Likes
Like

Posted 09 September 2012 - 04:39 AM

Hi I'll try to answer your question


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.


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)

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


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).


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??

#4 Dbowler92   Members   -  Reputation: 166

Like
0Likes
Like

Posted 09 September 2012 - 05:15 AM


Hi I'll try to answer your question


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.


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)

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


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).


Hi,

Many thanks for the detailed response Posted Image

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??


Turns out that I had lost the back buffer Posted Image

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, 09 September 2012 - 05:27 AM.


#5 angelmu88   Members   -  Reputation: 228

Like
0Likes
Like

Posted 09 September 2012 - 06:19 AM

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)


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, 09 September 2012 - 06:22 AM.


#6 Dbowler92   Members   -  Reputation: 166

Like
0Likes
Like

Posted 09 September 2012 - 06:52 AM


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)


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?


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 Posted Image

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, 09 September 2012 - 07:20 AM.


#7 angelmu88   Members   -  Reputation: 228

Like
0Likes
Like

Posted 09 September 2012 - 09:18 AM

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?


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.

#8 Dbowler92   Members   -  Reputation: 166

Like
0Likes
Like

Posted 10 September 2012 - 02:06 AM


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?


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.


Hi,

Yeah I call present() Posted Image

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, 10 September 2012 - 02:06 AM.


#9 Dbowler92   Members   -  Reputation: 166

Like
0Likes
Like

Posted 10 September 2012 - 02:26 AM



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?


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.


Hi,

Yeah I call present() Posted Image

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 Posted Image


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 :)

#10 angelmu88   Members   -  Reputation: 228

Like
0Likes
Like

Posted 10 September 2012 - 06:50 AM

I'm glad you solved it.
I'm sorry but I don't know much about using two monitors.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS