Jump to content
  • Advertisement
Sign in to follow this  

[C++ DX] Back buffer sizing issue.

This topic is 3031 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

Hi there, I have a small problem in a C++ game of pong I am writing in DirectX.

I have a class GraphicsDevice which contains all the Dx Graphics setup and drawing code


class GraphicsDevice
CWindow* m_ParentWindow;

LPDIRECT3D9 d3dInterface;
int iBackbufferWidth, iBackbufferHeight;

CWindow* GetParentWindow(void) {return m_ParentWindow;}
GraphicsDevice* GetGraphics(void) {return this;}
LPDIRECT3D9 GetInterface(void) {return d3dInterface;}
LPDIRECT3DDEVICE9 GetDevice(void) {return d3dDevice;}

bool Create(CWindow* Window);

void BeginScene(Color clearColor, DWORD Flags = D3DCLEAR_TARGET);
bool EndScene(void);
void Shutdown(void);



bool GraphicsDevice::Create(CWindow* Window)
m_ParentWindow = Window;

d3dInterface = Direct3DCreate9(D3D_SDK_VERSION);

iBackbufferWidth = Window->GetWidth();
iBackbufferHeight = Window->GetHeight();

ZeroMemory(&d3dParams, sizeof(d3dParams));
d3dParams.Windowed = !Window->IsFullScreen();
d3dParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dParams.hDeviceWindow = m_ParentWindow->GetHandle();
d3dParams.BackBufferFormat = D3DFMT_UNKNOWN;
d3dParams.BackBufferWidth = iBackbufferWidth;
d3dParams.BackBufferHeight = iBackbufferHeight;

HRESULT Hr = d3dInterface->CreateDevice(

Window->GetLog()->WriteErrorMessage("Error Creating the D3DDevice in Graphics Device. Failed & Closing");
return false;
Window->GetLog()->WriteDebugMessaage("Created the GraphcisDevice Sucessfully, continuing ..");
return true;
void GraphicsDevice::BeginScene(Color clearColor, DWORD Flags)
d3dDevice->Clear(0, NULL,
Flags, clearColor.AsD3DColor(),
1.0f, 0);

bool GraphicsDevice::EndScene(void)
d3dDevice->Present(NULL, NULL, NULL, NULL);
return true;

Now, the problem is Problem

I am drawing a texture at 0,0 and this texture has a size of 800x600. and my graphicsDevice is 800x600 the D3DPRESENT_PARAMETERS width and height are 800x600. however I cannot see the whole texture as most of it is drawn off the screen?

am I supposed to have some kind of drawing rectanlge for the back buffer to clamp it? what i am doing wrong? any help appreciated xD

Share this post

Link to post
Share on other sites
How are you "drawing a texture at 0,0"? Textures are applied to 3D objects, not 2D. What is your projection matrix set up like?

Share this post

Link to post
Share on other sites
Hi Steve, thanks for the quick reply.

I load and hold my texture in a Texture class and then create a D3DXSPRITE (which is held in the Sprite Class)


class Sprite
GraphicsDevice* m_gdGraphics;
Texture* m_Texture;

LPD3DXSPRITE m_SpritePointer;
D3DXMATRIX m_SpriteMatrix;
Vector m_topLeftPosition;
Vector m_Center;
RECT m_CullingRect;

float m_Scale;
float m_Rotation;

bool Create(GraphicsDevice *Device);
bool Create(GraphicsDevice *Device, Texture *Texture);

bool Begin(void);
bool End(void);
bool Draw(Color color);


bool Sprite::Begin()
HRESULT result = m_SpritePointer->Begin(D3DXSPRITE_ALPHABLEND);

if(result == S_OK)
return true;
return false;

bool Sprite::End()
return true;
bool Sprite::Draw(Color color)
if(Begin()) //if we beging sucessfully

//Drawing Code
m_Texture->GetD3DTexture(), //Texture
NULL,//&m_CullingRect, //Drawing Rect

return End();
return false;

Share this post

Link to post
Share on other sites
1. What is your sprite's m_Center? Try passing NULL for the centre point paramteter to ID3DXSprite::Draw().
2. Are you sure the texture is 800x600, and it's not being resized? You'll need to pass D3DX_DEFAULT_NONPOW2 for the width and height to D3DXCreateTextureFromFileEx() to ensure that. You can call D3DXSaveTextureToFile to see what size it was loaded as.
3. When you create the window, do you call AdjustWindowRect() to ensure the client area size matches the backbuffer size?

Share this post

Link to post
Share on other sites
Ahh thanks steve :0

it seemed to be adding the function
that made it correct. Thank you

Also I changed my D3DXCreateTextureFromFileEx() width and high params to D3DX_DEFAULT_NONPOW2 from D3DX_DEFAULT;

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!