Jump to content

  • Log In with Google      Sign In   
  • Create Account

Why doesnt this work?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
17 replies to this topic

#1 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 27 November 1999 - 09:20 PM

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,


Sponsor:

#2 mordell   Members   -  Reputation: 122

Like
Likes
Like

Posted 14 November 1999 - 05:01 AM


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


#3 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 14 November 1999 - 02:45 PM

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:

#4 CJ   Members   -  Reputation: 122

Like
Likes
Like

Posted 14 November 1999 - 10:31 PM

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......


#5 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 15 November 1999 - 01:25 PM

I have other code in a function to flip the surface but my program cant even get past that function

#6 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 16 November 1999 - 03:14 PM

PLEASE, I STILL NEED HELP, Please , if yo can please try to help me, thanx alot

#7 CJ   Members   -  Reputation: 122

Like
Likes
Like

Posted 17 November 1999 - 04:31 AM

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......


#8 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 17 November 1999 - 02:43 PM

Thanks, but one more question, what CAPS should I use for the GetAttachedSurface for the back buffer,
thanks alot

#9 CJ   Members   -  Reputation: 122

Like
Likes
Like

Posted 18 November 1999 - 05:46 AM

DDSCAPS_BACKBUFFER

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


#10 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 19 November 1999 - 08:36 PM

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!

#11 CJ   Members   -  Reputation: 122

Like
Likes
Like

Posted 19 November 1999 - 11:32 PM

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......


#12 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 24 November 1999 - 08:54 PM

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.

#13 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 25 November 1999 - 03:20 PM

Doesnt any one have any ideas????????
PLESAE help,
thanx.

#14 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 25 November 1999 - 06:02 PM

Could someone Please Help ME THANX

#15 Strabbi   Members   -  Reputation: 122

Like
Likes
Like

Posted 26 November 1999 - 06:48 AM

Do you get an error returned from CreateSurface, and if so which error?

DirectDraw's error codes can be helpful.


#16 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 26 November 1999 - 07:08 PM

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.

#17 Yoshi   Members   -  Reputation: 122

Like
Likes
Like

Posted 26 November 1999 - 11:54 PM

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.

#18 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 27 November 1999 - 09:20 PM

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!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS