• entries
455
639
• views
421669

# Bonsai We have text!

71 views

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;vsstd::string finalname = filenamebase + numberfix + texturetype;

*whistles*

Anyways;

The code;
require "engine"function runDemo()eng = bonsai.createGraphics()print ("Created : " .. eng:__tostring())eng:createWindow()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		endfunction baseimg:new(o)	o = o or {}	setmetatable(o,self)	self.__index = self	return oendimg = 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}while(eng:startFrame())do	eng:renderQuads(imgs)	eng:renderText(0,100,"Testing",font,{r=0,g=1,b=1})	img:update()	img2:update()	eng:endFrame()endeng:deleteTexture(tex)eng:destroyWindow()endrunDemo()

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...

There are no comments to display.