Original Post
Hi, i have read some tutorials about direct3d, and im trying to write an idiot direct3d app (with directX9), with only direct3d initialization without neither vertexbuffers nor drawprimitive, i wish only to be able to clear the screen with a d3dDevice->Clear() call and the program have to stay alive in the Messagepeek loop, this is all, the only problem is that the program dont clear the screen, but it dont give any error from any functions, it all seems good, and it arrive and stay alive in the messagepeek loop, there are some MessageBox in some places to try to understand where is the problem , but i dont...
Could someone tell me why this idiot app dont clear the screen with green?
A very big part of the code is from a tutorial...
( i hope i dont get kick from the forum for the lenght of the paste
#define INITGUID
#define WIN32_LEAN_AND_MEAN
#include <d3d9.h>
#include <d3dx9.h>
#include <D3DX9Math.h>
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
LPDIRECT3D9 g_pD3D = NULL;
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
float scrWidth = 1024;
float scrHeight = 768;
const int scrDepth = 16;
HINSTANCE g_hInst;
HWND g_hWnd;
HRESULT g_hr;
bool g_minimized = FALSE;
HRESULT InitD3D( HWND hWnd )
{
if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
{
return E_FAIL;
}
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) )
{
return E_FAIL;
}
return S_OK;
}
VOID Cleanup()
{
if( g_pd3dDevice != NULL)
g_pd3dDevice->Release();
if( g_pD3D != NULL)
g_pD3D->Release();
}
HRESULT Render()
{
if( g_pd3dDevice == NULL) return E_FAIL;
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,255,0), 1.0f, 0 );
if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
MessageBox(g_hWnd,"dentro Render()","boh",MB_OK);
g_pd3dDevice->EndScene();
}
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
void SetupScreen(float WindowWidth, float WindowHeight)
{
D3DXMATRIX matOrtho;
D3DXMATRIX matIdentity;
D3DXMatrixOrthoLH(&matOrtho, WindowWidth, WindowHeight, 0.0f, 1.0f);
D3DXMatrixIdentity(&matIdentity);
g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matOrtho);
g_pd3dDevice->SetTransform(D3DTS_WORLD, &matIdentity);
g_pd3dDevice->SetTransform(D3DTS_VIEW, &matIdentity);
g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
}
LRESULT CALLBACK WndProc(HWND wpHWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_SYSCOMMAND:
{
switch (wParam)
{
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
}
return 0;
case WM_SIZE:
switch (wParam)
{
case SIZE_MINIMIZED:
Cleanup();
ShowCursor ( TRUE);
g_minimized = TRUE;
return 0;
case SIZE_RESTORED:
//InitD3D(g_hWnd);
ShowCursor (FALSE);
g_minimized = FALSE;
return 0;
}
break;
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
} break;
default:break;
}
return DefWindowProc(wpHWnd, msg, wParam, lParam);
}
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASSEX winClass;
MSG msg;
g_hInst=hInstance;
winClass.cbSize = sizeof(WNDCLASSEX);
winClass.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
winClass.lpfnWndProc = WndProc;
winClass.cbClsExtra = 0;
winClass.cbWndExtra = 0;
winClass.hInstance = g_hInst;
winClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winClass.lpszMenuName = NULL;
winClass.lpszClassName = "DXclass";
winClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if (!RegisterClassEx(&winClass))
{
MessageBox(g_hWnd, "Unable to create window class", "Initialisation Error...", MB_OK);
return 0;
}
g_hWnd = CreateWindowEx(NULL,
"DXclass",
"DX Tutorial",
WS_POPUP,
0, 0,
scrWidth, scrHeight,
NULL,
NULL,
g_hInst,
NULL);
if (!g_hWnd)
{
MessageBox(g_hWnd, "Unable to create window", "Initialisation Error...", MB_OK);
return 0;
}
// InitScene();
if(InitD3D(g_hWnd) == E_FAIL)
{
MessageBox(g_hWnd,"dentro initd3d, errore","boh",MB_OK);
Cleanup();
return 0;
}
ShowCursor (FALSE);
MessageBox(g_hWnd,"dopo initd3d","boh",MB_OK);
SetupScreen(scrWidth, scrHeight);
while(1)
{
while (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if (msg.message == WM_QUIT)
break;
}
if (msg.message==WM_QUIT)
break;
if ( g_minimized == FALSE)
{
// if ( KeyDown(DIK_ESCAPE) )
// PostQuitMessage(0);
// Update_Fps();
// UpdateKeys();
// DrawScene();
if(Render() == E_FAIL)
{
MessageBox(g_hWnd,"errore di render","boh",MB_OK);
return 0;
}
MessageBox(g_hWnd,"nel loop del peek message","boh",MB_OK);
Cleanup();
return 0;
}
}
Cleanup();
return 0;
}