Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Direct Draw back buffer problem

Status
Not open for further replies.

Rouslan

Technical User
Sep 7, 2002
27
CA
I am new at using directX and am clueless as to why my GetAttachedSurface returns an error. This program works just fine with only one surface. I have included my WinMain function.

Code:
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
					 LPSTR lpCmdLine, int nCmdShow)
{
	DDSURFACEDESC2 ddsd;
	HRESULT hRet;

	MSG msg;
	HWND hWnd;
	WNDCLASS wc;

	LONGLONG cur_time;
	DWORD time_count;
	LONGLONG perf_cnt;
	bool perf_flag=false;
	LONGLONG next_time=0;
	LONGLONG last_time=0;
	double time_elapsed;
	double time_scale;

	wc.style		=CS_HREDRAW|CS_VREDRAW;
	wc.lpfnWndProc	=(WNDPROC)WindowProc;
	wc.cbClsExtra	=0;
	wc.cbWndExtra	=0;
	wc.hInstance	=hInstance;
	wc.hIcon		=LoadIcon(hInstance,"Rouslan");
	wc.hCursor		=LoadCursor(NULL,IDC_ARROW);
	wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
	wc.lpszMenuName	=MAKEINTRESOURCE(IDR_MENU1);
	wc.lpszClassName="Rouslan";
	if(!RegisterClass(&wc))return false;

	if(QueryPerformanceFrequency((LARGE_INTEGER*)&perf_cnt))
	{
		perf_flag=true;
		time_count=perf_cnt/30;
		QueryPerformanceCounter((LARGE_INTEGER*)&next_time);
		time_scale=1.0/perf_cnt;
	}else{
		next_time=timeGetTime();
		time_scale=0.001;
		time_count=33;
	}
	last_time=next_time;

	hInst=hInstance;

	hWnd = CreateWindow(lpszAppName,lpszTitle,WS_POPUP,0,0,
		GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),NULL,NULL,hInstance,NULL);

	if(!hWnd)return false;

	ShowWindow(hWnd,nCmdShow);
	UpdateWindow(hWnd);

	hRet=DirectDrawCreateEx(NULL,(LPVOID*)&lpDD,IID_IDirectDraw7,NULL);
	if(hRet != DD_OK)return false;

	hRet = lpDD->SetCooperativeLevel(hWnd,DDSCL_FULLSCREEN|DDSCL_EXCLUSIVE);
	if(hRet != DD_OK)return false;

	hRet = lpDD->SetDisplayMode(640,480,16,0,0);

	/*hRet=lpDD->CreateClipper(NULL,&lpClip,NULL);
	if(hRet != DD_OK)
	{
		ErrStr=Err_CreateClip;
		return false;
	}
	lpClip->SetHWnd(0,hWnd);*/

	ZeroMemory(&ddsd,sizeof(ddsd));
	ddsd.dwSize = sizeof(ddsd);
	ddsd.dwFlags = DDSD_CAPS|DDSD_BACKBUFFERCOUNT;
	ddsd.dwBackBufferCount=1;
	ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_FLIP|DDSCAPS_COMPLEX;
	hRet=lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL);
	if(hRet != DD_OK)return false;

	/////////GOOD UP TO HERE///////////

	DDSCAPS2 ddscaps;
	ddscaps.dwCaps=DDSCAPS_BACKBUFFER;
	hRet=lpDDSPrimary->GetAttachedSurface(&ddscaps,&lpDDSBack);
	if(hRet!=DD_OK)
	{
		MessageBox(hWnd,"This message gets called","Hmm",MB_OK);
		return false;
	}

	/////////BREAK DOWN HERE///////////
	

	//lpDDSPrimary->SetClipper(lpClip);
	bInit=true;

	GAME.SetWndData(&hWnd,&hInst);

	while(true)
	{
		if(PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
		{
			if(!GetMessage(&msg,NULL,0,0))return msg.wParam;
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}else{
			if(perf_flag)QueryPerformanceCounter((LARGE_INTEGER*)&cur_time);
			else cur_time=timeGetTime();

			if(cur_time>next_time)
			{
				time_elapsed=(cur_time-last_time)*time_scale;
				last_time=cur_time;
				GAME.Action();
				SCREEN.DrawScreen(&GAME,&hWnd);
				next_time=cur_time+time_count;
			}
		}
	}
	return(msg.wParam);
}
 
Well I'm not really sure, this is just a gues:

Three lines after [tt]/////////GOOD UP TO HERE///////////[/tt], try inserting

[tt]ddsCaps.dwCaps2 = 0;[/tt]

The DDSCAPS structure actually has 4 members, (only [tt]dwCaps[/tt] and [tt]dwCaps2[/tt] are used, though.) Since [tt]dwCaps2[/tt] wasn't getting initialized, it probably had a random value like [tt]0xCCCCCCCC[/tt], which could cause [tt]GetAttachedSurface[/tt] to fail when it tries to get a back buffer with a whole bunch of capabilities declared in [tt]dwCaps2[/tt].

Sorry if it doesn't work, this is just my guess-- I've actually been off the DirectDraw7 scene since DirectX 8 came out, so I'm a bit rusty in that subject.

Happy gaming
 
Thanks for trying but that didn't help. Anyways when I checked which error message it turned out to be DDERR_NOTFOUND. That seems strange to me.
 
Never mind. I just switched to Direct X 8 and couldn't be happier.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top