Help with DirectDraw please!

Started by
6 comments, last by Zeraan 21 years, 10 months ago
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"
Advertisement
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]
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
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
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"
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.

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

This topic is closed to new replies.

Advertisement