Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


MartinSmith160

Member Since 28 Mar 2012
Offline Last Active Jun 19 2013 02:09 AM

Topics I've Started

Improving loading times for 2D animations in Directx

28 May 2013 - 04:39 AM

Hi Guys,

 

I was wandering if you could help me. I have a 2D game built using directx 9 and its all working fine. I would however like to reduce the load time for the game as there is a substantial amount of graphics to load. My sprite class uses LPDIRECT3DTEXTURE9 for the images and an image is loaded using D3DXGetImageInfoFromFile().

 

This approach works perfectly its just I have some animations that have a large number of large individual frames to load. This increases the load time and the size of the overall game by quite a bit. I was looking at a way to replace these animations with some form of flash animation sequence but i cant find a way to maintain the transparency of a flash animation in directx. 

 

Any help of this would be greatly appreciated,

 

All the best,

Martin


Horizontal Tearing problem with DirectX 9 2D

18 September 2012 - 01:33 AM

Hi Guys

Im having a strange problem that I would appreciate some help with. I have wrote a simple 2D DirectX 9 GameEngine and all is up and running. There is one problem with it though. When I move a sprite around the window tearing occurs frequently. Its like one half of the sprite is drawn in the old coordinates and the rest in the new position.

I thought this was simple a double buffering issue but I have already set up double buffering to work. Here is the code for setting up the device and the back buffer.

[source lang="cpp"]D3DDISPLAYMODE dm; LPDIRECT3DDEVICE9 newDevice; LPDIRECT3DSURFACE9 newbackbuffer; LPD3DXSPRITE new_sprite_handler; this->d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dm); //set configuration options for Direct3D D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = !targetWindow->IsFullScreen(); d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D16; d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; d3dpp.BackBufferFormat = dm.Format; d3dpp.BackBufferCount = 1; d3dpp.BackBufferWidth = clientWindowRect.right; d3dpp.BackBufferHeight = clientWindowRect.bottom; d3dpp.hDeviceWindow = targetWindow->GetHWND(); //create Direct3D device this->d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, targetWindow->GetHWND(), D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &newDevice); newDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_RGBA(0,0,0,255), 1.0f, 0); if(newDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &newbackbuffer) != D3D_OK) st_engine->LogError("BackBuffer Failed to create");[/source]

Is there anything im missing here. I tried changing the backbuffer count down to 0 so it should be single buffered and it looks the same. That implies to me that even tho im saying use double buffering its not. Any help on this would be greatly appreciated.

Thanks in advance,
Martin.

How to create a reusable triangle class in directX 9.0

28 June 2012 - 03:36 AM

Hi All,

I have created a 2D DirectX 9.0 game engine and the last thing I need to add to is is the ability to draw triangle primitives. I wrote a class after looking at a number of tutorials. The code compiles fine but nothing is ever drawn to the screen.

Here is the Header:

[source lang="cpp"]typedef struct d3dVert { float x,y,z,rhw; DWORD color; }D3DVERTEX;class ST_Prim_Triangle { private: LPDIRECT3DVERTEXBUFFER9 vertex_object; void * vertex_buffer; D3DVERTEX vertices[3]; ST_Window *targetWindow; public: ST_Prim_Triangle(); ~ST_Prim_Triangle(); bool Create(ST_Window *targetWindow, ST_Point2f p1, ST_Point2f p2, ST_Point2f p3, D3DCOLOR col = D3DCOLOR_XRGB(255,0,0)); bool Draw(); }; //class[/source]

Here is the implementation:

[source lang="cpp"]ST_Prim_Triangle::ST_Prim_Triangle() { vertices[0].x = 0.0f; vertices[0].y = 0.0f; vertices[0].z = 0.0f; vertices[0].rhw = 1.0f; vertices[1].x = 0.0f; vertices[1].y = 0.0f; vertices[1].z = 0.0f; vertices[1].rhw = 1.0f; vertices[2].x = 0.0f; vertices[2].y = 0.0f; vertices[2].z = 0.0f; vertices[2].rhw = 1.0f; vertex_object = NULL; vertex_buffer = NULL; } ST_Prim_Triangle::~ST_Prim_Triangle() { vertex_object->Release(); vertex_buffer = 0; targetWindow = 0; } bool ST_Prim_Triangle::Create(StormEngine::ST_Window *targetWindow, StormEngine::ST_Point2f p1, StormEngine::ST_Point2f p2, StormEngine::ST_Point2f p3, D3DCOLOR col) { this->targetWindow = targetWindow; vertices[0].x = p1.x; vertices[0].y = p1.y; vertices[0].z = 0.0f; vertices[0].rhw = 1.0f; vertices[0].color = col; vertices[1].x = p2.x; vertices[1].y = p2.y; vertices[1].z = 0.0f; vertices[1].rhw = 1.0f; vertices[1].color = col; vertices[2].x = p3.x; vertices[2].y = p3.y; vertices[2].z = 0.0f; vertices[2].rhw = 1.0f; vertices[2].color = col; if(FAILED(targetWindow->GetWindowDevice()->CreateVertexBuffer(3*sizeof(D3DVERTEX), 0, D3DFVF_XYZRHW|D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &vertex_object, NULL))) { return(0); } if(FAILED(vertex_object->Lock(0, 3*sizeof(D3DVERTEX), &vertex_buffer, 0))) return(0); memcpy(vertex_buffer, vertices, 3*sizeof(D3DVERTEX)); vertex_object->Unlock(); return true; } bool ST_Prim_Triangle::Draw() { targetWindow->GetWindowDevice()->SetStreamSource(0, vertex_object, 0, sizeof(D3DVERTEX)); targetWindow->GetWindowDevice()->SetFVF(D3DFVF_XYZRHW|D3DFVF_DIFFUSE); targetWindow->GetWindowDevice()->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); return true; }[/source]

Im not really sure where im going wrong with this, any help would be so greatly appreciated as its the last aspect of the engine to finish.

Thanks in advance.

All the best,
Martin

Creating a DirectX 9.0 window class in C++

08 June 2012 - 03:08 AM

Hi All

I have read through Advanced2D development by J Harbour in which you create a 2D directX 9.0 game engine. The engine is based around a single window.

I was planning on doing it the following way but im not sure its the correct approach:

  • Write a window class that has all the parameters to allow creation of different types and styles of window
  • Each window will have its own D3D device
  • Each window will be registered with windows
  • Each window will have its own rendering portion, so each sprite on its draw command will pass in it's D3D device (like a GC in openGL)

This is what I plan to do but im not sure about handling the rendering properly. I also can never know how many windows a user could create so I am going to add them to a vector and then iterate over each whilst processing. I haven't really thought about sound yet.

My question is, is there anything blindingly I have missed out or really need to think about before I start this.

Thanks guys,

All the best,
Martin

DirectX Performance issues when using different window style

21 May 2012 - 08:48 AM

Hi All,

I have wrote a simple DirectX 2D game engine and im having some issues when running the game applications on different computers. I developed the engine and demos on a windows 7 dual core with an NVIDIA GeForce GT 520. I can run the game over two monitors and its performance is 60+ FPS.

The platform I need to run my games on is a dual core, XP system with an ATi HD 3200 across dual monitors. I setup the games to look fullscreen by using the WS_POPUP window style, using one window which is 2048 x 768 running on a 1024 x 768 resolution.

This works brilliant on my computer but im having some issues on other computers.

The problems I am having are:
  • If I use WS_POPUP the first monitor is just a black screen
  • If I use WS_POPUPWINDOW it works and draws to both monitors but its really slow
  • If I set the game to not be borderless, E.g use WS_OVERLAPPEDWINDOW instead, the performace shoots up from around 10 FPS to 25 FPS but it no longer looks fullscreen.

This is my window style setup code:


if (g_engine->getFullscreen())
{
DEVMODE dm;
memset(&dm, 0, sizeof(dm));
dm.dmSize = sizeof(dm);
dm.dmPelsWidth = g_engine->getScreenWidth();
dm.dmPelsHeight = g_engine->getScreenHeight();
dm.dmBitsPerPel = g_engine->getColorDepth();
dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

if (ChangeDisplaySettings(&dm, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
MessageBox(NULL, "Display mode failed", NULL, MB_OK);
g_engine->setFullscreen(false);
}

dwStyle = WS_POPUP;
dwExStyle = WS_EX_APPWINDOW;
ShowCursor(FALSE);
}
else if(g_engine->getBorderless())
{
dwStyle = WS_POPUP;
dwExStyle = WS_EX_APPWINDOW | WS_EX_TOPMOST ;
}
else {
dwStyle = WS_OVERLAPPEDWINDOW;
dwExStyle = WS_EX_APPWINDOW | WS_EX_TOPMOST ;
}

Im very confused with these issues and any help would be greatly appreciated.

Thanks,
Martin

PARTNERS