Archived

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

Guest Anonymous Poster

Why doesnt this work?

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


Esap1,

Let me preface this by saying that I am not a Direct3D guru, but have some experience with COM.

The only thing that really jumped out at me was the fact that you were Querying an uninitialized interface pointer for itself..:


lpd3d->QueryInterface(IID_IDirect3D2, ...)

that line should read:

lpdd->QueryInterface(IID_IDirect3D2, (void**)&lpd3d)

Since you need to query the IDirectDraw interface for the IDirect3D interface.

As a side note, you might want to consider taking the time to create your own exception handling class, something that takes an HRESULT and maps it to a string definition of what went wrong.

HTH,

-mordell

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
1 more thing, when I set hardware to 1 as it is there, it cant get past AddAttachedSurface, but if I set it to 0, it cant get past the CreateDevice, I just dont know what wrong:

Share this post


Link to post
Share on other sites
Since you have a primary surface and a back surface, I assume you want to flip. But eeeeh, you didn't make code to flip your surface. Change that...

------------------
Dance with me......

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I have other code in a function to flip the surface but my program cant even get past that function

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
PLEASE, I STILL NEED HELP, Please , if yo can please try to help me, thanx alot

Share this post


Link to post
Share on other sites
Ok

1) Get lost of the DDSCL_MODEX
2) Use (DirectDraw->)QueryInterface before you set the display mode.
3) use "FrontBuffer->GetAttachedSurface(&caps, &BackBuffer);" instead of AddAttachedSurface();

I Use addattchedSurface to attach the z buffer.

I would go for the following items in the following order:
1) DirectDrawCreate()
2) SetCooperativeLevel()
3) QueryInterface()
4) SetDisplayMode()
5) CreateSurface()
6) GetAttachedSurface()
( 7) CreateSurface + AddAttachedSurface for zbuffer)
8) CreateDevice()
9) CreateViewPort()
10) AddViewPort()
11) SetCurrentViewPort()
12) SetTransform()

etc etc..........

------------------
Dance with me......

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thanks, but one more question, what CAPS should I use for the GetAttachedSurface for the back buffer,
thanks alot

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I was wondering if yo have to CreateSurface a Backbuffer before you use AddAttachedSurface,
Also Im doing everything right
but AddAttachedSurface returns an error.
thank you!

Share this post


Link to post
Share on other sites
Look at the following bit.

DDSURFACEDESC ddsd;

ZeroMemory(&ddsd, sizeof(ddsd));

ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY;

ddsd.dwBackBufferCount = 1;

err = dd->CreateSurface(&ddsd, &FrontBuffer, NULL);

if (err != DD_OK)
{
ddsd.ddsCaps.dwCaps &= ~DDSCAPS_VIDEOMEMORY;
err = dd->CreateSurface(&ddsd, &FrontBuffer, NULL);
}

if (err != DD_OK)
{
return FALSE;
}

DDSCAPS caps;

caps.dwCaps = DDSCAPS_BACKBUFFER;
err = FrontBuffer->GetAttachedSurface(&caps, &BackBuffer);

if (err != DD_OK)
{
return FALSE;
}

memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(DDSURFACEDESC);
ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT |DDSD_CAPS | DDSD_ZBUFFERBITDEPTH;
ddsd.dwHeight = height;
ddsd.dwWidth = width;
ddsd.dwZBufferBitDepth = bpp;
ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_SYSTEMMEMORY;

err = dd->CreateSurface(&ddsd, &ZBuffer, 0);
if(err != DD_OK)
{
return FALSE;
}

err = BackBuffer->AddAttachedSurface(ZBuffer);

if(err != DD_OK)
{
return FALSE;
}

------------------
Dance with me......

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I tried that exact code and it died on that first CreateSuface(FrontBuffer
it jus kills it, i had to EndTask to get out of it, thanks for helpin the new guy.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The only way I no it was CreateSurface that killed it was because 1 time it didnt Totaly Freeze my comp. I some how got it out and it did return a long error, though I didnt write it down. Every time I run the program it freezes and I can only turn off my comp, tried everything.

Share this post


Link to post
Share on other sites
If you want to debug your program you shouldn't use the FULLSCREEN flag. Just test the program in windowed mode and switch then to fullscreen. But be aware of the fact that you cant flip pages in windowed modes.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
heres the code, im a begginner so dont laugh if its obvios

LPDIRECT3D2 lpd3d;
LPDIRECT3DDEVICE2 lpd3ddevice;
LPDIRECTDRAW lpdd = NULL;
LPDIRECTDRAWSURFACE lpddsprimary = NULL;
LPDIRECTDRAWSURFACE lpddsbackbuffer = NULL;
LPDIRECTDRAWPALETTE lpddpal = NULL;
PALETTEENTRY color_palette[256];
DDSURFACEDESC ddsd;
DDSCAPS ddscaps;
HRESULT ddrval;
HWND main_window_handle=NULL;

int hardware;

int DD_Init(HWND hwnd)
{
// this function is responsible for initializing direct draw, it creates a
// primary surface

int index; // looping index
// now that the windows portion is complete, start up direct draw
if (DirectDrawCreate(NULL,&lpdd,NULL)!=DD_OK)
{
// shutdown any other dd objects and kill window
DD_Shutdown();
return(0);
} // end if

// now set the coop level to exclusive and set for full screen and mode x
if (lpdd->SetCooperativeLevel(hwnd, DDSCL_ALLOWREBOOT | DDSCL_EXCLUSIVE |
DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX)!=DD_OK)
{
// shutdown any other dd objects and kill window
DD_Shutdown();
return(0);
} // end if

// now set the display mode
if (lpdd->SetDisplayMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP)!=DD_OK)
{
// shutdown any other dd objects and kill window
DD_Shutdown();
return(0);
} // end if

// Create the primary surface
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

if (lpdd->CreateSurface(&ddsd,&lpddsprimary,NULL)!=DD_OK)
{
// shutdown any other dd objects and kill window
DD_Shutdown();
return(0);
} // end if

ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
ddsd.dwWidth = SCREEN_WIDTH;
ddsd.dwHeight = SCREEN_HEIGHT;
hardware=1; //Forse Hardware Acceleration
if (hardware)
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY;

else
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_SYSTEMMEMORY;

if (lpdd->CreateSurface(&ddsd, &lpddsbackbuffer,NULL) != DD_OK) return(0);
if (lpddsprimary->AddAttachedSurface(lpddsbackbuffer) != DD_OK) return(0);


//Query the hardware

if (lpd3d->QueryInterface(IID_IDirect3D2, (LPVOID *)&lpd3d) != S_OK)
return (0);


// Create the D3D device

if (lpd3d->CreateDevice(IID_IDirect3DHALDevice, lpddsbackbuffer, &lpd3ddevice) != D3D_OK)
return FALSE;

// return success if we got this far
return(1);

} // end DD_Init

---------------------------------
Thank yo so much
also, sorry for the length
I dont really know whats wrong but it cant get past the Query Interface, also I am forcing hardware acceleration (I THINK) jus to make it easier,
Thanks again,

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
when I turn off fullscreen mode and dont change the video mode the program seems to work as it does not return an error. Though onces I use full screen and hardware acceleration I found out that when I use CreateSurface(Front_Buffer), It returns DDER_INVALIDCAPS. I dont no if Im using the right caps. THANX AGAIN!

Share this post


Link to post
Share on other sites