Direct X 7 Problem
Im having a problem with direct draw 7. There is an error creating the primary surface.
This causes me to not be able to set the clipper which causes an illegal operation message upon excution.
umm... Here''s the code that (I think, could be wrong) is causing the problem:
//Create the Primary surface
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;
hRet=lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL);
The defintion of the local variables of the function:
DDSURFACEDESC2 ddsd;
HRESULT hRet;
DDSCAPS2 ddscaps;
Global variables:
LPDIRECTDRAW7 lpDD=NULL //DirectDraw object
LPDIRECTDRAWSURFACE7 lpDDSPrimary=NULL; //DirectDraw Primary Surface
LPDIRECTDRAWCLIPPER lpClip=NULL; //DirectDraw Clipper
LPDIRECTDRAWSURFACE7 lpBack=NULL; //Back Buffer
I realize that this is annoyingly long...
/////////////////////////////////////////////////"Sufficiently advanced technology is indistinguishable from magic" Arthur C. Clark
I cant really see anything wrong with your code there, except maybe make the two sizeof''s sizeof(DDSURFACEDESC2). Whats your code for attaching the backbuffer and clipper, maybe thats the problem?
Ballistic Programs
Ballistic Programs
Well ok, I guess thats good to know...
The code for the clipper?
//Create the clipper
hRet=lpDD->CreateClipper(0 ,&lpClip,NULL);
if (hRet!=DD_OK)
{
MessageBox(hWnd, "Clip Create error", "error!", MB_ICONERROR);
}
//Set the clipper to the window
hRet=lpClip->SetHWnd(0,hWnd);
if (hRet!=DD_OK)
{
MessageBox(hWnd, "Clip Set error", "error!", MB_ICONERROR);
}
And(after creating the primary surface so I don''t think its the problem...) :
//Get the back buffer
lpDDSPrimary->GetAttachedSurface( &ddscaps, &lpBack);
//Set the clipper to the primary surface
lpDDSPrimary->SetClipper(lpClip);
But couldn''t it be the setup of the direct draw object?
//Create the DirectDraw object
hRet=DirectDrawCreateEx(NULL,(VOID**)&lpDD, IID_IDirectDraw7, NULL);
if (hRet!=DD_OK)
{
MessageBox(hWnd, "DDraw Create error", "error!", MB_ICONERROR);
}
//Set Cooperative Level to full screen
lpDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
if (hRet!=DD_OK)
{
MessageBox(hWnd, "coop level error!!!", "error!", MB_ICONERROR);
}
The code for the clipper?
//Create the clipper
hRet=lpDD->CreateClipper(0 ,&lpClip,NULL);
if (hRet!=DD_OK)
{
MessageBox(hWnd, "Clip Create error", "error!", MB_ICONERROR);
}
//Set the clipper to the window
hRet=lpClip->SetHWnd(0,hWnd);
if (hRet!=DD_OK)
{
MessageBox(hWnd, "Clip Set error", "error!", MB_ICONERROR);
}
And(after creating the primary surface so I don''t think its the problem...) :
//Get the back buffer
lpDDSPrimary->GetAttachedSurface( &ddscaps, &lpBack);
//Set the clipper to the primary surface
lpDDSPrimary->SetClipper(lpClip);
But couldn''t it be the setup of the direct draw object?
//Create the DirectDraw object
hRet=DirectDrawCreateEx(NULL,(VOID**)&lpDD, IID_IDirectDraw7, NULL);
if (hRet!=DD_OK)
{
MessageBox(hWnd, "DDraw Create error", "error!", MB_ICONERROR);
}
//Set Cooperative Level to full screen
lpDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
if (hRet!=DD_OK)
{
MessageBox(hWnd, "coop level error!!!", "error!", MB_ICONERROR);
}
/////////////////////////////////////////////////"Sufficiently advanced technology is indistinguishable from magic" Arthur C. Clark
Wierd, you seem to have everything done fine, the only thing I can thik of is the oder you are doing things, try
Creating Directdraw object
Set the cooperative level
Set the display mode
Set up the DDSURFACEDESC2 for the primary surface
Create primary surface
Set up DDSCAPS2 for Backbuffer
Attach backbuffer
Create Clipper
SetHWND in clipper
Set clipper
you didnt put the code where you set up your DDSCAPS2 for the back buffer I assume you used
memset(&ddscaps,0,sizeof(DDSCAPS2));
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
A finial thing to try would be to place a message box before each function call, to pop up and tell you where you are in the program, that way you can find which line is causing the problem and work from there.
Ballistic Programs
Creating Directdraw object
Set the cooperative level
Set the display mode
Set up the DDSURFACEDESC2 for the primary surface
Create primary surface
Set up DDSCAPS2 for Backbuffer
Attach backbuffer
Create Clipper
SetHWND in clipper
Set clipper
you didnt put the code where you set up your DDSCAPS2 for the back buffer I assume you used
memset(&ddscaps,0,sizeof(DDSCAPS2));
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
A finial thing to try would be to place a message box before each function call, to pop up and tell you where you are in the program, that way you can find which line is causing the problem and work from there.
Ballistic Programs
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement