Adding a console

Started by
11 comments, last by Calin 18 years, 4 months ago
Hello, I'd like to add a console to my 'engine'. I have no idea on how I can do with DirectX 9.0. I think to use an IDirect3DSurface9 surface. Apparently, fonts are only rendering to the backbuffer. Is it possible to render to a surface? Do I have to use bitmapped fonts? I'm also wondering how I can blit the surface on the backbuffer with alpha blending... (I use StrechRect()). All ideas are welcome... Thanks in advance!
Advertisement
I think you're reinventing the wheel... I would use a 3rd party API for the GUI or at the very least a windows control from VisualStudio.
Hi gael!
I saw an article on making a Quake stile console in the GameDev Articles section. I think it was for DirectX but it might be a little outdated though.
As for ideea itself my opinion is that a console like that is not worth the effort. It takes a significant time to build and it eats resources at run time.
For debugging usualy a simple log file is sufficient. Also if you want to change game parameters at run time you can find another 100 ways to do it.

My project`s facebook page is “DreamLand Page”

Nearly every game has a console, makes life so much easier. Shouldn't take more then 2-8 hours to implement either. Not sure how it "eats resources at runtime" but I never noticed a difference in my frame rates. I used my in game console for changing params, while I used a dos box to output data on specific objects (have it on another screen).

Only thing I could find was this:
http://geekswithblogs.net/jolson/articles/2659.aspx

Hope it helps.

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

To make a console you will have to look at what a console is. A general console is a simple quad that gets pulled down over your existing application. This means that you will need a quad (Simple interface for debugging and giving your engine instructions), a way to give your console an interactive environment (be able to send and receive messages from your engine).

With that said you can use a couple of methods and the most general way is to implement a scripting engine/language such as LUA or Python and many more. You will then use your scripting language as the middleware that will work between your engine and the user.

The interface screen is really a trivial exercise and all you need to do is poll your engine for a specific key such as the tilde(~) and then bring down a transparent/textured quad that will allow the user to enter commands. You can place your engine in a paused state or a state of your liking. Furthermore you will then have to create a way for your engine to poll your keyboard for keys pressed and when the keys are pressed print them to the console window, when you then press enter you will do some comparisons to check for existing methods that you might want to call.

This is just a basic outline and an article or 2 might have been written explaining this in great detail.
Take a look a these following articles
Lua as a scripting engine
Introduction to Lua

I hope this helps.
Take care.
I have a fully-functional console in my current project, and I love it. I use it both for logging info, and for executing Lua commands at runtime. The console itself was very easy...just render a shaded quad, with text on top of it. I have macros that write to the console (such as LOG_INFO(), LOG_FAILURE(), and LOG_SUCCESS()), so it's very easy to use (note that these macros also output to a file).

However, adding the Lua scripting part is not trivial at all. A robust implementation takes a lot of work and consideration. Its also a thing that you continually build up, as you add more and more classes. Note that Luabind has some really annoying and ill-timed bugs, but generally, it works OK. Note that the Console is not the Scripting system - rather it is just a runtime input to it. The main input for scripting is from text file scripts loaded from the disk.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )

How have you written the console?
Quote:Original post by gael

How have you written the console?

What part of it? The display was cake, just render a shaded quad (for some background color) and then draw the applicable text over it.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
How have you done to write characters to the surface (texture)?
Quote:
How have you done to write characters to the surface (texture)?

You could simply use the ID3DXFont interface in native DirectX or the Font in Managed DirectX to render the text.

I hope this helps.
Take care.

This topic is closed to new replies.

Advertisement