only getting 45fps ?!

Started by
16 comments, last by steg 20 years, 11 months ago
Hi all, Drawing just two quads using index buffers and my frame count is only 45fps (in window mode) ? The code looks fine, maybe my fps code is incorrect ? I use the following function which is called every frame - FrameRate holds fps. void CD3DManager::FrameCount(INT64& FrameCount, INT64& FrameRate) { INT64 Frequency = 0; INT64 NewCount = 0; INT64 LastCount = 0; INT64 Difference = 0; QueryPerformanceFrequency((LARGE_INTEGER*)&Frequency); QueryPerformanceCounter((LARGE_INTEGER*)&NewCount); FrameCount++; Difference = NewCount - LastCount; if(Difference >= Frequency) { FrameRate = FrameCount; FrameCount = 0; LastCount = NewCount; } } Kind regards, Steve As I get older, my mind becomes more cluttered.

If it isn't working, take a bath, have a think and try again...

Advertisement
You are resetting LastCount every frame. That would do it.
No, that is correct, I think 45fps must be right ?

If it isn't working, take a bath, have a think and try again...

We would help better if we saw the code. But most often the issue is in locking the vertex buffer every frame - i.e. take a look if you don`t have LOCK function call somewhere at the same place as Render. If not, we would need to see the code. Other issue that comes to my mind is graphics card issue. I had problems with my old TNT1 working slower in 640x480 windowed slower than 800x600 fullscreen on certain driver combinations.
Depending on your config I`d expect the framerate about 300 at least.

And also check for VSync - i.e. whether you`re not limited by set frequency - i.e. when you make the change, and the frame stops at 99.99 or 59.99 or 84.99 (most obvious combinations), you know that it`s in this.

If none of this helps, just show us your whole code.

VladR
Avenger game

[edited by - VladR on May 6, 2003 2:37:08 PM]

VladR My 3rd person action RPG on GreenLight: http://steamcommunity.com/sharedfiles/filedetails/?id=92951596

Ok, here is the full code, hope it inserts ok....


          #define WIN32_LEAN_AND_MEAN// The main windows include file#include <windows.h>#include <mmsystem.h>#include <d3d9.h>#include <d3dx9.h>#include "D3DManager.h"#include <stdio.h>#include "Terrain.h"#include "..\..\Camera\camera.h"#include "..\..\TextRender\TextRender.h"int GameInit();int GameLoop();int GameShutdown();int Render();void DisplayCameraPos();LPDIRECT3D9 g_pD3D = 0;LPDIRECT3DDEVICE9 g_pDevice = 0;CD3DManager d3dManager;CTerrain* pTerrain;// Camera objectCCamera camera;// Font objectCTextRender textRenderer;HWND g_hWndMain;// The window procedure to handle eventslong CALLBACK WndProc( HWND hWnd, UINT uMessage,                                 WPARAM wParam, LPARAM lParam ){	// Switch the windows message to figure out what it is	switch( uMessage )	{		case WM_CREATE:	// The CreateWindow() function was just called		{			// One Time Initialization			return 0;		}		case WM_PAINT:	// The window needs to be redrawn		{			ValidateRect( hWnd, NULL );			return 0;		}				case WM_DESTROY:	// The window is about to be closed		{			// Our main window is closing.  This means we want our app to exit.			// Tell windows to put a WM_QUIT message in our message queue			PostQuitMessage( 0 );			return 0;		}		default:			// Some other message		{			// Let windows handle this message			return DefWindowProc( hWnd, uMessage, wParam, lParam );		}	}}// The windows entry point. The application will start executing hereint WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,                                     PSTR pstrCmdLine, int iCmdShow ){//	CTerrain terrain(NULL,1,3);//	terrain.CreateIndices();		HWND hWnd;		// The handle to our main window	MSG msg;		// The message windows is sending us	WNDCLASSEX wc;	// The window class used to create our window	// The name of our class and also the title to our window	static char strAppName[] = "Direct3D Initialization FullScreen";	// Fill in the window class with the attributes for our main window	// The size of this struture in bytes	wc.cbSize			= sizeof( WNDCLASSEX );		//  The style of the window.	wc.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;	// Useless information.  Just set to zero.	wc.cbClsExtra		= 0;	// Useless information.  Just set to zero.	wc.cbWndExtra		= 0;	// The name of our event handler	wc.lpfnWndProc		= WndProc;	// A handle to the applications instance	wc.hInstance		= hInstance;	// The handle to the brush to use for the window background	wc.hbrBackground	= (HBRUSH)GetStockObject( DKGRAY_BRUSH );	// A handle to the icon to use for the window	wc.hIcon			= LoadIcon( NULL, IDI_APPLICATION );	// A handle to a smaller version of the apps icon	wc.hIconSm			= LoadIcon( NULL, IDI_APPLICATION );	// A handle to the cursor to use while the mouse is over our window	wc.hCursor			= LoadCursor( NULL, IDC_CROSS );	// A handle to the resource to use as our menu	wc.lpszMenuName		= NULL;	// The human readable name for this class	wc.lpszClassName	= strAppName;	// Register the class with windows	RegisterClassEx( &wc );	// Create the window based on the previous class	hWnd = CreateWindowEx( WS_EX_TOPMOST,	// Advanced style settings	            strAppName,			// The name of the class				strAppName,			// The window caption				WS_OVERLAPPEDWINDOW,// The window style			   	CW_USEDEFAULT,		// The initial x position                 CW_USEDEFAULT,		// The initial y position			   	640, 480,			// The intiial width / height				NULL,				// Handle to parent window										NULL,				// Handle to the menu				hInstance,			// Handle to the apps instance				NULL );				// Advanced context	g_hWndMain = hWnd;	// Display the window we just created	ShowWindow( hWnd, SW_MINIMIZE );	// Draw the window contents for the first time	UpdateWindow( hWnd );	if( FAILED( GameInit() ) )	{		d3dManager.SetError( "Initialization Failed" );		GameShutdown();		return E_FAIL;	}	// Start the message loop	while( TRUE )	{		// Check if a message is waiting for processing		if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )		{			// Check if the message is to quit the application			if( msg.message == WM_QUIT )				// Exit the message loop				break;						// Change the format of certain messages			TranslateMessage( &msg );			// Pass the message to WndProc() for processing			DispatchMessage( &msg );		}		else		{			GameLoop();		}	}		GameShutdown();	// Return control to windows with the exit code	return msg.wParam;}int GameInit(){		HRESULT r = 0;	// Holds return values		// Acquire a pointer to IDirect3D8	g_pD3D = Direct3DCreate9( D3D_SDK_VERSION );	if( g_pD3D == NULL )	{		d3dManager.SetError( "Could not create IDirect3D8 object" );		return E_FAIL;	}	r= d3dManager.InitDirect3DDevice( g_hWndMain, 800, 600, TRUE, D3DFMT_X8R8G8B8, g_pD3D, &g_pDevice );	if(FAILED(r))	{		d3dManager.SetError("Initialisation of device failed");		return E_FAIL;	}	g_pDevice->Clear(0,0,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0),1.0f,0);	if (FAILED(r))	{		d3dManager.SetError("Couldn't get back buffer");		return E_FAIL;	}	pTerrain = new CTerrain(g_pDevice,1,3);	pTerrain->CreateIndices();	pTerrain->CreateIndexBuffer(18);	pTerrain->CreateTestQuad();	pTerrain->CreateTerrainVertexBuffer();		D3DXMATRIX matProj;	D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );	g_pDevice->SetTransform( D3DTS_PROJECTION, &matProj );	// set up font	textRenderer.Initialize(g_pDevice,(HFONT)::GetStockObject(SYSTEM_FONT),D3DCOLOR_XRGB(0,255,0));	d3dManager.InitGameTime();		return S_OK;}void DisplayCameraPos(){	char buf[200];	static INT64 FrameCount;	static INT64 FrameRate;		d3dManager.UpdateFPS();		textRenderer.SetColour(D3DCOLOR_XRGB(0,255,0));	float x = camera.GetCameraPos().x;	float y = camera.GetCameraPos().y;	float z = camera.GetCameraPos().z;	memset(buf,'\0',sizeof(buf));	sprintf(buf,"World Camera Position:");	textRenderer.OutputText(buf,10,10);	memset(buf,'\0',sizeof(buf));	sprintf(buf,"X %f",x);	textRenderer.OutputText(buf,10,30);	memset(buf,'\0',sizeof(buf));	sprintf(buf,"Y %f",y);	textRenderer.OutputText(buf,10,50);	memset(buf,'\0',sizeof(buf));	sprintf(buf,"Z %f",z);//	textRenderer.OutputText(buf,10,70);	memset(buf,'\0',sizeof(buf));	sprintf(buf,"fps %f",d3dManager.GetFPS());	textRenderer.OutputText(buf,10,70);	}int GameLoop(){	Render();	camera.SetYaw(0);	camera.SetPitch(0);	camera.SetRoll(0);	if( GetAsyncKeyState( VK_ESCAPE ) )		PostQuitMessage(0);	if( GetAsyncKeyState(VK_UP))	{		camera.MoveBackward(0.1f);	}    if( GetAsyncKeyState(VK_DOWN))	{		camera.MoveForward(0.1f);	}	if( GetAsyncKeyState(VK_LEFT))	{		camera.LookLeft(0.005f);	}	if( GetAsyncKeyState(VK_RIGHT))	{		camera.LookRight(0.005f);	}	if( GetAsyncKeyState(VK_NUMPAD4))	{		camera.StrafeLeft(0.03f);	}	if( GetAsyncKeyState(VK_NUMPAD6))	{		camera.StrafeRight(0.03f);	}	if( GetAsyncKeyState(VK_NEXT))	{		camera.LookUp(0.005f);	}	if( GetAsyncKeyState(VK_PRIOR))	{		camera.LookDown(0.005f);	}	if( GetAsyncKeyState(VK_NUMPAD8))	{		camera.StrafeUp(0.05f);	}	if( GetAsyncKeyState(VK_NUMPAD2))	{		camera.StrafeDown(0.05f);	}	if( GetAsyncKeyState(VK_HOME))	{		camera.ResetCamera();	}	return S_OK;}int Render(){	HRESULT r = 0;	g_pDevice->BeginScene()	;	g_pDevice->SetTransform( D3DTS_VIEW, &camera.GetView() );	pTerrain->Render();	camera.Update();	DisplayCameraPos();		g_pDevice->EndScene();	g_pDevice->Present(NULL,NULL,NULL,NULL);	return S_OK;}int GameShutdown(){	if( g_pDevice )		g_pDevice->Release();		// Release the pointer to IDirect3D8	if( g_pD3D )		g_pD3D->Release();	return S_OK;}  



