Archived

This topic is now archived and is closed to further replies.

Chrisz_6

DirectDraw - Speedups?

Recommended Posts

Hey there, I was reading the forums 1-2 days ago, saw a post about someway to speed up direct draw.. i tried searching, thats WAY TOO slow, I think its either broken, or its really laggy. Anyone have any ideas how to speed directdraw up? Some games go well into the hundreds for their FPS, my VB app, not even drawing anything, 76 FPS -_- -Chrisz [edited by - Chrisz_6 on October 13, 2003 1:52:05 PM] [edited by - Chrisz_6 on October 13, 2003 1:57:28 PM]

Share this post


Link to post
Share on other sites
If you would have spent any time searching for VSYNC you would have found something similar to this

D3DPRESENT_PARAMATERS Parms;

then when creating the device, make sure this line is there.

Parms.PresentationInterval=D3DPRESENT_INTERVAL_IMMEDIATE;

Share this post


Link to post
Share on other sites
My recommendation may seem a bit radical at first but it''s to simply not use DD. I began by trying to use it and it seemed to efficiently kill my framerate. My solution is to use alpha-blended quads with D3D. If you''re intrested in trying it out, I''ve already stuffed it into a pretty little class.
Bitmap.h:

#include <string>
using namespace std;
class CBitmap
{
public:
int m_x, m_y;
D3DCOLOR m_ColorKey;
bool m_AlwaysSolid;
LPDIRECT3DVERTEXBUFFER9 m_VB;
int m_Width, m_Height;
LPDIRECT3DTEXTURE9 m_Texture;
string m_strFileName;
bool m_bInitialized;
void Init();
public:
CBitmap();
CBitmap(char* strFileName);
CBitmap(char* strFileName, D3DCOLOR ColorKey);
CBitmap(char* strFileName, D3DCOLOR ColorKey, int x, int y);
void LoadNewFile(char* strFileName);
void Render();
void ReloadVerts();
};

Bitmap.cpp:

#include <Windows.h>
#include <mmsystem.h>
#include <d3dx9.h>
#include <fstream.h>
#include <d3dx9core.h>
#include <stdlib.h>
#include <stdio.h>
#include <string>
using namespace std;
#include "bitmap.h"
LPDIRECT3D9 extern g_pD3D;
LPDIRECT3DDEVICE9 extern g_pd3dDevice;
int extern DEVICEWIDTH;
int extern DEVICEHEIGHT;
int g_DeviceWidth = DEVICEWIDTH;
int g_DeviceHeight = DEVICEHEIGHT;

struct BITMAPVERTEX
{
D3DXVECTOR4 position;
FLOAT tu, tv;
};
#define D3DFVF_BITMAPVERTEX (D3DFVF_XYZRHW|D3DFVF_TEX1)

CBitmap::CBitmap()
{
m_VB = NULL;
m_Texture = NULL;
m_Width = m_Height = m_x = m_y = m_ColorKey = m_AlwaysSolid = NULL;
m_strFileName = "";
}
CBitmap::CBitmap(char* strFileName)
{
m_VB = NULL;
m_Texture = NULL;
m_Width = m_Height = m_x = m_y = m_ColorKey = m_AlwaysSolid = NULL;
m_strFileName = strFileName;
}
CBitmap::CBitmap(char* strFileName, D3DCOLOR ColorKey)
{
m_VB = NULL;
m_Texture = NULL;
m_Width = m_Height = m_x = m_y = m_AlwaysSolid = NULL;
m_ColorKey = ColorKey;
m_strFileName = strFileName;
}
CBitmap::CBitmap(char* strFileName, D3DCOLOR ColorKey, int x, int y)
{
m_VB = NULL;
m_Texture = NULL;
m_Width = m_Height = m_AlwaysSolid = NULL;
m_x = x;
m_y = y;
m_ColorKey = ColorKey;
m_strFileName = strFileName;
}
void CBitmap::Init()
{
HBITMAP hBitmap;
BITMAP Bitmap;
hBitmap = (HBITMAP)LoadImage(NULL, m_strFileName.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
if(hBitmap == NULL)
return;
GetObject(hBitmap, sizeof(BITMAP), &Bitmap);
DeleteObject(hBitmap);
m_Width = Bitmap.bmWidth;
m_Height = Bitmap.bmHeight;

D3DXCreateTextureFromFileEx(g_pd3dDevice, m_strFileName.c_str(), m_Width, m_Height, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, m_ColorKey, NULL, NULL, &m_Texture);
if(m_VB != NULL)
m_VB->Release();
g_pd3dDevice->CreateVertexBuffer( 4*sizeof(BITMAPVERTEX), 0, D3DFVF_BITMAPVERTEX, D3DPOOL_DEFAULT, &m_VB, NULL );
BITMAPVERTEX* pVertices;
m_VB->Lock( 0, 0, (void**)&pVertices, 0 );
pVertices[0].position = D3DXVECTOR4((float)(m_x), (float)(m_y), 0.5f, 1.0f);
pVertices[1].position = D3DXVECTOR4((float)(m_x + m_Width), (float)(m_y) , 0.5f, 1.0f);
pVertices[2].position = D3DXVECTOR4((float)(m_x), (float)(m_y + m_Height), 0.5f, 1.0f);
pVertices[3].position = D3DXVECTOR4((float)(m_x + m_Width), (float)(m_y + m_Height), 0.5f, 1.0f);
pVertices[0].tu = 0.0f;
pVertices[0].tv = 0.0f;
pVertices[1].tu = 1.0f;
pVertices[1].tv = 0.0f;
pVertices[2].tu = 0.0f;
pVertices[2].tv = 1.0f;
pVertices[3].tu = 1.0f;
pVertices[3].tv = 1.0f;
m_VB->Unlock();
m_bInitialized = true;
}
void CBitmap::Render()
{
if(!m_bInitialized)
{
Init();
}
DWORD prevfill;
g_pd3dDevice->GetRenderState( D3DRS_FILLMODE, &prevfill );
g_pd3dDevice->SetStreamSource( 0, m_VB, 0, sizeof(BITMAPVERTEX) );
g_pd3dDevice->SetFVF( D3DFVF_BITMAPVERTEX );
g_pd3dDevice->SetTexture(0, m_Texture);
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
if(m_AlwaysSolid)
g_pd3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );

g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

g_pd3dDevice->SetRenderState( D3DRS_FILLMODE, prevfill );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, 4 );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, 2 );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, 2 );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, 2 );
g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO);
g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
}
void CBitmap::ReloadVerts()
{
if(!m_bInitialized)
return;
BITMAPVERTEX* pVertices;
m_VB->Lock( 0, 0, (void**)&pVertices, 0 );
pVertices[0].position = D3DXVECTOR4((float)(m_x), (float)(m_y), 0.5f, 1.0f);
pVertices[1].position = D3DXVECTOR4((float)(m_x + m_Width), (float)(m_y) , 0.5f, 1.0f);
pVertices[2].position = D3DXVECTOR4((float)(m_x), (float)(m_y + m_Height), 0.5f, 1.0f);
pVertices[3].position = D3DXVECTOR4((float)(m_x + m_Width), (float)(m_y + m_Height), 0.5f, 1.0f);
pVertices[0].tu = 0.0f;
pVertices[0].tv = 0.0f;
pVertices[1].tu = 1.0f;
pVertices[1].tv = 0.0f;
pVertices[2].tu = 0.0f;
pVertices[2].tv = 1.0f;
pVertices[3].tu = 1.0f;
pVertices[3].tv = 1.0f;
m_VB->Unlock();
}

With it all you have to do is:
CBitmap MyBitmap("bitmap.bmp", D3DCOLOR_XRGB(255, 0, 255), 0, 0);
and then call
MyBitmap.Render();
in your render loop. The Initializer is CBitmap(char* filename, D3DCOLOR ColorKey, int x, int y).

Good luck

Share this post


Link to post
Share on other sites
quote:
Original post by RhoneRanger
If you would have spent any time searching for VSYNC you would have found something similar to this

D3DPRESENT_PARAMATERS Parms;

then when creating the device, make sure this line is there.

Parms.PresentationInterval=D3DPRESENT_INTERVAL_IMMEDIATE;


He''s using DirectDraw not Direct3D.

For DirectDraw use the DDFLIP_NOVSYNC flag when flipping your surfaces.

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

Share this post


Link to post
Share on other sites