Okay with the text addon i got maybe 1 or 2 fps increase (now at 3 or 4) using the edited version given in that post, and with itoa i sometimes get 1 extra. heres my edited source, i can figure out for the life of me how to get text on top like I want without sacrificing speed(I only lose speed when the mouse is moving btw which makes me think its the get image part)
Text.h
// Text.h
#pragma once
typedef enum E_TEXT_ALIGN_TYPE
{
ALIGN_LEFT,
ALIGN_CENTER,
ALIGN_RIGHT
} TEXT_ALIGN_TYPE;
class CText
{
public:
CText(void);
~CText(void);
static void InitTextOnce();
void SetFont(char *pFont, int nFontSize, int nFontBold, int nFontItalic);
void SetTextColor(BYTE r, BYTE g, BYTE b, BYTE a);
static void StartText(void);
static void EndText(void);
void TextOut(int x, int y, TEXT_ALIGN_TYPE nAlign, char *pString);
private:
static IDirect3DDevice9* s_pDevice;
static ID3DXSprite* s_pTextSprite;
static int s_iSpriteRefCount;
BYTE m_cRed;
BYTE m_cGreen;
BYTE m_cBlue;
BYTE m_cAlpha;
ID3DXFont* m_pFont;
};
Text.cpp
// Text.cpp
#include "Gloabl Header.h"
IDirect3DDevice9* CText::s_pDevice = NULL;
ID3DXSprite* CText::s_pTextSprite = NULL;
int CText::s_iSpriteRefCount = 0;
CText::CText(void) // Constructor
{
m_pFont = NULL;
m_cRed = 0xff; // Standard color/alpha values
m_cGreen = 0xff;
m_cBlue = 0xff;
m_cAlpha = 0xff;
CText::s_iSpriteRefCount++;
}
CText::~CText(void) // Destructor
{
if (m_pFont) { m_pFont->Release(); m_pFont = NULL; }
CText::s_iSpriteRefCount--;
if (s_iSpriteRefCount>0) return;
if (s_pTextSprite) { s_pTextSprite->Release(); s_pTextSprite = NULL; }
}
void CText::InitTextOnce() // Call once, to receive the Device pointer
{
CText::s_pDevice = dbGetDirect3DDevice();
}
void CText::SetTextColor(BYTE r, BYTE g, BYTE b, BYTE a)
{
m_cRed = r;
m_cGreen = g;
m_cBlue = b;
m_cAlpha = a;
}
void CText::SetFont(char *pFont, int iFontSize, int iFontBold, int iFontItalic)
{
if (m_pFont)
{
m_pFont->Release();
m_pFont = NULL;
}
HRESULT hr;
HDC hDC = GetDC(NULL);
int nLogPixelsY = GetDeviceCaps(hDC, LOGPIXELSY);
ReleaseDC(NULL, hDC);
int iRealSize = -iFontSize * nLogPixelsY / 72;
hr = D3DXCreateFont( CText::s_pDevice, // D3D device
iRealSize, // Height
0, // Width
(iFontBold?FW_BOLD:FW_NORMAL), // Weight
1, // MipLevels, 0 = autogen mipmaps
(iFontItalic?true:false), // Italic
DEFAULT_CHARSET, // CharSet
OUT_DEFAULT_PRECIS, // OutputPrecision
DEFAULT_QUALITY, // Quality
DEFAULT_PITCH | FF_DONTCARE, // PitchAndFamily
pFont, // pFaceName
&m_pFont); // ppFont
if (hr != S_OK) return; // Error, do not create Sprite.
m_pFont->PreloadGlyphs(32,180);
if (!CText::s_pTextSprite) D3DXCreateSprite(CText::s_pDevice, &CText::s_pTextSprite);
}
void CText::StartText(void) // Call before one or more TextOut blocks
{
if (!CText::s_pTextSprite) return;
CText::s_pTextSprite->Begin(D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_TEXTURE);
}
void CText::EndText(void) // Call after one or more TextOut blocks
{
if (!CText::s_pTextSprite) return;
CText::s_pTextSprite->End();
}
void CText::TextOut(int x, int y, TEXT_ALIGN_TYPE nAlign, char *pString)
{
if ((!CText::s_pTextSprite)||(!m_pFont)) return;
RECT rc;
SetRect(&rc, x, y, 0, 0 );
D3DCOLOR dwColor = D3DCOLOR_ARGB(m_cAlpha, m_cRed, m_cGreen, m_cBlue);
switch (nAlign)
{
case ALIGN_LEFT: break; // align left is standard
case ALIGN_CENTER:
{
m_pFont->DrawText(CText::s_pTextSprite, pString, -1, &rc, DT_CALCRECT, dwColor);
rc.left = x-((rc.right-x)/2); // only set rc.left. drawing NO_CLIP
break;
}
case ALIGN_RIGHT:
{
m_pFont->DrawText(CText::s_pTextSprite, pString, -1, &rc, DT_CALCRECT, dwColor);
rc.left = x-(rc.right-x); // only set rc.lect. drawing NO_CLIP
break;
}
}
m_pFont->DrawText(CText::s_pTextSprite, pString, -1, &rc, DT_NOCLIP, dwColor);
}
My Source
#include "DarkGDK.h"
#include "iostream"
#include "sstream"
#include "text.h"
#include <stdio.h>
#include <stdlib.h>
using namespace std;
//nessisary functions
void spr_paste(int id, int x, int y, int img);
//text
CText *txt=NULL;
// the main entry point for the application is this function
void DarkGDK ( void )
{
CText::InitTextOnce();//setups text objects
txt=new CText();
txt->SetFont("Arial",12,1,0);
txt->SetTextColor(0,0,0,255);
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
//get data variables
int mx=dbMouseX();
int oldmx=mx;
char buffer[125];
itoa(dbMouseX(),buffer,12);
//set nessisary display options
dbDrawSpritesFirst();
//load in nessesary images
dbLoadImage("Media/Other/Back.JPG",1);
dbLoadImage("Media/Other/Tbar.JPG",2);
dbLoadImage("Media/Other/data.JPG",3);
//create sprites from images
dbSprite(1,1,1,1);
dbSprite(2,5,1,2);
dbSprite(3,110,1,3);
// our main loop
while ( LoopGDK ( ) )
{
//re-draw sprites
spr_paste(1,1,1,1);
spr_paste(2,5,1,2);
//this sprite is setup to accept text
spr_paste(3,110,1,3);
//grab the screen and make a new sprite out of it
if(oldmx!=mx)
{
dbGetImage(50000,0,0,640,480);
dbSprite(50000,0,0,50000);
dbDeleteImage(50000);
}
//draw data bar information
itoa(dbScreenFPS(),buffer,12);
dbSetWindowTitle(buffer);
dbInk(dbRGB(0, 0, 0), dbRGB(0, 0, 0));
oldmx=mx;
mx=dbMouseX();
itoa(dbMouseX(),buffer,12);
CText::StartText();
txt->TextOut(120,4,ALIGN_LEFT,buffer);
CText::EndText();
//dbText(120,4,buffer);
// update the screen
dbSync ( );
}
// return back to windows
return;
}
void spr_paste(int id, int x, int y, int img)
{
dbSprite(id,x,y,img);
dbPasteSprite(id,x,y);
dbDeleteSprite(id);
}
also with itoa my mouse x variable displays a letter now so it can say like 20a or 150b mostly only a's and b's tho
Show me your combat algorithms(programmers read this NOT in a programming state of mind)