// 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);
}
DirectDraw Error at SetPalette
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:
Help me please !!! I'm new in DirectX
What is "MAKEINTRESOURCE( IDB_BACKGROUND )" resolving to? Are you sure the bitmap is appropriately formatted?
Ryan
Ryan
I have copy/past directx.bmp from the FullScreenMode example in DirectX SDK 8. What is the format require to work?
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);}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement