Error message:
"Tried to read a surface which has no read permissions!"
For those of you that are having problems with the "Dark GDK Upgrade - November 2008" when you are using the "dbSetDisplayModeAntialias ()" function and doing a screen capture within your code with "dbGetImage()".
Here is a temporary option until the problem hopefully gets solved.
A straight copy of my "SnapShot.CPP" file.
#include "DarkGDK.h"
#include "globstruct.h"
#define DIK_SYSRQ 0xB7 /* PrintScreen key */
#define TARGET_DIRECTORY "SnapShot\\" /* Folder name where screen captures will be sent (IT REQUIRES THE 2 BACKSLASHES IN THE "SnapShot" NAME */
void SaveBitmap(char *szFilename,HBITMAP hBitmap)
{
HDC hdc=NULL;
FILE* fp=NULL;
LPVOID pBuf=NULL;
BITMAPINFO bmpInfo;
BITMAPFILEHEADER bmpFileHeader;
do{
hdc=GetDC(NULL);
ZeroMemory(&bmpInfo,sizeof(BITMAPINFO));
bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
GetDIBits(hdc,hBitmap,0,0,NULL,&bmpInfo,DIB_RGB_COLORS);
if(bmpInfo.bmiHeader.biSizeImage<=0)
bmpInfo.bmiHeader.biSizeImage=bmpInfo.bmiHeader.biWidth*abs(bmpInfo.bmiHeader.biHeight)*(bmpInfo.bmiHeader.biBitCount+7)/8;
if((pBuf = malloc(bmpInfo.bmiHeader.biSizeImage))==NULL)
{
MessageBox( NULL, "Unable to Allocate Bitmap Memory", "Error", MB_OK|MB_ICONERROR);
break;
}
bmpInfo.bmiHeader.biCompression=BI_RGB;
GetDIBits(hdc,hBitmap,0,bmpInfo.bmiHeader.biHeight,pBuf, &bmpInfo, DIB_RGB_COLORS);
if((fp = fopen(szFilename,"wb"))==NULL)
{
//Probably didn't have a directory to put snapshots into.
dbMakeDirectory ( TARGET_DIRECTORY );
if((fp = fopen(szFilename,"wb"))==NULL)
{
MessageBox( NULL, "Unable to Create Bitmap File", "Error", MB_OK|MB_ICONERROR);
break;
}
}
bmpFileHeader.bfReserved1=0;
bmpFileHeader.bfReserved2=0;
bmpFileHeader.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+bmpInfo.bmiHeader.biSizeImage;
bmpFileHeader.bfType='MB';
bmpFileHeader.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
fwrite(&bmpFileHeader,sizeof(BITMAPFILEHEADER),1,fp);
fwrite(&bmpInfo.bmiHeader,sizeof(BITMAPINFOHEADER),1,fp);
fwrite(pBuf,bmpInfo.bmiHeader.biSizeImage,1,fp);
}while(false);
if(hdc)
ReleaseDC(NULL,hdc);
if(pBuf)
free(pBuf);
if(fp)
fclose(fp);
}
void CaptureScreen(char *szFilename)
{
int nScreenWidth = dbScreenWidth( );
int nScreenHeight = dbScreenHeight( );
HWND hGamescreenWnd = g_pGlob->hWnd;
HDC hGamescreenDC = GetDC(hGamescreenWnd);
HDC hCaptureDC = CreateCompatibleDC(hGamescreenDC);
HBITMAP hCaptureBitmap =CreateCompatibleBitmap(hGamescreenDC, nScreenWidth, nScreenHeight);
SelectObject(hCaptureDC,hCaptureBitmap);
BitBlt(hCaptureDC, 0, 0, nScreenWidth, nScreenHeight, hGamescreenDC, 0, 0, SRCCOPY|CAPTUREBLT);
SaveBitmap( szFilename, hCaptureBitmap);
ReleaseDC(hGamescreenWnd,hGamescreenDC);
DeleteDC(hCaptureDC);
DeleteObject(hCaptureBitmap);
}
void ScreenCaptureTest(void)
{
char szTempStr [ 128 ];
char szTempStr2 [ 128 ];
int image_iID = 65535;
int static iPictureTaken;
//Control picture taking so it happens only once every key press.
if ((dbScanCode ( ) == DIK_SYSRQ) && (!iPictureTaken) )
{
// Build the Picture file name
strcpy( szTempStr, TARGET_DIRECTORY);
strcpy( szTempStr2, dbGetDate$( ));
szTempStr2 [2] = szTempStr2 [3];
szTempStr2 [3] = szTempStr2 [4];
szTempStr2 [4] = szTempStr2 [6];
szTempStr2 [5] = szTempStr2 [7];
szTempStr2 [6] = szTempStr2 [8];
strcat( szTempStr, szTempStr2);
strcpy( szTempStr2, dbGetTime$( ));
szTempStr2 [2] = szTempStr2 [3];
szTempStr2 [3] = szTempStr2 [4];
szTempStr2 [4] = szTempStr2 [6];
szTempStr2 [5] = szTempStr2 [7];
szTempStr2 [6] = szTempStr2 [8];
strcat( szTempStr, szTempStr2);
strcat( szTempStr, ".BMP");
CaptureScreen(szTempStr);
//Set the picture taken flag
iPictureTaken = 1;
}
if ( (dbScanCode ( ) != DIK_SYSRQ) && (iPictureTaken) )
{
//Clear the picture taken flag
iPictureTaken = 0;
}
}
One can use the "ScreenCaptureTest()" within the game loop for automatic key test and produce the picture, or use any of the other functions as you see fit.
Any problems, please let me know.
EDIT: UGHHH.... How does one stop all those extra Backslash characters from corrupting the code fragments ????????
EDIT2: It looks to have fixed itself .... hope nothing got corrupted