Archived

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

fireking

Quest for Directx

Recommended Posts

fireking    122
Ok, I've given up on creating a successful GDI engine, reason? Speed, like always..... Anyways, I've given Direct x a chance, and ive been studying the sdk very closely(direct x 7 a sdk)... But its very vague about some things, so i just want to check and see if what im doing is correct. I am creating a small 2d engine for use with Direct Draw. The engine class creates a window, creates direct draw, a primary surface, a clipper, and a back buffer surface. It also destroys them. I wanted to check and see if what im doing is correct. here is what i have so far: CLASS FFENGINE
  
class ffengine{
public:
	ffengine();
	~ffengine();

	HINSTANCE h;
	WNDCLASSEX w;
	WNDPROC winproc;
	char *CLASSNAME;
	char *WINDOWNAME;
	long winwidth;
	long winheight;
	HWND hwnd;
	HDC dc;

	LPDIRECTDRAW7 dd;
	LPDIRECTDRAWSURFACE7 primary;
	LPDIRECTDRAWSURFACE7 backbuffer;
	LPDIRECTDRAWCLIPPER clipper;
	DDSURFACEDESC2 pddsd;
	DDSURFACEDESC2 bddsd;
	long pwidth;
	long pheight;

	BOOL Create();
	void Destroy();
};
  
IMPLEMENTATION OF FFENGINE
  
ffengine::ffengine(){
	CLASSNAME="my class";
	WINDOWNAME="my window";
	winwidth=800;
	winheight=600;
}
ffengine::~ffengine(){
	h=NULL;
	memset(&w,0,sizeof(w));
	winproc=NULL;
	CLASSNAME="";
	WINDOWNAME="";
	winwidth=0;
	winheight=0;
	hwnd=NULL;
	dc=NULL;
	pwidth=0;
	pheight=0;
}
BOOL ffengine::Create(){
	//Create Window

	w.cbClsExtra=0;
	w.cbSize=sizeof(w);
	w.cbWndExtra=0;
	w.hbrBackground=(HBRUSH)COLOR_WINDOW;
	w.hCursor=LoadCursor(0,IDC_ARROW);
	w.hIcon=LoadIcon(0,IDI_WINLOGO);
	w.hInstance=h;
	w.lpfnWndProc=winproc;
	w.lpszClassName=CLASSNAME;
	w.lpszMenuName=0;
	w.nostyle=CS_VREDRAW|CS_HREDRAW;
	RegisterClassEx(&w);
	hwnd=CreateWindow(
		CLASSNAME,WINDOWNAME,
		WS_SYSMENU,
		0,0,
		winwidth,winheight,
		0,0,h,0);
	if(!hwnd){
		return FALSE;
	}
	SetFocus(hwnd);
	ShowWindow(hwnd,1);
	UpdateWindow(hwnd);
	dc=GetDC(hwnd);
	if(!dc){
		return FALSE;
	}
	//Create DirectDraw

	if(FAILED(DirectDrawCreateEx(NULL,(void **)&dd,IID_IDirectDraw7,NULL))){
		return FALSE;
	}
	if(FAILED(dd->SetCooperativeLevel(NULL,DDSCL_NORMAL))){
		return FALSE;
	}
	//Create Primary Surface (onscreen)

	memset(&pddsd,0,sizeof(pddsd));
	pddsd.dwSize=sizeof(pddsd);
	pddsd.dwFlags=DDSD_CAPS;
	pddsd.ddsCaps.dwCaps=DDSCAPS_PRIMARYSURFACE;
	if(FAILED(dd->CreateSurface(&pddsd,&primary,NULL))){
		return FALSE;
	}
	primary->GetSurfaceDesc(&pddsd);
	pwidth=pddsd.dwWidth;
	pheight=pddsd.dwHeight;
	//Create Clipper for Primary Surface

	if(FAILED(dd->CreateClipper(0,&clipper,NULL))){
		return FALSE;
	}
	if(FAILED(clipper->SetHWnd(0,hwnd))){
		return FALSE;
	}
	if(FAILED(primary->SetClipper(clipper))){
		return FALSE;
	}
	//Create BackBuffer Surface (offscreen)

	memset(&bddsd,0,sizeof(bddsd));
	bddsd.dwSize=sizeof(bddsd);
	bddsd.dwFlags=DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT;
	bddsd.ddsCaps.dwCaps=DDSCAPS_OFFSCREENPLAIN;
	bddsd.dwWidth=pwidth;
	bddsd.dwHeight=pheight;
	if(FAILED(dd->CreateSurface(&bddsd,&backbuffer,NULL))){
		return FALSE;
	}

	return TRUE;
}
void ffengine::Destroy(){
	if(backbuffer){
		backbuffer->Release();
		backbuffer=NULL;
	}
	if(primary){
		primary->Release();
		primary=NULL;
	}
	if(dd){
		dd->Release();
		dd=NULL;
	}
	UnregisterClass(CLASSNAME,h);
	ReleaseDC(hwnd,dc);
}
  
