Jump to content
  • Advertisement
Sign in to follow this  
Andy474

[C++ DX] Back buffer sizing issue.

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


GraphcisDevice.h

class GraphicsDevice
{
protected:
CWindow* m_ParentWindow;

private:
LPDIRECT3D9 d3dInterface;
LPDIRECT3DDEVICE9 d3dDevice;
D3DPRESENT_PARAMETERS d3dParams;
int iBackbufferWidth, iBackbufferHeight;

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


GraphicsDevice(void);
~GraphicsDevice(void);
};


GraphicsDevice.cpp

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(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
m_ParentWindow->GetHandle(),
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dParams,
&d3dDevice);

if(FAILED(Hr))
{
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);

d3dDevice->BeginScene();
}
bool GraphicsDevice::EndScene(void)
{
d3dDevice->EndScene();
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
Advertisement
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)

sprite.h

class Sprite
{
protected:
GraphicsDevice* m_gdGraphics;
Texture* m_Texture;

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




sprite.cpp

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

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

}
bool Sprite::End()
{
m_SpritePointer->End();
return true;
}
bool Sprite::Draw(Color color)
{
//m_Scale;
//m_Rotation;
//m_SpriteMatrix
if(Begin()) //if we beging sucessfully
{

//Drawing Code
m_SpritePointer->Draw(
m_Texture->GetD3DTexture(), //Texture
NULL,//&m_CullingRect, //Drawing Rect
&m_Center.GetAsD3DVect3(),
&m_topLeftPosition.GetAsD3DVect3(),
color.AsD3DColor());

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!