Archived

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

Zeraan

Help with DirectDraw please!

Recommended Posts

I''m learning how to use DirectDraw 7, and everything is fine up to the point where I try to make back buffer, then it failed to make back buffer. Any help will be apprecriated! Here''s the code: int Game_Init() { if ( FAILED( DirectDrawCreateEx(NULL, (LPVOID*)&lpdd, IID_IDirectDraw7, NULL))) return 1; if (FAILED(lpdd->SetCooperativeLevel( g_hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT))) return 2; if (FAILED(lpdd->SetDisplayMode(800,600,16,0,0))) return 3; ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; if (FAILED(lpdd->CreateSurface(&ddsd, &lpDDSPrimary, NULL))) return 4; //This function below makes the backbuffer... if (FAILED(lpDDSPrimary->GetAttachedSurface(&ddscaps, &lpDDSBack))) return 5; <------ This is what I got return 0; } ______________________________________________ You know your game is in trouble when your AI says, in a calm, soothing voice, "I''m afraid I can''t let you do that, Dave"

Share this post


Link to post
Share on other sites
I am still learning the directdraw stuff myself, but do you actually initialise your DDSCAPS2 struct ddscaps? I have noticed the pattern so far that every struct you pass the directx functions you should initialise. If you are using the LaMothe books he defines a macro

#define INIT_STRUCT(thisStruct) { memset(thisStruct,0,sizeof(thisStruct)); thisStruct.dwSize = sizeof(thisStruct); }

Something along those lines. You then pass your DDSCAPS and DDSURFACEDESC structs before you use them..

This help?

Looking at your code again, don't you have to actually set the ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER or something??? before you call getattached surface... Don't take that for definate though.. Hope this is of some help

[edited by - hammerstein_02 on June 10, 2002 10:42:34 AM]

Share this post


Link to post
Share on other sites
Im not to sure, i dont have my SDK with me im at work but isnt this
if (FAILED(lpDDSPrimary->GetAttachedSurface(&ddscaps, &lpDDSBack)))

supposed to be this

if (FAILED(lpDDSPrimary->GetAttachedSurface(&ddsd.ddsCaps, &lpDDSBack)))

I remember that part, i think


hope that helps cyas

Share this post


Link to post
Share on other sites
Im not to sure, i dont have my SDK with me im at work but isnt this
if (FAILED(lpDDSPrimary->GetAttachedSurface(&ddscaps, &lpDDSBack)))

supposed to be this

if (FAILED(lpDDSPrimary->GetAttachedSurface(&ddsd.ddsCaps, &lpDDSBack)))

I remember that part, i think


hope that helps cyas

Share this post


Link to post
Share on other sites
Even with ddsd.ddsCaps, it still failed to make backbuffer

if(FAILED(lpDDSPrimary->GetAttachedSurface(&ddsd.ddsCaps, &lpDDSBack)))
return 5;

______________________________________________
You know your game is in trouble when your AI says, in a calm, soothing voice, "I''m afraid I can''t let you do that, Dave"

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Zeraan
Even with ddsd.ddsCaps, it still failed to make backbuffer

if(FAILED(lpDDSPrimary->GetAttachedSurface(&ddsd.ddsCaps, &lpDDSBack)))
return 5;

______________________________________________
You know your game is in trouble when your AI says, in a calm, soothing voice, "I''m afraid I can''t let you do that, Dave"


ddsd.ddsCaps.dwCaps=DDSCAPS_BACKBUFFER;

HRESULT hr=lpDDSPrimary->GetAttachedSurface(&ddsd.ddsCaps,&lpDDSBack);
if(FAILED(hr))
return 5;

that works fine for me.

Share this post


Link to post
Share on other sites
Instead of just using the FAILED macro, why not actually check the return code? The return codes for each function are in the docs so there''s no reason you shouldn''t know what error is causing it to fail.


Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

Share this post


Link to post
Share on other sites
Thanks! I added ddsd.ddsCaps.dwCaps=DDSCAPS_BACKBUFFER before the backbuffer initalization like this:

ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;

ddsd.dwBackBufferCount = 1;

if (FAILED(lpdd->CreateSurface(&ddsd, &lpDDSPrimary, NULL)))
return 4;

ddsd.ddsCaps.dwCaps=DDSCAPS_BACKBUFFER;

if (FAILED(lpDDSPrimary->GetAttachedSurface(&ddsd.ddsCaps, &lpDDSBack)))
return 5;

If this is incorrect way, inform me.

By the way, how do you make that box that allows you to put code inside in a clean and presentable way?

______________________________________________
You know your game is in trouble when your AI says, in a calm, soothing voice, "I''m afraid I can''t let you do that, Dave"

Share this post


Link to post
Share on other sites