I know its a lot of code, but i just want to make sure that what i am doing is correct. A lot of the tutorials at game dev seem to be old (1999-2000), and often mention 1 mb video cards, palletes, and other things that have no meaning anymore (i have a low grade comp and my video card has 32mb, palletes are a thing of the past, 16bit and 32bit is the way to go). Also, I wanted to mention that the engine will not support full screen, its window mode only, because I am a strong believer of windowed mode Thanks, --Fireking Owner/Leader Genetics 3rd Dimension Development [edited by - fireking on September 30, 2002 10:43:31 PM]

Share this post


Link to post
Share on other sites
DrunkenHyena    805
Unfortunately it''s been too long since I''ve done DirectDraw to really comment on the code, but I do have a few things to say about your other comments.

The tutorials may be a little old, but so is DirectDraw. Nothing significant has changed from when those tutorials were written and now. Sure you have more resources, but the way you use DD will be the same.

Palettes are far from dead. I know a lot of 3D programmers who wish there was better support for palettes on 3D hardware.

By the way, a lot of people (many of whom I''m sure will get around to commenting) feel that DirectDraw is dead and no one should waste their time on it. Personally, if DD is a good fit for what you''re doing, I say go ahead. But keep in mind that when you''re looking back on "old" techniques, others are looking at your new development the same way. Perspective is rarely a bad thing.

Supporting windowed mode is nice. What about your users who feel strongly about fullscreen mode? Unless you''re trying to make some sort of politcal statement there is no good reason not to support both.

Just some thoughts. Good luck with your project.


Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
fireking    122
its not an engine for the masses, its for me basically, so it doesnt matter if i support full screen or whatever...

its an engine i intend, so far, to use to make one game. if i like how it goes ill use it over and over again, but i have no intensions of going to full screen at this time.

games like Ultima Online, which are windowed, is the direction im going, as far as engine goes. I guess all i have to figure out now is how to load bitmaps, and how to draw them, and im pretty much set (ive got tile system down already, from my previous project). The colorkey is going to be a real nice feature, instead of using masks and what not in the GDI. I am also looking forward to the speed. I was achieving 30 on GDI with a 672x472 pixel display (Centered on 800x600, 64 pixels of space on each side of the rendered rectangular area). And now maybe i wont be hassled so much about using the GDI.

I think its funny that i take the big step from GDI to DD, and still people think dd is old. Dd isnt old! It may be old looking at it from the time point of view, but its not old according to what it does. It lets you access the video memory, and move the memory around in the video card, how can that be considered old or whatever? Plus, making a 2d game in a "3d world" so to speak, isnt my idea of being effecient. Sure it can be utilized to be even faster, but you can achieve required speed in Direct Draw, look at all the games that was made on it.

I am done babbling, anyone care to comment on my code?

Thanks,


--Fireking

Owner/Leader
Genetics 3rd Dimension Development

Share this post


Link to post
Share on other sites