Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Work in Progress / Antialiased text rendering plugin - please help me test it!

Author
Message
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 19th Feb 2007 01:44 Edited at: 25th Feb 2007 12:42
This plugin will allow any truetype font you have on your system to be rendered with antialiasing (smoothing) and kerning (correct spacing between letters).

<edit 25,2,07: All known issues fixed so far! Turned example code into functions to make it easier to use.>



Pretty nice - don't you think?! This is not a prerendered bitmap, but real time dbpro output. It's pretty fast, but obviously with bigger font sizes and longer strings of text, it will get a little slower. I know there is Cloggy's excellent d3d plugin which also renders antialiased text amongst other things, but unfortunately I have found it seems to have some issues on some pc's, and sometimes seems to struggle with correct kerning for 'script-like' fonts. I wrote this because I need something I can guarantee will work on all pc's, which is why I would be grateful to anyone who can help me test this.

The command is 'GUI_RENDERTEXT font$,size,text$'. The commented example code below shows you how to use it.

Setting up the plugin is very straight forward - just two downloads below and your away.

You will need 3 dll's to be included either in your project folder (where the .dbpro program is) or in your windows system folder. If you distribute your project, the end user will need these too, so it's best to include them in your project folder:

zlib1.dll
libpng13.dll
freetype6.dll

These can be downloaded here:

http://www.andromedus.com/misc/rendertextfiles.zip

The open source 'freetype6' dll has a license agreement which should go with it.

And here is the plugin, which needs to go into your 'user plugins' folder (Dark Basic Professional/Compiler/plugins-user):

http://www.andromedus.com/misc/GUI_rendertext.dll

Please let me know if there are any problems. Thanks,

Ric.

Here is some example code of it in action:



Attachments

Login to view attachments
TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 19th Feb 2007 08:31
Looks cool, will try it after college; 07:31 at the moment.

TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 19th Feb 2007 16:55
The example gives me a 'memblock position outside range at line 111' error I'm afraid.

Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 19th Feb 2007 17:27
Really? That's very odd - that refers to my alpha function (line 111 is marked):



I can't see anything wrong there - and this function has been tested on lots of machines, so this is very confusing! Which version of dbpro are you running?

Could you try replacing

for x=0 to sx-1
for y=0 to sy-1

with

for x=1 to sx-2
for y=1 to sy-2

to see if that keeps within the size of the image memblock? Theoretically, that should leave a black line all the way around the edge of the text.

Thanks,

Ric.

TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 19th Feb 2007 18:54 Edited at: 19th Feb 2007 19:04
Thats the line! OK. I'll try changing it. I'm using version 1.064 of DBP.

[Edit]
Tried that and it still didn't work. I added a line to set the exit prompt to display values of x,y and pos at the time of the error.
X=0
Y=0
Pos=12
Therefore it was on the first iteration and I have no idea what is wrong!
[/Edit]

[Edit2]
Now I tried taking out the alpha function call and it seems that the png created with the text on it isn't being created properly. Take a look at the screen attached.
[/Edit2]

Attachments

Login to view attachments
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 19th Feb 2007 19:21
Ok - thanks for helping me test this.

So, for some reason, the image seems to have no memblock information at all - most weird! I'll have to think about why that could be.

Could you check in the project folder to see if an image called 'output.png' has been created - and if so, whether it is a proper, viewable png image. If it is non-viewable, then perhaps it is corrupt, which might explain why it had no memblock info.

Thanks!

TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 19th Feb 2007 19:25 Edited at: 19th Feb 2007 19:27
Yeah, I already looked and it is corrupt.
[Edit]Wait! It seems to preview now. And it opens in Fireworks.[/Edit]
[Edit2]It won't open in paint though! All my other png files do![/Edit2]

Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 19th Feb 2007 20:35 Edited at: 20th Feb 2007 16:40
Seems like there is something odd with the image then. Strange that it works fine on my two test pc's.

Anyone else able to test on their pc to give me a better idea of why it works or why it doesn't?

heartbone
22
Years of Service
User Offline
Joined: 9th Nov 2002
Location:
Posted: 21st Feb 2007 19:40
Cool this Ric.

I'll give it a shot in a bit.

I'm unique, just like everybody else.
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 21st Feb 2007 20:10
Thanks - I'm kinda praying it works for at least somebody!!

heartbone
22
Years of Service
User Offline
Joined: 9th Nov 2002
Location:
Posted: 21st Feb 2007 20:37
I also got

Runtime Error 5105 - Memblock position outside range at line 111

The antialiased output.png file seems to be created fine,
it works with ALL my browsers and editors.

Your memblock indexing
(the calculation for the variable pos)
is a bit confusing to me.
(in your example sx = 266 ; sy = 100 ; memblock = 1)
but I suppose you know what is happening
because I don't.

But the value of pos is the stopper.

The bad value does not happen immediately, you will get into the x & y loops for a while.



I'm unique, just like everybody else.
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 21st Feb 2007 21:58 Edited at: 21st Feb 2007 22:01
Thanks Heartbone - so the output png actually shows the text, too? (ie not just a blank image?)

I'll take a look at the calculation for 'pos' and see if I went wrong there, although as it failed for teh coderer with x=0 y=0, I have a feeling there may be something funny about the png that dbp doesn't like.

Math89
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: UK
Posted: 21st Feb 2007 22:06
I think it's a problem with the display mode, if you are in 16 bits mode, maybe dbpro converts all images to 16 bits, that's why the position is wrong.
heartbone
22
Years of Service
User Offline
Joined: 9th Nov 2002
Location:
Posted: 21st Feb 2007 22:07 Edited at: 21st Feb 2007 22:09
I'm attaching the file in question.


Yes I am running in 16 bit mode.

I'll switch to 32 bit and see what happens.

