• entries
707
1173
• views
435848

# Sooner than I thought

289 views

Well, I finished the code base sooner than I had though I would. The only thing left to add is my own font class, but with the way I set up the font engine, I can add that once I figure out how I want to do it (not sure if I want to do variable-width or fixed-width, we'll see). The codebase now consists of this:
//common (dftcb)DebugOutput()*FormattedDebugOutput()IniFileDllFileDllInterface<>SingletonListType*Manager::SingletonTimer*Window::Singleton//graphics (dftgfx)Direct3D::SingletonTexture::ListTypeTexturePool::ManagerVertexBufferIndexBufferIFont::ListTypeFontEngine::Manager//input (dftin)enum InputMessagesenum InputKeysenum InputButtonsInputEventtypedef void (*EVENTPROC)(InputEvent Event)DirectInput*

Edit:
DebugOutput* - Forgot to mention that this uses html and CSS for output. The user has to state wether or not there was an error, if so the font class is changed to Error. The CSS is in a separate file so that the user can customize how it looks.

ListType* - This is a base class for any class that will be used with Manager. Manager assumes that the list type that it is using has 3 functions: GetID(), Compare(), and Release().

Timer* - My Timer class does not keep track of the frame rate. You use Start() and End() to figure out how long something took, be it a frame or just part of your code. End can take a string. If one is passed to it, it uses FormattedDebugOutput() to write a string in the form of Profile(Name:%s, Time Elapsed: %f). Where the %s is the string that you pass in.

DirectInput* - DirectInput allows for event based and non event based input. You can switch back and forth with a simple function call.

I also have taken some time to write out some render state classes. These are simple classes like this:
class rsAlphaBlending{    static bool        m_bEnabled;    static D3DBLEND    m_SrcBlend, m_DestBlend;public:    static void SetBlendMode(D3DBLEND SrcBlend, D3DBLEND DestBlend)    {        if(m_SrcBlend != SrcBlend)        {            dftcb::Direct3D::GetSingleton()->GetDeviceComPtr()->SetRenderState((D3DRENDERSTATETYPE)RS_SRCBLEND, SrcBlend);            m_SrcBlend = SrcBlend;        }        if(m_DestBlend != DestBlend)        {            dftcb::Direct3D::GetSingleton()->GetDeviceComPtr()->SetRenderState((D3DRENDERSTATETYPE)RS_DESTBLEND, DestBlend);            m_DestBlend = DestBlend;        }    }    static void Enable()    {        if(!m_bEnabled)        {            dftcb::Direct3D::GetSingleton()->GetDeviceComPtr()->SetRenderState((D3DRENDERSTATETYPE)RS_ALPHABLENDENABLE, TRUE);            m_bEnabled = true;        }    }    static void Disable()    {        if(m_bEnabled)        {            dftcb::Direct3D::GetSingleton()->GetDeviceComPtr()->SetRenderState((D3DRENDERSTATETYPE)RS_ALPHABLENDENABLE, FALSE);            m_bEnabled = false;        }    }    static bool     IsEnabled()         { return m_bEnabled;    }    static D3DBLEND GetSrcBlendMode()   { return m_SrcBlend;    }    static D3DBLEND GetDestBlendMode()  { return m_DestBlend;   }};bool        rsAlphaBlending::m_bEnabled     = false;D3DBLEND    rsAlphaBlending::m_SrcBlend     = D3DBLEND_ONE;D3DBLEND    rsAlphaBlending::m_DestBlend    = D3DBLEND_ZERO;// Then you use it like sorsAlphaBlending::SetBlendMode(D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA);rsAlphaBlending::Enable();//draw alpha blended objectsrsAlphaBlending::Disable();//draw non alpha-blended objects

The source code for everything will be available (for free) once I finish the first game. I want to make sure it all works and works right before I release it.

Yuck, variable-width font classes. I think the real nightmare part of them isn't the usage, but loading them from a file. I used SDL_ttf (or SDL_tff, or something) awhile back and its glyph-loading functions had some quirks.

Like... the surfaces they returned would just fit the glyph, meaning you have to figure out how to position each letter yourself. Quite the pain. I think the solution was to load each letter with the '|' character so they all were positioned right.

But yeah. I hate writing font buggers - and I'll need to fix up the one I have now so it doesn't create a new surface everytime you call drawText(..) [sad]

lol yea, thats why I've always stuck with fixed width fonts. The thing that I'm really worried about is rendering. I'm rendering each letter to a quad, which seems to keep up quite well with ID3DXFont until I start rendering really long text, then mine slows down, but this shouldn't be a problem because I was rendering almost 1024 characters lol.

On a different note: WOHOO I've started my 2D demo! I'm working on the tile system right now, so I'll probably post a screenshot of that when I'm done.

Although my code was never as pretty, I can certainly relate to your woes. When I have the urge for drawing text/fonts, I either grab some freeware OGL lib or the D3D Font interface. If neither are within reach, I'll curl up into a ball and lay in the corner until the desire goes away.

Looking forward to seeing your game once all of this groundwork is done! :)

Hey, thats a great idea! I'll have to try it sometime, but I'll have to clear out a corner :D.

## Create an account

Register a new account