Now I have installed the directX Dev-pack for dev-c++, and the samples works fine and my program compiles as it should.
But, when I try to start my program it crashes.
When I debug it I get the error: "An access volation (Segmentation Fault) raised in your program" and highlights the row g_pd3dDevice->CreateOffscreenPlainSurface(
When I comment out all the "->" rows the program works fine, I think is something whit "g_pd3dDevice->".
I find the code in a other forum, and it seems to work for all the outers
I am probably doing something wrong, so if someone can take a last look =)
Code:
#include <d3d9.h>
#include <d3dx9.h>
//#include <D3dx9tex.h>
#include <windows.h>
//#pragma comment(lib,"d3d9.lib")
//#pragma comment(lib,"d3dx9.lib")
IDirect3DDevice9* g_pd3dDevice=NULL;
IDirect3DSurface9* g_pSurface=NULL;
bool SaveScreenShot( char *fileName, _D3DXIMAGE_FILEFORMAT ImgFormat);
INT WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow )
{
SaveScreenShot("test.bmp",D3DXIFF_BMP);
//g_pd3dDevice->CreateOffscreenPlainSurface(200, 300, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &g_pSurface, NULL);
//g_pd3dDevice->GetFrontBufferData(0, g_pSurface);
//g_pd3dDevice->CreateTexture(200,300,0,0,D3DFMT_A8R8G8B8,D3DPOOL_SCRATCH, &g_pTexture,NULL);
//this
//SurfaceLoader.Save("Screenshot.bmp", 0, g_pSurface);
//or???
//D3DXSaveSurfaceToFile("Screenshot.bmp",D3DXIFF_BMP,g_pSurface,NULL,NULL);
//g_pSurface->Release();
return 0;
}
bool SaveScreenShot( char *fileName, _D3DXIMAGE_FILEFORMAT ImgFormat)
{
HRESULT hr;
//The front buffer used to get the screenshot
LPDIRECT3DSURFACE9 buffer = NULL;
// Create a surface for the screenshot to be rendered to
if( FAILED( hr = g_pd3dDevice->CreateOffscreenPlainSurface(
1024,
768,
D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &buffer, NULL ) ) )
return false;
// Write the front buffer to the surface
if( FAILED( hr = g_pd3dDevice->GetFrontBufferData( 0, buffer ) ) )
{
//mGCLog.Error("Cannot Acquire front buffer...");
buffer->Release();
return false;
}
D3DXSaveSurfaceToFile( fileName, ImgFormat, buffer, NULL, NULL );
// Cleanup
buffer->Release();
return true;
}