Sign in to follow this  

DirectDraw Error at SetPalette

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

When I compile I have no warning and no error and when I'm going to run the program my debugger reply I cannot set the palette. This is my DD Code:
// directdraw.cpp //////////////////////////////////////////////

// INCLUDES ////////////////////////////////////////////////////

#include <windows.h>
#include <windowsx.h>
#include <ddraw.h>

#include "initWindow.h"
#include "game.h"
#include "directdraw.h"

#include "ddutil.h"
#include "dxutil.h"
#include "resource.h"

CDisplay*	g_pDisplay = NULL;
CSurface*	g_pBackground = NULL;
bool isWindowed = true;

// DD INIT /////////////////////////////////////////////////////

int DD_Init( HWND hWnd )
{
	LPDIRECTDRAWPALETTE pDDPal = NULL;

	g_pDisplay = new CDisplay();
	if( isWindowed )
	{
		if( FAILED( g_pDisplay->CreateWindowedDisplay( hWnd, SCREEN_WIDTH, SCREEN_HEIGHT ) ) )
		{
			SHUTDOWN_ERROR("Cannot initialize DirectDraw 7 in windowed mode.\n");
		}
	}
	else
	{
		if( FAILED( g_pDisplay->CreateFullScreenDisplay( hWnd, SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP ) ) )
		{
			SHUTDOWN_ERROR("Cannot initialize DirectDraw 7 in full screen mode.\n");
		}
	}

	if( FAILED( g_pDisplay->CreatePaletteFromBitmap( &pDDPal, MAKEINTRESOURCE( IDB_BACKGROUND ) ) ) )
	{
		SHUTDOWN_ERROR("Error at the creation of the palette.\n");
	}

	if( FAILED( g_pDisplay->SetPalette( pDDPal ) ) )
	{
		SHUTDOWN_ERROR("Cannot set the palette.\n");
	}

	SAFE_RELEASE( pDDPal );

	if( FAILED( g_pDisplay->CreateSurfaceFromBitmap( &g_pBackground, MAKEINTRESOURCE( IDB_BACKGROUND ), SCREEN_WIDTH, SCREEN_HEIGHT ) ) )
	{
		SHUTDOWN_ERROR("Cannot create the surface for the bitmap Bitmap1.bmp\n");
	}

	return(1);
}

// DD UPDATE FRAME /////////////////////////////////////////////

int DD_Updateframe( void )
{
	g_pDisplay->Clear( 0 );
	g_pDisplay->Blt( 0, 0, g_pBackground, NULL );

	if( FAILED( g_pDisplay->Present() ) )
	{
		SHUTDOWN_ERROR("Error at the flip.\n");
	}

	return(1);
}

// DD RESTORE SURFACE //////////////////////////////////////////

int DD_RestoreSurfaces( void )
{
	LPDIRECTDRAWPALETTE pDDPal = NULL;

	if( FAILED( g_pDisplay->GetDirectDraw()->RestoreAllSurfaces() ) )
	{
		SHUTDOWN_ERROR("Error at the restoring of all surfaces.\n");
	}

	if( FAILED( g_pDisplay->CreatePaletteFromBitmap( &pDDPal, MAKEINTRESOURCE( IDB_BACKGROUND ) ) ) )
	{
		SHUTDOWN_ERROR("Error at the creation of the palette.\n");
	}
	

	if( FAILED( g_pDisplay->SetPalette( pDDPal ) ) )
	{
		SHUTDOWN_ERROR("Cannot set the palette.\n");
	}

	SAFE_RELEASE( pDDPal );

	if( FAILED(	g_pBackground->DrawBitmap( MAKEINTRESOURCE( IDB_BACKGROUND ), SCREEN_WIDTH, SCREEN_HEIGHT ) ) )
	{
		SHUTDOWN_ERROR("Cannot draw the bitmap Bitmap1.bmp\n");
	}

	return(1);
}

// DD GAME /////////////////////////////////////////////////////

int DD_Game( void )
{
	DD_Updateframe();
	DD_RestoreSurfaces();

	return(1);
}

// DD SHUTDOWN /////////////////////////////////////////////////

int DD_Shutdown( void )
{
	SAFE_DELETE( g_pBackground );
	SAFE_DELETE( g_pDisplay );

	return(1);
}


Help me please !!! I'm new in DirectX

Share this post


Link to post
Share on other sites
I have changed my method and now that work. For curious that was my new code:


// directdraw.cpp //////////////////////////////////////////////

// INCLUDES ////////////////////////////////////////////////////

#include <windows.h>
#include <windowsx.h>
#include <ddraw.h>

#include "initWindow.h"
#include "game.h"
#include "directdraw.h"

#include "ddutil.h"
#include "dxutil.h"
#include "resource.h"

CDisplay* g_pDisplay = NULL;
CSurface* g_pBackground = NULL;
bool isWindowed = true;

// DD INIT /////////////////////////////////////////////////////

int DD_Init( HWND hWnd )
{
g_pDisplay = new CDisplay();
if( isWindowed )
{
if( FAILED( g_pDisplay->CreateWindowedDisplay( hWnd, SCREEN_WIDTH, SCREEN_HEIGHT ) ) )
{
SHUTDOWN_ERROR("Cannot initialize DirectDraw 7 in windowed mode.\n");
}
}
else
{
if( FAILED( g_pDisplay->CreateFullScreenDisplay( hWnd, SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP ) ) )
{
SHUTDOWN_ERROR("Cannot initialize DirectDraw 7 in full screen mode.\n");
}
}

return(1);
}

// DD UPDATE FRAME /////////////////////////////////////////////

int DD_Updateframe( void )
{
g_pDisplay->Clear( 0 );
g_pDisplay->CreateSurfaceFromBitmap( &g_pBackground, MAKEINTRESOURCE( IDB_BACKGROUND ), SCREEN_WIDTH, SCREEN_HEIGHT );
g_pDisplay->Blt( 0, 0, g_pBackground, NULL );

if( FAILED( g_pDisplay->Present() ) )
{
SHUTDOWN_ERROR("Error at the flip.\n");
}

return(1);
}

// DD GAME /////////////////////////////////////////////////////

int DD_Game( void )
{
DD_Updateframe();

return(1);
}

// DD SHUTDOWN /////////////////////////////////////////////////

int DD_Shutdown( void )
{
SAFE_DELETE( g_pBackground );
SAFE_DELETE( g_pDisplay );

return(1);
}


Share this post


Link to post
Share on other sites

This topic is 4833 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this