and the terrain class (very much unfinished) :


       // Terrain.cpp: implementation of the CTerrain class.////////////////////////////////////////////////////////////////////////#include <stdio.h>#include <d3d9.h>#include <d3dx9.h>#include "Terrain.h"//////////////////////////////////////////////////////////////////////// Construction/Destruction//////////////////////////////////////////////////////////////////////CTerrain::CTerrain(LPDIRECT3DDEVICE9 pDevice, int xDim, int zDim){	m_pDevice = pDevice;	m_pIndices = NULL;	m_xDim = xDim;	m_zDim = zDim;	m_x = -10.0f;}CTerrain::~CTerrain(){	delete []m_pIndices;}void CTerrain::CreateIndices(){	int index = 0;	int offset = 0;	m_pIndices = new WORD[m_xDim * 6];	for(int x=0; x < m_xDim; x++)	{		for(int z=0; z < m_zDim; z++)		{			m_pIndices[index] = z + offset;                			m_pIndices[index+1] = z + 1 + offset;    			m_pIndices[index+2] = z + 2 + offset;			m_pIndices[index+3] = z + 3 + offset;			m_pIndices[index+4] = z + 2 + offset;			m_pIndices[index+5] = z + 1 + offset;			index += 6;			offset += 1;		}	}	// this is for debug....	char buffer[MAX_PATH];		int n=0;	for(int j=0; j<m_zDim; j++)	{		sprintf(buffer,"%i,%i,%i,%i,%i,%i",m_pIndices[n],m_pIndices[n+1],m_pIndices[n+2],m_pIndices[n+3],m_pIndices[n+4],m_pIndices[n+5]);		n+=6;	}}void CTerrain::CreateTestQuad(){	TERRAINVERTEX TestQuad[] = 	{		// 1st quad		{0,0,0,255},		{0,0,10,255},		{10,0,0,255},		{10,0,10,255},		// 2nd quad - remember, sharing vertices!!!		{20,0,0,155},		{20,0,10,155},			// 3rd quad		{30,0,0,255},		{30,0,10,255}	};	m_pTestQuad = TestQuad;}bool CTerrain::CreateIndexBuffer(UINT nLength){    BYTE* pBufferIndices;	if(m_pIndices==NULL)  // no indices have been created - need to call CreateIndices first!		return false;	    //Create the index buffer from our device    if(FAILED(m_pDevice->CreateIndexBuffer(nLength * sizeof(WORD),                                               0, D3DFMT_INDEX16, D3DPOOL_MANAGED,                                              &m_pIndexBuffer,NULL)))    {        return false;    }            //Get a pointer to the index buffer indices and lock the index buffer     m_pIndexBuffer->Lock(0, nLength * sizeof(WORD), (VOID**)&pBufferIndices, 0);    //Copy our stored indices values into the index buffer    memcpy(pBufferIndices, m_pIndices, nLength * sizeof(WORD));        //Unlock the index buffer    m_pIndexBuffer->Unlock();	return true;}HRESULT CTerrain::CreateTerrainVertexBuffer(){	TERRAINVERTEX TestQuad[] = 	{		// 1st quad		{0,0,0,RGB(0,255,0)},		{0,0,10,RGB(0,255,0)},		{10,0,0,RGB(0,255,0)},		{10,0,10,RGB(0,255,0)},		// 2nd quad - remember, sharing vertices!!!		{20,0,0,RGB(0,255,0)},		{20,0,10,RGB(0,255,0)},			// 3rd quad		{50,0,0,RGB(0,255,0)},		{50,0,10,RGB(0,255,0)}	};		HRESULT r = m_pDevice->CreateVertexBuffer(sizeof(TERRAINVERTEX)*8,0,CUSTOM_ZENVERTEX,D3DPOOL_DEFAULT,&m_pVB,NULL);	if(FAILED(r))	{		return E_FAIL;	}	VOID* pVertices = 0;	r = m_pVB->Lock(0,0,(void**)&pVertices,0);	CopyMemory(pVertices,/*m_p*/TestQuad,8*sizeof(TERRAINVERTEX));	if(FAILED(r))	{		return E_FAIL;	}	m_pVB->Unlock();	return S_OK;}HRESULT CTerrain::Render(){	HRESULT r = 0;	m_pDevice->Clear(0,0,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0),1.0f,0);	D3DXMATRIX matWorld;		D3DXMatrixTranslation(&matWorld, -10,-5,-40.0);//-m_x);	m_pDevice->SetTransform( D3DTS_WORLD, &matWorld );	m_pDevice->SetStreamSource(0,m_pVB, 0,sizeof(TERRAINVERTEX));	m_pDevice->SetFVF(CUSTOM_ZENVERTEX);	m_pDevice->SetRenderState(D3DRS_LIGHTING,FALSE);	m_pDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);	m_pDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);	m_pDevice->SetIndices(m_pIndexBuffer);	// draw 2nd one - 4,0,4,0,2	//	g_pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,4,0,4,0,2);	// 8 vertices, 6 triangles!	m_pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,8,0,6);		m_x += 0.08f;	return S_OK;}  




and the manager class :



     // Direct3D Wrapper V1.0a// (C) 2001-2002 S.Green#ifndef __D3DMANAGER__#define __D3DMANAGER__#pragma comment(lib,"d3dx9.lib")class CD3DDebugManager {public:  CD3DDebugManager() { };  void SetError( char* String );  void ShowInfo( char* String );}; class CD3DManager : public CD3DDebugManager{public:  CD3DManager();  int InitDirect3DDevice( HWND hWndTarget, int Width, int Height, BOOL bWindowed, 							D3DFORMAT FullScreenFormat, LPDIRECT3D9 pD3D, 							LPDIRECT3DDEVICE9* ppDevice );  int GetBackBuffer();  HRESULT ValidateDevice(LPDIRECT3DDEVICE9 ppDevice,   LPDIRECT3DSURFACE9 pBacksurface);  HRESULT CreateViewPort(LPDIRECT3DDEVICE9 ppDevice, DWORD dwWidth, DWORD dwHeight);  HRESULT SetTexture(char* szFilename);  LPDIRECT3DTEXTURE9 GetTexture();  // Object Culling methods  void       SetBoundingSphere(PVOID pvPointsFVF, DWORD dwNumVertices, DWORD FVF, D3DXVECTOR3* pCenter, FLOAT* pRadius);  D3DXMATRIX GetViewMatrix();  D3DXMATRIX GetProjectionMatrix();  D3DXMATRIX GetViewFrustum();  void       ExtractFrustum();  BOOL		 PointInFrustum( float x, float y, float z );  BOOL		 SphereInFrustum( float x, float y, float z, float radius );  BOOL		 SphereInFrustum( float x, float y, float z, float radius, float rx, float ry, float rz );  void		 FrameCount(INT64& FrameCount, INT64& FrameRate);  void	     InitGameTime();  float      GetGameTime();  void       UpdateFPS();  float		 GetFPS() { return m_fps; }  private:  HRESULT RestoreGraphics();  double frustum[6][4];  // 4 planes (ABCD), 6 faces  BOOL m_bTextureSet;  LPDIRECT3DSURFACE9 m_pBackSurface;  LPDIRECT3DDEVICE9  m_pDevice;  LPDIRECT3DTEXTURE9 m_pTexture;  D3DPRESENT_PARAMETERS m_d3dpp;  D3DDISPLAYMODE m_d3ddm;  int m_DeviceWidth;  int m_DeviceHeight;  float  m_timeAtGameStart;  UINT64 m_ticksPerSecond;  float  m_lastUpdate;  float  m_fpsUpdateInterval;  UINT   m_numFrames;  float  m_fps; };CD3DManager::CD3DManager(){	m_fps = 0;	m_fpsUpdateInterval = 0.5f;	m_lastUpdate = 0;	m_numFrames = 0;}void CD3DManager::FrameCount(INT64& FrameCount, INT64& FrameRate){	INT64 Frequency = 0;	INT64 NewCount = 0;    INT64 LastCount = 0;	INT64 Difference = 0;	QueryPerformanceFrequency((LARGE_INTEGER*)&Frequency);	QueryPerformanceCounter((LARGE_INTEGER*)&NewCount);	FrameCount++;	Difference = NewCount - LastCount;	if(Difference >= Frequency)	{		FrameRate = FrameCount;		FrameCount = 0;		LastCount = NewCount;	}}void CD3DManager::InitGameTime(){  // We need to know how often the clock is updated  if( !QueryPerformanceFrequency((LARGE_INTEGER *)&m_ticksPerSecond) )    m_ticksPerSecond = 1000;  // If timeAtGameStart is 0 then we get the time since  // the start of the computer when we call GetGameTime()  m_timeAtGameStart = 0;  m_timeAtGameStart = GetGameTime();}// Called every time you need the current game timefloat CD3DManager::GetGameTime(){  UINT64 ticks;  float time;  // This is the number of clock ticks since start  if( !QueryPerformanceCounter((LARGE_INTEGER *)&ticks) )    ticks = (UINT64)timeGetTime();  // Divide by frequency to get the time in seconds  time = (float)(__int64)ticks/(float)(__int64)m_ticksPerSecond;  // Subtract the time at game start to get  // the time since the game started  time -= m_timeAtGameStart;  return time;}void CD3DManager::UpdateFPS(){  m_numFrames++;  FLOAT currentUpdate = 0;  currentUpdate = GetGameTime();  if( currentUpdate - m_lastUpdate > m_fpsUpdateInterval )  {    m_fps = m_numFrames / (currentUpdate - m_lastUpdate);    m_lastUpdate = currentUpdate;    m_numFrames = 0;  }}// Output an error to the debug windowvoid CD3DDebugManager::SetError( char* String ){	OutputDebugString( "ERROR: " );	OutputDebugString( String );	OutputDebugString( "\n" );}void CD3DDebugManager::ShowInfo( char* String ){	OutputDebugString( "Info: " );	OutputDebugString( String );	OutputDebugString( "\n" );}// Call every frame to check if the device is valid.  If it// is not then it is re-aquirred if possible// !!!!THIS NEEDS FIXING!!!!HRESULT CD3DManager::ValidateDevice(LPDIRECT3DDEVICE9 ppDevice,   LPDIRECT3DSURFACE9 pBacksurface){	HRESULT r = 0;	if (!ppDevice)		return E_FAIL;		// Test the current state of the device	r = ppDevice->TestCooperativeLevel();	if( FAILED( r ) )	{		// If the device is lost then return failure		if( r == D3DERR_DEVICELOST )			return E_FAIL;		// If the device is ready to be reset then attempt to do so		if( r == D3DERR_DEVICENOTRESET )		{			// Release the back surface so it can be recreated			pBacksurface->Release();			// Reset the device			r = ppDevice->Reset( &m_d3dpp);			if( FAILED( r ) )			{				// If the device was not reset then exit				SetError( "Could not reset device" );				PostQuitMessage( E_FAIL );				return E_FAIL;			}						// Reaquire a pointer to the new back buffer			r = ppDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBacksurface );			if( FAILED( r ) )			{				SetError( "Unable to reaquire the back buffer" );				PostQuitMessage( 0 );				return E_FAIL;			}			ppDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 0, 0, 0 ), 0.0f, 0 );			RestoreGraphics();		}	}	return S_OK;}HRESULT CD3DManager::CreateViewPort(LPDIRECT3DDEVICE9 ppDevice, DWORD dwWidth, DWORD dwHeight){	HRESULT r = 0;	if (!ppDevice)		return E_FAIL;		D3DVIEWPORT9 ViewPort;	ViewPort.X = 0; 	ViewPort.Y = 0;	ViewPort.Width = dwWidth;	ViewPort.Height = dwHeight;	ViewPort.MaxZ = 1.0f;	ViewPort.MinZ = 0.0f;	return r = ppDevice->SetViewport(&ViewPort);	}// Use this function to reinit any surfaces that were lost// when the device was lost.HRESULT CD3DManager::RestoreGraphics(){		return S_OK;}int CD3DManager::GetBackBuffer(){	return m_pDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &m_pBackSurface);}// Initializes the Direct3D deviceint CD3DManager::InitDirect3DDevice( HWND hWndTarget, int Width, int Height, BOOL bWindowed, 							D3DFORMAT FullScreenFormat, LPDIRECT3D9 pD3D, 							LPDIRECT3DDEVICE9* ppDevice ) {	// Structure to hold information about the rendering method	HRESULT r = 0;		if( *ppDevice )		(*ppDevice)->Release();	// Initialize the structure to 0	ZeroMemory( &m_d3dpp, sizeof( D3DPRESENT_PARAMETERS ) );	// Get the settings for the current display mode	if(bWindowed)	{			r = pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &m_d3ddm );		if( FAILED( r ) )		{			SetError( "Could not get display adapter information" );			return E_FAIL;		}	}	else 	{		m_d3ddm.Format = D3DFMT_R5G6B5;		m_d3ddm.Width = Width;		m_d3ddm.Height = Height;		m_d3ddm.RefreshRate = 0;	}	// The width of the back buffer in pixels	m_d3dpp.BackBufferWidth = Width;	// The height of the buffer in pixels	m_d3dpp.BackBufferHeight = Height;	// The format of the back buffer	m_d3dpp.BackBufferFormat = bWindowed ? m_d3ddm.Format : FullScreenFormat;	// The number of back buffers	m_d3dpp.BackBufferCount = 1;	// The type of multisampling	m_d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;	// The swap effect - wait for vsync if full screen	m_d3dpp.SwapEffect = bWindowed ? m_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD : /*COPY :*/	                   m_d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP;// D3DSWAPEFFECT_COPY_VSYNC;	// The handle to the window that we want to render to 	m_d3dpp.hDeviceWindow = hWndTarget;		// Windowed or fullscreen	m_d3dpp.Windowed = bWindowed;	// Let Direct3D manage the depth buffer	m_d3dpp.EnableAutoDepthStencil = TRUE;	// Set the depth buffer format to 16 bits	m_d3dpp.AutoDepthStencilFormat = D3DFMT_D16;		// Use the default refresh rate available	m_d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;		// Present the information as fast as possible	m_d3dpp.PresentationInterval = bWindowed ? 0 : D3DPRESENT_INTERVAL_IMMEDIATE;	//m_d3dpp.FullScreen_PresentationInterval = bWindowed ? 0 : D3DPRESENT_INTERVAL_IMMEDIATE;	// Allow the back buffer to be accessed for 2D work	m_d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;	// Acquire a pointer to IDirect3DDevice8	r = pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWndTarget,							D3DCREATE_HARDWARE_VERTEXPROCESSING, 							&m_d3dpp, ppDevice );	if( FAILED( r ) )	{		SetError( "Could not create the render device" );		return E_FAIL;	}	m_pDevice = *ppDevice;		// Save global copies of the device dimensions	m_DeviceHeight = Height;	m_DeviceWidth = Width;	return S_OK;}inline LPDIRECT3DTEXTURE9 CD3DManager::GetTexture(){	return m_pTexture;}D3DXMATRIX CD3DManager::GetViewMatrix(){	D3DXMATRIX view;	m_pDevice->GetTransform(D3DTS_VIEW, &view);	return view;}D3DXMATRIX CD3DManager::GetProjectionMatrix(){	D3DXMATRIX projection;	m_pDevice->GetTransform(D3DTS_PROJECTION, &projection);	return projection;}D3DXMATRIX CD3DManager::GetViewFrustum(){	D3DXMATRIX ViewFrustum;	D3DXMatrixMultiply( &ViewFrustum, &GetViewMatrix(), &GetProjectionMatrix() );	return ViewFrustum;}void CD3DManager::ExtractFrustum(){	double t;	D3DXMATRIX clip;	clip = GetViewFrustum();// RIGHT PLANE	frustum[0][0] = clip._14 - clip._11;	frustum[0][1] = clip._24 - clip._21;	frustum[0][2] = clip._34 - clip._31;	frustum[0][3] = clip._44 - clip._41;	t = sqrt( frustum[0][0] * frustum[0][0] + frustum[0][1] * frustum[0][1] + frustum[0][2] * frustum[0][2] );	frustum[0][0] /= t;	frustum[0][1] /= t;	frustum[0][2] /= t;	frustum[0][3] /= t;	// LEFT PLANE	frustum[1][0] = clip._14 + clip._11;	frustum[1][1] = clip._24 + clip._21;	frustum[1][2] = clip._34 + clip._31;	frustum[1][3] = clip._44 + clip._41;	t = sqrt( frustum[1][0] * frustum[1][0] + frustum[1][1] * frustum[1][1] + frustum[1][2] * frustum[1][2] );	frustum[1][0] /= t;	frustum[1][1] /= t;	frustum[1][2] /= t;	frustum[1][3] /= t;	// BOTTOM PLANE	frustum[2][0] = clip._14 + clip._12;	frustum[2][1] = clip._24 + clip._22;	frustum[2][2] = clip._34 + clip._32;	frustum[2][3] = clip._44 + clip._42;	t = sqrt( frustum[2][0] * frustum[2][0] + frustum[2][1] * frustum[2][1] + frustum[2][2] * frustum[2][2] );	frustum[2][0] /= t;	frustum[2][1] /= t;	frustum[2][2] /= t;	frustum[2][3] /= t;	// TOP PLANE	frustum[3][0] = clip._14 - clip._12;	frustum[3][1] = clip._24 - clip._22;	frustum[3][2] = clip._34 - clip._32;	frustum[3][3] = clip._44 - clip._42;	t = sqrt( frustum[3][0] * frustum[3][0] + frustum[3][1] * frustum[3][1] + frustum[3][2] * frustum[3][2] );	frustum[3][0] /= t;	frustum[3][1] /= t;	frustum[3][2] /= t;	frustum[3][3] /= t;	// FAR PLANE	frustum[4][0] = clip._14 - clip._13;	frustum[4][1] = clip._24 - clip._23;	frustum[4][2] = clip._34 - clip._33;	frustum[4][3] = clip._44 - clip._43;	t = sqrt( frustum[4][0] * frustum[4][0] + frustum[4][1] * frustum[4][1] + frustum[4][2] * frustum[4][2] );	frustum[4][0] /= t;	frustum[4][1] /= t;	frustum[4][2] /= t;	frustum[4][3] /= t;	// NEAR PLANE	frustum[5][0] = clip._14 + clip._13;	frustum[5][1] = clip._24 + clip._23;	frustum[5][2] = clip._34 + clip._33;	frustum[5][3] = clip._44 + clip._43;	t = sqrt( frustum[5][0] * frustum[5][0] + frustum[5][1] * frustum[5][1] + frustum[5][2] * frustum[5][2] );	frustum[5][0] /= t;	frustum[5][1] /= t;	frustum[5][2] /= t;	frustum[5][3] /= t;}BOOL CD3DManager::SphereInFrustum( float x, float y, float z, float radius ){   int p;   for( p = 0; p < 6; p++ )   {      if( frustum[p][0] * x + frustum[p][1] * y + frustum[p][2] * z + frustum[p][3] <= -radius )         return false;   }   return true;}BOOL CD3DManager::SphereInFrustum( float x, float y, float z, float radius, float rx, float ry, float rz ){   int p;   for( p = 0; p < 6; p++ )   {      if( frustum[p][0] * (x + rx) + frustum[p][1] 						* (y + ry) + frustum[p][2] 						* (z + rz) + frustum[p][3] <= -radius )         return false;   }   return true;}BOOL CD3DManager::PointInFrustum( float x, float y, float z ){   int p;   for( p = 0; p < 6; p++ )   {      if( frustum[p][0] * x + frustum[p][1] * y + frustum[p][2] * z + frustum[p][3] <= 0 )         return false;   }   return true;}HRESULT CD3DManager::SetTexture(char* szFilename){	HRESULT r = 0;	m_bTextureSet = FALSE;	if (m_pTexture)		m_pTexture->Release();	r = D3DXCreateTextureFromFile(m_pDevice, szFilename, &m_pTexture);	if(SUCCEEDED(r))	{		m_bTextureSet = TRUE;		return S_OK;	}	return E_FAIL;}void CD3DManager::SetBoundingSphere(PVOID pvPointsFVF, DWORD dwNumVertices, DWORD FVF, D3DXVECTOR3* pCenter, FLOAT* pRadius){	D3DXComputeBoundingSphere((D3DXVECTOR3*)pvPointsFVF, dwNumVertices, FVF, pCenter, pRadius);}#endif  


