It was working, drawing the frame rate, no problems. But now if I run the app from the debug directory it just quits out.
Using debug->start in visual studio .net (c++, direct 3d9) I got this error:
unhandled exception at 0x77f767cd
Here's my code:
setting up the font
//setting up the font
////FONT
D3DXCreateFont(g_pD3DDevice9, //D3D Device
22, //Font height
0, //Font width
FW_NORMAL, //Font Weight
1, //MipLevels
false, //Italic
DEFAULT_CHARSET, //CharSet
OUT_DEFAULT_PRECIS, //OutputPrecision
ANTIALIASED_QUALITY, //Quality
DEFAULT_PITCH|FF_DONTCARE,//PitchAndFamily
"Arial", //pFacename,
&g_pFont); //ppFont
Heres the game loop
//game loop
void Game_Loop()
{
////RECOVER FROM ALT TAB
HRESULT hr;
hr=g_pD3DDevice9->TestCooperativeLevel();
if(hr==D3DERR_DEVICELOST)
{ //Device is lost and cannot be reset yet
Sleep(500); //Wait a bit so we don't burn through cycles for no reason
FreeVolatileResources();
}
else if(hr==D3DERR_DEVICENOTRESET)
{ //Lost but we can reset it now
hr=g_pD3DDevice9->Reset(&g_d3dpp);
if(SUCCEEDED(hr))
InitVolatileResources();
}
////RENDER
//clear back buffer to white
g_pD3DDevice9->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(255,255,0),1.0f,0);
g_pD3DDevice9->BeginScene();
g_pD3DDevice9->SetFVF(g_dwFVF);
g_pD3DDevice9->SetStreamSource(0,g_pVertexBuffer,0,sizeof(VERTEX));
//Render from Vertex Buffer
g_pD3DDevice9->DrawPrimitive(D3DPT_TRIANGLELIST,0,g_primitive_count);
g_pD3DDevice9->EndScene();
//FRAMES PER SECOND
g_nFrames++;
DWORD dwFpsTime=GetTickCount();
//when 1 second has passed display the frames per second
if (dwFpsTime>(g_dwLastFpsLog+1000))
{
//store max fps and current fps
g_nCurrentFrames=g_nFrames;
if(g_nCurrentFrames>g_nMaxFrames)g_nMaxFrames=g_nCurrentFrames;
//reset frames and record time when we last showed fps
g_nFrames=0;
g_dwLastFpsLog=dwFpsTime;
}
//store max frames and fps in a string
g_StrStream<<"Max Frames: "<<g_nMaxFrames<<" Current Frames: "<<g_nCurrentFrames;
string strFrameRate=g_StrStream.str();
const char *c_chFrameRate=strFrameRate.c_str();
g_StrStream.str("");
//setup up rect for fps
RECT recFrameRate;
recFrameRate.left=0;
recFrameRate.top=0;
recFrameRate.right=100;
recFrameRate.bottom=100;
//DRAW FPS
g_pFont->DrawText(NULL,c_chFrameRate,
-1,&recFrameRate,DT_LEFT|DT_NOCLIP,D3DCOLOR_XRGB(0,0,0));//crashes at this point
//crash is an execution crash, so there were no compile errors
//flip back buffer
g_pD3DDevice9->Present(NULL,NULL,NULL,NULL);
}
void InitVolatileResources()
{
//Init internal resources
g_pFont->OnResetDevice();
}
void FreeVolatileResources()
{
//Free up some internal resources
g_pFont->OnLostDevice();
}
here's the global section relating to fonts
//globals.h
#ifndef __GLOBALS_H__
#define __GLOBALS_H__
#include <d3d9.h>
#include <d3dx9.h>
extern ID3DXFont *g_pFont;//font
#endif
//globals.cpp
#include "globals.h"
ID3DXFont *g_pFont=NULL;//font
Anyone able to help?
[Edited by - utilae on February 15, 2005 8:26:23 PM]