Jump to content
  • Advertisement

Archived

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

Metus

ZBuffering ... Again

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

Ok...I'm MAD!!! I've tried to create a ZBuffer for about 2 days now using Direct3D IM and i can't get it to work... Am I to stupid or what? Can't i use Buffering when I'm using Pageflipping? Anyway..here's the ZBuffer part of my code: SurfaceDesc.dwSize = sizeof(DDSURFACEDESC2); SurfaceDesc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_ZBUFFERBITDEPTH; SurfaceDesc.dwWidth = Width; SurfaceDesc.dwHeight = Height; SurfaceDesc.ddpfPixelFormat.dwZBufferBitDepth = 16; SurfaceDesc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_SYSTEMMEMORY; if(DirectDraw->CreateSurface(&SurfaceDesc, &ZBuffer, NULL) != DD_OK) MessageBox(hWnd, "CreateSurface Failed", "Direct3D Error", MB_OK | MB_ICONERROR); Observe that I've tried to replace the DDSD_ZBUFFERBITDEPTH with DDSD_PIXELFORMAT I've tried to use all the examples i've found on the net, but none of them works...perhaps my MAtrox G400 suxx... So I'm beggin you: Do you got a working example when using ZBuffering that you can give me..please? sincerely Patrik Wixner Edited by - Metus on 8/28/00 1:38:19 PM

Share this post


Link to post
Share on other sites
Advertisement
Well, I think some Zbuffers have to be in Video memory:

SurfaceDesc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY;


Then add this:

SurfaceDesc.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
SurfaceDesc.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;


Jim Adams


Share this post


Link to post
Share on other sites
Hi.

First of all when you try for the first time to make a ZBuffer make sure you have some code who work, to loock at. Whith DX7 IM when creating a zbuff you have to check for the pixel format, validate the DDSD_PIXELFORMAT on the dwFlag field, load the ddpfPixelFormat with the pixel format you checked for, set memory destination(video for IID_IDirect3DHALDevice or IID_IDirect3DTnHALDevice and system for IID_IDirect3DRGB) then create the ZBuffer and attach it to the rendering surface. You should do this before seting the device or you should call IDirect3DDevice7::SetRenderTarget(LPDIRECTDRAWSURFACE7) with your rendering surface as the parameter. Is a good ideea to allways check the returns for errors so you'll know what is wrong. Try loocking in the samples.

Hope this help, ChMar.

DDSURFACEDESC2 ddsd;
ddsd.dwSize = sizeof(ddsd);
s2->GetSurfaceDesc(&ddsd);
ddsd.dwFlags = DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_VIDEOMEMORY;
ddsd.ddpfPixelFormat.dwSize = 0;

if(FAILED(lpDD->QueryInterface(IID_IDirect3D7, (void**)&lpD3D)))
{
MessageBox(hWnd, "Error creating Direct3D", "Error", MB_OK);
return FALSE;
}

lpD3D->EnumZBufferFormats(IID_IDirect3DHALDevice, EnumZBufferFormatsCallback, (void*)&ddsd.ddpfPixelFormat);
if(0 == ddsd.ddpfPixelFormat.dwSize)
{
ddsd.ddpfPixelFormat.dwRGBBitCount = 16;
lpD3D->EnumZBufferFormats(IID_IDirect3DHALDevice, EnumZBufferFormatsCallback, (void*)&ddsd.ddpfPixelFormat);
if(0 == ddsd.ddpfPixelFormat.dwSize)
{
MessageBox(hWnd, "No valid ZBuffer", "Error", MB_OK);
return FALSE;
}
}
HRESULT hr;
if(FAILED(hr = lpDD->CreateSurface(&ddsd, &ZBuffer, NULL)))
{
if(hr == DDERR_OUTOFVIDEOMEMORY)
MessageBox(hWnd, "No memory for ZBuff", "Error", MB_OK);
else
MessageBox(hWnd, "Creating ZBuffer failed", "Error", MB_OK);
return FALSE;
}
if(FAILED(s2->AddAttachedSurface(ZBuffer)))
{
MessageBox(hWnd, "Coudn't attached ZBuff", "Error", MB_OK);
return FALSE;
}

if(FAILED(lpD3D->CreateDevice(IID_IDirect3DHALDevice, s2, &lpD3DDevice)))
{
MessageBox(hWnd, "Can't create Direct3DDevice", "Error", MB_OK);
return FALSE;
}
lpD3DDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, true);


static HRESULT WINAPI EnumZBufferFormatsCallback(DDPIXELFORMAT *pddpf, VOID *pContext)
{
DDPIXELFORMAT* pddpfOut = (DDPIXELFORMAT*)pContext;

if( pddpfOut->dwRGBBitCount == pddpf->dwRGBBitCount )
{
(*pddpfOut) = (*pddpf);
return D3DENUMRET_CANCEL;
}

return D3DENUMRET_OK;
}


Edited by - ChMar on August 28, 2000 4:36:04 PM

Share this post


Link to post
Share on other sites

  • 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!