The fps is displayed in the DisplayCameraPos function within the first lot of code I showed -> d3dManager.UpdateFPS(), this function is found in the last bit of code (the manager class) above.

Kind regards,
Steve



[edited by - steg on May 7, 2003 3:34:15 AM]

[edited by - steg on May 7, 2003 3:35:20 AM]

[edited by - steg on May 7, 2003 3:36:57 AM]

[edited by - steg on May 7, 2003 3:38:55 AM]

If it isn't working, take a bath, have a think and try again...

Just ran it in full screen mode and I get 400 fps.....

Steve

As I get older, my mind becomes more cluttered.

If it isn't working, take a bath, have a think and try again...

BTW, where do you have the code for frustum planes ? I`d bet my hand that it`s my code I copied here recently at one thread. I even remember the spacing in function pointionfrustum and sphereinfrustum not mentioning the variable names

VladR
Avenger game

VladR My 3rd person action RPG on GreenLight: http://steamcommunity.com/sharedfiles/filedetails/?id=92951596

Sorry VladR but the code I did some 2 years ago (dated at top of code), honest. I think I got the frustum plane stuff from a tutorial off the web, maybe we used the same tutorial - I can''t really remember what it was now, maybe Mark Morley ? And the sphereinfrustum method etc, I did at the same time, I did put a mod in recently in the setboundingsphere as I''m now using DX9.
I use this code from frustum culling.

