Help! Strange pause in D3D
Help!
I have this strange problem. I start Direct3D in full screen mode. If I start it in a visible window, it allways works, but pauses after 1-2 seconds for 2 second. The game freezes for 2 seconds and then it continues normal.
But, if I use window without VISIBLE flag, game might exit at start, or might not,totally random, and after its started it never pauses.
Please advise.
Code is bases on DXSDK 3d samples
main file:
#include <d3d8.h>
#include "sp.h"
LPDIRECT3D8 g_pD3D = NULL; // Used to create the D3DDevice
LPDIRECT3DDEVICE8 g_pd3dDevice = NULL; // Our rendering device
HWND hWnd = NULL; // Window
WFMApp * game; // Game
WNDCLASSEX wc;
HRESULT InitD3D()
{
if( NULL == ( g_pD3D = Direct3DCreate8( D3D_SDK_VERSION ) ) )
return E_FAIL;
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = FALSE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.FullScreen_PresentationInterval=D3DPRESENT_INTERVAL_IMMEDIATE;
d3dpp.FullScreen_RefreshRateInHz=0;
d3dpp.BackBufferCount=1;
d3dpp.BackBufferFormat =D3DFMT_R5G6B5;// D3DFMT_A8R8G8B8;
d3dpp.BackBufferWidth=800;
d3dpp.BackBufferHeight=600;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice )))
{
exit(1);
}
return S_OK;
}
HRESULT Reset()
{
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = FALSE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.FullScreen_PresentationInterval=D3DPRESENT_INTERVAL_IMMEDIATE;
d3dpp.FullScreen_RefreshRateInHz=0;
d3dpp.BackBufferCount=1;
d3dpp.BackBufferFormat = D3DFMT_R5G6B5;//D3DFMT_A8R8G8B8;
d3dpp.BackBufferWidth=800;
d3dpp.BackBufferHeight=600;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
g_pd3dDevice->Reset(&d3dpp);
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: Cleanup()
// Desc: Releases all previously initialized objects
//-----------------------------------------------------------------------------
VOID Cleanup()
{
if( g_pd3dDevice != NULL)
g_pd3dDevice->Release();
if( g_pD3D != NULL)
g_pD3D->Release();
}
//-----------------------------------------------------------------------------
// Name: MsgProc()
// Desc: The window''s message handler
//-----------------------------------------------------------------------------
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_QUIT:
exit(0);
case WM_CLOSE:
UnregisterClass( "SolarTrader", wc.hInstance );
game->InvalidateDeviceObjects();
game->DeleteDeviceObjects();
delete game;
DestroyWindow( hWnd );
PostQuitMessage(0);
return 0;
break;
case WM_SETCURSOR:
// Turn off Windows cursor in fullscreen mode
SetCursor( NULL );
g_pd3dDevice->ShowCursor( TRUE );
return TRUE; // prevent Windows from setting cursor to window class cursor
break;
case WM_CREATE:
break;
}
//return TRUE;
return DefWindowProc( hWnd, msg, wParam, lParam );
}
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: The application''s entry point
//-----------------------------------------------------------------------------
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
srand( (unsigned)time( NULL ) );
{
// Register the windows class
WNDCLASS wndClass = { 0, MsgProc, 0, 0, wc.hInstance,
NULL,
NULL,
(HBRUSH)GetStockObject(WHITE_BRUSH),
NULL, _T("SolarTrader") };
RegisterClass( &wndClass );
// Set the window''s initial style
DWORD m_dwWindowStyle = WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|
WS_MINIMIZEBOX|WS_VISIBLE;
// Set the window''s initial width
RECT rc;
SetRect( &rc, 0, 0, 800, 600 );
AdjustWindowRect( &rc, m_dwWindowStyle, FALSE );
// Create the render window
hWnd = CreateWindow( _T("SolarTrader"), _T("SolarTrader"), m_dwWindowStyle,
CW_USEDEFAULT, CW_USEDEFAULT,
(rc.right-rc.left), (rc.bottom-rc.top), 0L,
0L,
wc.hInstance, 0L );
}
InitD3D();
game=new WFMApp();
game->OneTimeSceneInit();
game->m_hWnd=hWnd;
game->m_pd3dDevice=g_pd3dDevice;
game->InitDeviceObjects();
game->RestoreDeviceObjects();
game->Run();
return 0;
}
run procedure:
INT WFMApp::Run()
{
DXUtil_Timer( TIMER_START );
BOOL bGotMsg;
MSG msg;
msg.message = WM_NULL;
PeekMessage( &msg, NULL, 0U, 0U, PM_NOREMOVE );
while( WM_QUIT != msg.message )
{
bGotMsg = PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE );
if( bGotMsg )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
if( active)
{
this->m_fTime = DXUtil_Timer( TIMER_GETAPPTIME );
this->m_fElapsedTime = DXUtil_Timer( TIMER_GETELAPSEDTIME );
this->FrameMove();
if( FAILED( Render3DEnvironment() ) )
SendMessage( m_hWnd, WM_CLOSE, 0, 0 );
}
}
}
return (INT)msg.wParam;
}
Hi!
I also noticed that all dx applications show window, even if they go into fullscreen mode? Why?
bye,and thanx
I also noticed that all dx applications show window, even if they go into fullscreen mode? Why?
bye,and thanx
It''s the OS, XP seems to do this on some computers. It happens on my roommates computer, but doesn''t happen on mine. Nothing you can do about it./
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement