Jump to content
  • Advertisement

Archived

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

Tealc

Win2k, DX8 & PrimarySurface Problem

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

Hello, I''m just trying to get into directx programming and I ''ve a problem width initalizing the PrimarySurface under Windows 2000. There are no compile errors but I can''t clear the PrimarySurface (trying to make it black). Here''s the code I use to create a complex surface (PrimarySurface with one BackSurface) :
int InitDirectX() {	HRESULT ddrval;		ddrval = DirectDrawCreateEx(NULL, (LPVOID *)&lpDD, IID_IDirectDraw7, NULL);	if (ddrval != DD_OK) {		MessageBox(hWnd, "DDraw Fehler: DirectDrawCreateEx()", "DDRAW ERROR", MB_OK);		return(-1);	}		ddrval = lpDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN );	if (ddrval != DD_OK) {		MessageBox(hWnd, "DDraw Fehler: SetCooperativeLevel()", "DDRAW ERROR", MB_OK);		return(-1);	}		ddrval = lpDD->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, 0, 0);		if (ddrval != DD_OK) 		return(-1);		// create Complex 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;	ddrval = lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL);	if (ddrval != DD_OK) {		MessageBox(hWnd, "DDraw Error: CreateSurface()", "DDRAW ERROR", MB_OK);		return(-1);	}	ZeroMemory(&ddscaps, sizeof(ddscaps));	ddscaps.dwCaps = DDSCAPS_BACKBUFFER;	ddrval = lpDDSPrimary->GetAttachedSurface(&ddscaps, &lpDDSBack);	if (ddrval != DD_OK) {		MessageBox(hWnd, "DDraw Error: GetAttachedSurface()", "DDRAW ERROR", MB_OK);		return(-1);	}	ClearSurface(lpDDSPrimary, 0);	ClearSurface(lpDDSBack, 0);	return(1);} 
 
And here is my routine to clean the surfaces:
bool ClearSurface(LPDIRECTDRAWSURFACE7 lpDDSurf, UCHAR Farbe) {	HRESULT ddrval;		DDBLTFX ddBltFx;	ZeroMemory(&ddBltFx, sizeof(DDBLTFX));	ddBltFx.dwSize = sizeof(DDBLTFX);	ddBltFx.dwFillColor = Farbe;	ddrval = lpDDSurf->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddBltFx);	if (ddrval != DD_OK) {		MessageBox(hWnd, "DDraw Error: ClearSurface()","DDRAW ERROR", MB_OK);		return(false);	}	return(true);} 
 
The Back Surface I can clear an set to black color by using ClearSurface(lpDDSBack, 0) - but that''s not working with the Primary Surface. Under Windows 98 it works fine. I only have problem under Windows 2000. What can I do to fix this ???

Share this post


Link to post
Share on other sites
Advertisement
Whoops - seems that I teared the source .... one more try ...


Hello,

I''m just trying to get into directx programming and I ''ve a problem width initalizing the PrimarySurface under Windows 2000.
There are no compile errors but I can''t clear the PrimarySurface (trying to make it black).
Here''s the code I use to create a complex surface (PrimarySurface with one BackSurface) :


int InitDirectX() {
HRESULT ddrval; // Rückgabewert

ddrval = DirectDrawCreateEx(NULL, (LPVOID *)&lpDD, IID_IDirectDraw7, NULL);
if (ddrval != DD_OK) {
MessageBox(hWnd, "DDraw Fehler: DirectDrawCreateEx()", "DDRAW ERROR", MB_OK);
return(-1);
}


ddrval = lpDD->SetCooperativeLevel(hWnd, DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT );
if (ddrval != DD_OK) {
MessageBox(hWnd, "DDraw Fehler: SetCooperativeLevel()", "DDRAW ERROR", MB_OK);
return(-1);
}

ddrval = lpDD->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, 0, 0);
if (ddrval != DD_OK)
return(-1);


// create Complex 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;

ddrval = lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL);
if (ddrval != DD_OK) {
MessageBox(hWnd, "DDraw Error: CreateSurface()", "DDRAW ERROR", MB_OK);
return(-1);
}

ZeroMemory(&ddscaps, sizeof(ddscaps));
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;