I have had a big break in game development, only recently started to get back into it, boy how I wished I had stuck with it!

Weird huh ?!

Regards,
Steve

If it isn't working, take a bath, have a think and try again...

quote:I think I got the frustum plane stuff from a tutorial off the web, maybe we used the same tutorial

Me too - so we must have the same original source then. It was long ago, but I remember it had an OpenGL implementation and that it was pdf format. But we both left the original names and spacing the same as it was. Funny.

quote:I have had a big break in game development, only recently started to get back into it, boy how I wished I had stuck with it!
Did life cross your gamedev route ? I had a long 3 motnhs break last year in September. It sucked a lot when I returned and watched the code from half a year back. Can`t imagine two years however. You can probably just start from scratch.

VladR
Avenger game


[edited by - VladR on May 7, 2003 7:02:32 AM]

VladR My 3rd person action RPG on GreenLight: http://steamcommunity.com/sharedfiles/filedetails/?id=92951596

VladR

It was an OpenGL function if I recall now.

Yes, two years is a long time, I''ve only been back into it for around a few months, still, the old stuff is still around ;-)

Struggling at the moment to come up with a way to generate my indices for my index buffer for my terrain, can''t seem to find a pattern ?

BTW - the game looks good ;-)

Regards,
Steve

If it isn't working, take a bath, have a think and try again...

This topic is closed to new replies.

Advertisement