Jump to content
  • Advertisement
Sign in to follow this  
eXon

DirectDraw Error at SetPalette

This topic is 5204 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
Advertisement
I have copy/past directx.bmp from the FullScreenMode example in DirectX SDK 8. What is the format require to work?

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
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!