ddrval = lpDDSPrimary->GetAttachedSurface(&ddscaps, &lpDDSBack);
if (ddrval != DD_OK) {
MessageBox(hWnd, "DDraw Error: GetAttachedSurface()", "DDRAW ERROR", MB_OK);
return(-1);
}

return(1);
}

And here is my routine to clean the surfaces:


bool ClearSurface(LPDIRECTDRAWSURFACE7 lpDDSurf, UCHAR Farbe) {
HRESULT ddrval;
DDBLTFX ddBltFx;

ZeroMemory(&ddBltFx, sizeof(DDBLTFX));
ddBltFx.dwSize = sizeof(DDBLTFX);
ddBltFx.dwFillColor = Farbe;

ddrval = lpDDSurf->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddBltFx);

if (ddrval != DD_OK) {
MessageBox(hWnd, "DDraw Error: ClearSurface()","DDRAW ERROR", MB_OK);
return(false);
}

return(true);
}


The Back Surface I can clear an set to black color by using ClearSurface(lpDDSBack, 0) - but that''s not working with the Primary Surface.
Under Windows 98 it works fine. I only have problem under Windows 2000.
What can I do to fix this ???





Share this post


Link to post
Share on other sites
Guest Anonymous Poster
MS has made it quite clear that you really can''t/shouldn''t use the primary buffer anymore, this allows for hardware company''s to optimize their designs better. Why after all they spout at you to not use it, would you want to use it?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Sorry, I see in your code you just posted that you''re using DX7 not DX8 like you state in the topic... Ignore my post then because it does not pertain to DX8.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Sorry, I see in your code you just posted that you''re using DX7 not DX8 like you state in the topic... Ignore my post then because it does not pertain to DX7.

Share this post


Link to post
Share on other sites
Yes, I''m using DX7 but it''s the DX8 SDK. I use DX7 because I
only have books about DX7. The way to initialize DX8 confuses
me but it''s still working under W2000.


HRESULT InitDirectDraw( HWND hWnd )
{
HRESULT hr;
LPDIRECTDRAWPALETTE pDDPal = NULL;
int iSprite;

g_pDisplay = new CDisplay();
if( FAILED( hr = g_pDisplay->CreateFullScreenDisplay( hWnd, SCREEN_WIDTH,
SCREEN_HEIGHT, SCREEN_BPP ) ) )
{
MessageBox( hWnd, TEXT("This display card does not support 640x480x8. "),
TEXT("DirectDraw Sample"), MB_ICONERROR | MB_OK );
return hr;
}

// Create and set the palette when in palettized color
if( FAILED( hr = g_pDisplay->CreatePaletteFromBitmap( &pDDPal, MAKEINTRESOURCE( IDB_DIRECTX ) ) ) )
return hr;

if( FAILED( hr = g_pDisplay->SetPalette( pDDPal ) ) )
return hr;

SAFE_RELEASE( pDDPal );

// Create a surface, and draw a bitmap resource on it.
if( FAILED( hr = g_pDisplay->CreateSurfaceFromBitmap( &g_pLogoSurface, MAKEINTRESOURCE( IDB_DIRECTX ),
SPRITE_DIAMETER, SPRITE_DIAMETER ) ) )
return hr;

// Create a surface, and draw text to it.
if( FAILED( hr = g_pDisplay->CreateSurfaceFromText( &g_pTextSurface, NULL, HELPTEXT,
RGB(0,0,0), RGB(255, 255, 0) ) ) )
return hr;

// Set the color key for the logo sprite to black
if( FAILED( hr = g_pLogoSurface->SetColorKey( 0 ) ) )
return hr;

// Init all the sprites. All of these sprites look the same,
// using the g_pDDSLogo surface.
for( iSprite = 0; iSprite < NUM_SPRITES; iSprite++ )
{
// Set the sprite''s position and velocity
g_Sprite[iSprite].fPosX = (float) (rand() % SCREEN_WIDTH);
g_Sprite[iSprite].fPosY = (float) (rand() % SCREEN_HEIGHT);

g_Sprite[iSprite].fVelX = 500.0f * rand() / RAND_MAX - 250.0f;
g_Sprite[iSprite].fVelY = 500.0f * rand() / RAND_MAX - 250.0f;
}

return S_OK;
}


Another interesting point I figured out, when I only create a Primary Surface without Back Surface it works. But without a
Back Surface I can''t do what I want. Hope that someone can help
me.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!