I'm unique, just like everybody else.

Attachments

Login to view attachments
heartbone
22
Years of Service
User Offline
Joined: 9th Nov 2002
Location:
Posted: 21st Feb 2007 22:18
Math89, you nailed it.

Ric, on this install of DBP (4.1) the registry commands are probably dysfunctional,
so all I'm seeing is Arial,
(I'll fix that)
but your routine is displaying antialiased Arial in 32-bit!

Now fix it for 16-bit calls and you'll be set.
(Does DBP work in 256 color mode?)

Happy happy, joy joy.

I'm unique, just like everybody else.
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 21st Feb 2007 23:31
So it works if the display is set to 32 bit mode, and not 16 bit mode?

So the command 'convert image to memblock' doesn't work if the image depth and the display mode depth don't match? Hmm.. I'm not sure how to solve that one - any ideas?

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 22nd Feb 2007 00:08
When a memblock is made from an image, its colour depth will match the desktop colour depth. Run this code in both a 16bit resolution and a 32bit one and you'll see what I mean:



Tempest (DBP/DBCe)
Multisync V1 (DBP)
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 22nd Feb 2007 17:53
Update:

Well, I checked what happens on my system if I switch to 16 bit mode (from the windows control panel). Oddly, png images are still being loaded in 32 bit mode, and the memblock routine still works on my pc. Must be a graphics card thing. However, I tried loading a bmp image, and that only loaded up in 16 bit mode - and applying my memblock routine to it gave me the memblock out of range error.

So, I did some digging - there are a few bits of info on these forums (IanM in particular provided some valuable information) .....

You can't use the 'standard' memblock routines (i.e. the ones most people use) on 16 bit images.

With 32 bit images, the image memblock format is bbbbbbbbggggggggrrrrrrrraaaaaaaa, where each letter represents one bit - so it's one byte (8 bits) for blue, one byte for green, one byte for red, and one for alpha.

With 16 bit images, it seems that SOME graphics cards use the format abbbbbgggggrrrrr - that's one bit for alpha, and 5 bits each for g, r and b. Some other graphics cards use bbbbbggggggrrrrr - that's 5 bits for blue, six bits for green (apparently the least distinguishable colour by the human eye) and five bits for red.

There is no telling, as far as I can see, which of the two 16 bit formats is in operation on who's system, so I have to work with the format I think is most common, and I think that's the first one.

So, I've adapted the memblock routine to convert 16 bit images into 32 bit images - thanks again to IanM for the code for extracting the colour information from the individual bits - I can't say I understand exactly how it works, but I think it does - at least it does here!!

So, please get rid of the old function called 'alpha()' in the code, and replace it with this:



and give it another whirl! Should work in both 16 bit and 32 bit screen mode. Theoretically.

TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 22nd Feb 2007 18:35
Now I get:

Runtime error 5106 - Memblock size value illegal at line 119

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 22nd Feb 2007 18:54
set bitmap format

Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 22nd Feb 2007 19:14
TEH CODERER: Oh dear - failed again! What screen colour depth are you using? 32 or 16 bit?

Diggsey: But I'm not loading or creating a bitmap - so I don't think that would make a difference ??

TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 22nd Feb 2007 23:45
32, what your code set it to.

heartbone
22
Years of Service
User Offline
Joined: 9th Nov 2002
Location:
Posted: 23rd Feb 2007 00:31
The changes work in both 16 and 32 bit graphics modes on my system.

ATI Radeon 9200 SE

I'm unique, just like everybody else.
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 23rd Feb 2007 00:32
Note that just because my code sets it to 32 bits, doesn't mean it is running in 32 bit - if your windows settings have it at 16, this will override dbpro.

Anyway, the memblock size illegal error is odd. I don't think there is any limit on maximum size, so it must indicate that the size is zero (or negative). This line of code sets the size:

if depth=32 then size=get memblock size(memblockin)

and if the size is zero, then it's telling me that the size of the memblockin ( the memblock created from the ong image) is also zero. That would explain why with the old code, the position went out of range on the first iteration. But I have no idea how converting an image to a memblock can result in a memblock of size zero. That has me completely stumped!

More thinking needed!

Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 23rd Feb 2007 21:40
Glad it works for you now Heartbone.

Teh Coderer: maybe a long shot, but perhaps dbpro would recognise the memblock format if it was an image saved by dbpro itself - I'm thinking load the png, save it as a dds, load it back up again, then turn it to a memblock. If you get a chance, could you try replacing this:

load image "output.png",1,1

with this:

load image "output.png",1,1
save image "output.dds",1
load image "output.dds",1,1

Cheers,

Ric.

TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 24th Feb 2007 13:28
Yeah! That works! Thanks Ric!

TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 24th Feb 2007 13:30
Gah! But now my default font is different! I don't if it is just my PC, but all my posts are now in a different font!

Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 25th Feb 2007 11:31
Glad it works now.

I don't see how my code could change your system settings though - by default font, do you mean the font used for text on this message board?

Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 25th Feb 2007 12:44
Update.

I've updated the first post in this thread. I've neatened up the example code, which now uses functions to make it easier to use in your own projects.

Included a license agreement in the 'rendertextfiles' download which should be distributed with the freetype6.dll

All known bugs fixed so far!

Cheers,

Ric.

TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 25th Feb 2007 14:24
Quote: "I don't see how my code could change your system settings though - by default font, do you mean the font used for text on this message board?
"

Yeah that is what I mean! It is very wierd and possibly a complete coincidence as it seems to have reverted to normal now.

Aaron Miller
18
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 27th Feb 2007 00:19
Very nice.

Cheers,

-db


Enter my forums here.

Login to post a reply

Server time is: 2024-11-23 22:45:22
Your offset time is: 2024-11-23 22:45:22