Hi, i'm a newbie here.
I have made a win32 application with DirectX9.
There's kinda an error in my rendering code, as it shows in my window stuff shown before, like other windows parts (menus,title bars, black rectangles..), when i should see a blank rectangle.
This is my rendering code:
Not quite, the color you specified is white. For me personally I also get such artifacts if I clear the backbuffer to anything but black. Try using
D3DCOLOR_XRGB(0,0,0).
Ok i re-wrote my rendering function and it is now correct!
My new task is different:
I'm able to create surfaces with DX9, but i haven't understood how to draw on them (device->draw methods only work in my "official" backbuffer, which is swapped to the frontbuffer with device->present).
What i want to do is to draw something in a separate surface, which content will not be rendered on my window by device->present, holding in the application memory this surface in order to let me use it later.
Is it possible? Thanks in advance
Thank you.
Could you please give me one last hint?
LPDIRECT3DSURFACE9 Surfaces[20];
//create the first surface!
device->CreateRenderTarget(100,100,D3DFMT_A8R8G8B8,D3DMULTISAMPLE_NONE,0,false,&Surfaces[0],NULL);
device->SetRenderTarget(0,Surfaces[0]);
Surfaces[0]->Release();
POINT a;
a.x = 10;
a.y = 10;
This code seems to work, but later, in my render loop, when i try to draw Surface[0] on the screen by copying it on the back buffer , i get an error:
the error message is:
Unhandled exception at 0x4fe13f3d in ProjDX.exe: 0xC0000005: Access violation in reading 0x00000000.
and it comes from the line with "UpdateSurface" method..
BackBuffer is obtained at the beginning of the application with this code:
IDirect3DSurface9* BackBuffer = NULL;
if(FAILED(g_pd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&BackBuffer)))
{ MessageBox(0,"Error","BackBuffer Error",MB_OK);}
I never got that message..
Ah sry, my fault. You are only supposed to Release the surface right after setting it as a rendertarget if you don't need its information later on (like for the backbuffer). Try to delete Surface[0]->Release(); , but be sure to release it on programs exit. Tell me if it worked.
If this can help you to help me (coxian sentence)
here is the entire code of my win32 application:
[sup]
#include <d3d9.h>
#include <WindowsX.h>
#pragma comment (lib,"d3d9.lib")
#pragma comment (lib,"d3dx9.lib")
//Add this source to your project
//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
LPDIRECT3D9 g_pD3D = NULL; // Used to create the D3DDevice
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; // Our rendering device
int mouse_x = 0;
int mouse_y = 0;
struct VERTEX
{
float x,y,z,rhw;
DWORD color;
};
VERTEX vertici[20];
//-----------------------------------------------------------------------------
// Name: InitD3D()
// Desc: Initializes Direct3D
//----------------------------------------------------------------------------- LPDIRECT3DSURFACE9 Surface = NULL;
LPDIRECT3DSURFACE9 BackBuffer = NULL;
POINT punto;
HRESULT InitD3D( HWND hWnd )
{
// Create the D3D object, which is needed to create the D3DDevice.
if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
return E_FAIL;
// Set up the structure used to create the D3DDevice. Most parameters are
// zeroed out. We set Windowed to TRUE, since we want to do D3D in a
// window, and then set the SwapEffect to "discard", which is the most
// efficient method of presenting the back buffer to the display. And
// we request a back buffer format that matches the current desktop display
// format.
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
// Create the Direct3D device. Here we are using the default adapter (most
// systems only have one, unless they have multiple graphics hardware cards
// installed) and requesting the HAL (which is saying we want the hardware
// device rather than a software one). Software vertex processing is
// specified since we know it will work on all cards. On cards that support
// hardware vertex processing, though, we would see a big performance gain
// by specifying hardware vertex processing.
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) )
{
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) )
return E_FAIL;
}
// Device state would normally be set here
//Creo una surface g_pd3dDevice->CreateRenderTarget(100,100,D3DFMT_UNKNOWN,D3DMULTISAMPLE_NONE,0,FALSE,&Surface,NULL);
PeekMessage( &mssg, NULL, 0, 0, PM_NOREMOVE);
// run till completed
while (mssg.message!=WM_QUIT)
{
// is there a message to process?
if (PeekMessage( &mssg, NULL, 0, 0, PM_REMOVE))
{
// dispatch the message
TranslateMessage(&mssg);
DispatchMessage(&mssg);
}
else
{
//No message to process?
// Then do your game stuff here
Render();
}
}
}