Sign in to follow this  
  • entries
  • comments
  • views

Bonsai We have text!

Sign in to follow this  


I did this last night, didn't take that long once I took care of some stupid mistakes in the C++ code [grin]

std::string finalname = filenamebase + numberfix + "." + texturetype;
std::string finalname = filenamebase + numberfix + texturetype;



The code;

require "engine"

function runDemo()

eng = bonsai.createGraphics()
print ("Created : " .. eng:__tostring())
print "Window Created"
tex = eng:createTexture("test.jpg")

baseimg = {dirx = 0.1, diry = 0.1}
function baseimg:update()
self.x = self.x + self.dirx
self.y = self.y + self.diry

if self.x + self.width > 800
or self.x < 0
then self.dirx = -self.dirx end

if self.y + self.height > 600
or self.y < 0
then self.diry = -self.diry end
function baseimg:new(o)
o = o or {}
self.__index = self
return o

img = baseimg:new({x = 0, y = 0, width = 200, height = 200, id = tex})
img2 = baseimg:new({x = 0, y = 100, width = 40, height = 10, id = tex})

font = eng:loadFont("scrolltext","png")
print "Font loaded..."

imgs = {img, img2}





The main changes being the code to load and render the text.

The loader loads the .bmf produced by Bitmap Font Generator and the textures which go with it. In theory it should be able to deal with fonts spread over multiple pages.

The text renderer takes the location to render, the string and the font and optionally a colour (currently a float between 0 and 1, I might change this to a 0-255 range instead) and renders the text using the supplied font. Again, this deals with multiple pages of fonts, in theory at least, however it's not what you'd call efficant. The main issue being the use of immediate mode and the constant changes of the texture between drawning each character. It might be worth, in the future, building an optimised VBO/VA of the data, maybe allowing the app to cache this data and just do a quick render. But, working under the principle of YAGNI I shant be doing that right now.

I'm infact pretty close to being able to do the graphical part of this game, I do need to sort a timer function out and then it's a matter of working out how to hook events together to get key presses.

I also spent some time thinking about sandboxing the scripts and doing things like making sure PhysFS is used for all file access; this involved a scheme of changing the enviroment for require and all manner of C Voodoo; then it dawned on me, there is no reason for this, in the launcher app I just restrict what I load at startup which will restrict the scripts to just what I allow. Oh well, only wasted about a day on that and it wasn't a real waste as I know how to make my own loader now so that all scripts will be loaded from PhysFS restricted locations.

Right, now I need to eat...
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now