Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Matrix (WARNING: Math Ahead!)

Custom Title Activated
Loyal Member
Joined
Jan 28, 2009
Messages
1,320
Reaction score
616
BMP Font + unicode + Matrix (WARNING: Math Ahead!)

I have a problem with matrix in PT, all my matrices starting around same place (right of center).

K8M9Pk5 - Matrix (WARNING: Math Ahead!) - RaGEZONE Forums

I tried with many different matrices, results are minor. (0,0) is always around same place.


I extracted D3DTRANSFORMSTATE_PROJECTION matrix from PT but failed to find WORD and VIEW...
Code:
3.351, 0.000, 0.000, 0.000
0.000, 2.681, 0.000, 0.000
0.000, 0.000, 1.005, 1.000
0.000, 0.000, -20.101, 0.000
...using it still gives me same results. (not sure to what this matrix is related, I got it by hooking GetTransform)


I can move whole matrix to top-left corner but it's not very accurate and Y change for some reason when I change monitor resolution (not PT resolution) or run pt in full screen mode (it look like X stay same).


Right now I'm using D3DXMatrixOrthoLH method:
Code:
2/w  0    0           0
0    2/h  0           0
0    0    1/(zf-zn)   0
0    0    zn/(zn-zf)  1

And not getting what I should get. :/


It would be nice to move my quad relatively to window resolution... e.g. from 0.0 to 1.0 (from 0% TO 100%).

O and since PT use mostly dx6.1 (can't find sdk :/) matrices are defined by D3DMATRIX and not D3DXMATRIX (unsure if I should mix those 2).

Any idea why I can't make working 2D matrix in PT?

Right now I'm using identity matrix and my quad stick to the center... but problem is that it stick to the center of whole screen so its reliable only in full screen mode. How to align it to the window? Do I need to create and set this matrix in some specific time? That's still a mystery for me.
 

Attachments

You must be registered for see attachments list
Last edited:
Custom Title Activated
Loyal Member
Joined
Jan 28, 2009
Messages
1,320
Reaction score
616
Bitmap font, so far my biggest problem is this matrix. For some reason (0,0) point is always projected to PT window from my desktop resolution :/ I also have some problems with transparency and vertex buffer, but if I solve first problem than I can move on with building bmp font engine.

Ultra fast PT for everyone and more...
 
Moderator
Staff member
Moderator
Joined
Feb 22, 2008
Messages
2,404
Reaction score
723
Nice! Which version of Directx SDK are you using? I belive 6, to match pt? Or you modified something else? I was trying to do something similar too lol

You said about desktop and window coordinates? You talking about ScreenToClient() or ClientToScreen() functions?
 
Custom Title Activated
Loyal Member
Joined
May 26, 2007
Messages
5,545
Reaction score
1,315
He said he can't get the API, so I'm guessing he's hooking direct in x86 without API and guessing function I/O.

Could you use the location of the window as an offset to your screen render location?
 
Custom Title Activated
Loyal Member
Joined
Jan 28, 2009
Messages
1,320
Reaction score
616
Yes, I'm hooking dx calls. But I'm using ddraw from dx7 sdk (need it to load textures, some old bs... I'm creating dd surface, blt data to surface, query interface and voila texture is ready to use)... dx6 sdk would be nice...

I'm not sure why matrices did not worked, in full screen mode (1280x1024) my X was from -1 to 1 and Y from 0.8 to -0.8... on different resolutions I got different results.

I changed vertex format to D3DFVF_XYZRHW, I can no longer use matrices to transform my geometry but finally I can set quad in pixel perfect position (taking X,Y from TextOutA).

Alpha blending finally working (PT is so picky about alpha data... Alpha 1 created by photoshop is not working).
Creating vertex buffer still crash PT but since PT is not using it (I think its not) for SOD/BC bmp font than I will skip vb too.

Right now I still need to do some tests and try to change texture color and decide what bitmap font app I'm going to use.

So yeah, practically all I need to do is bmp font engine.



I7veDDk - Matrix (WARNING: Math Ahead!) - RaGEZONE Forums
 

Attachments

You must be registered for see attachments list
Custom Title Activated
Loyal Member
Joined
May 26, 2007
Messages
5,545
Reaction score
1,315
That conversion from 3D space to 2D space in DirectX has defeated me in programming an independent game I had in mind, so major gratz on that Vormav. As for the alpha, I have found that PT is quite happy with TGA alpha (if you have the correct, uncompressed bottom right to top left byte order style TGA) but won't touch 32-bit BMP files. It insists on 2 24-bit ones, one with the normal map and one with the alpha map. :roll-eyes:
 
Custom Title Activated
Loyal Member
Joined
Jan 28, 2009
Messages
1,320
Reaction score
616
I end up using 32bit tga (works fine as run-length encoded too, 16bit is ok too) with color key; gives me better results than:
MySetRenderState(d3ddev, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
MySetRenderState(d3ddev, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCCOLOR);

+and its faster.
-can't use semi-transparent pixels. However I don't need them. Font look better without TrueType outline or hinting, especially small font. It's sharp and clean even when window get stretched.
Also I can use vertex color to tint text, could not do it with SRCALPHA & INVSRCCOLOR (material and light does not work for me).

Vormav - Matrix (WARNING: Math Ahead!) - RaGEZONE Forums




I probably won't be able to distribute this with windows fonts (I think they are licensed even when converted to bitmap), but there are some open alternatives like gnu fonts.
Encoding will be a problem. PT does not support Unicode. I will have to do this OEM style: ANSI, BALTIC... etc. Unless someone have better idea? Does PT support languages like arabic (right to left... I would have to add special code for that... meh)?
Choosing korean, japanese and chinese fonts/characters also gives me a headache. Any "one" font to do them all?
Btw does PT ever use DrawTextA? Never seen text coming out from there and I don't know if it's worth hooking.
 
Last edited:
Custom Title Activated
Loyal Member
Joined
Jan 28, 2009
Messages
1,320
Reaction score
616
You mostly hook all you need. For drawing triangles you need things like Begin/End scene, DrawPrimitive, settexture, setrenderstate... and so on.

PS. so far things going smoothly, I might be able to release it soon. Still beta but font is as sharp as razor, even when I resize it, this makes me wonder how others do bmp fonts and why they are so blurry.
 
Custom Title Activated
Loyal Member
Joined
May 26, 2007
Messages
5,545
Reaction score
1,315
I probably won't be able to distribute this with windows fonts (I think they are licensed even when converted to bitmap), but there are some open alternatives like gnu fonts.
Despite what font foundries would like you to believe, it is illegal to claim copyright on Fonts. Other notable exceptions to copyright law include pornography, regardless of other photographic or illustrative copyright laws. :eek:
Choosing korean, japanese and chinese fonts/characters also gives me a headache. Any "one" font to do them all?
Unicode is the "one ring to rule them all" in this case. It is your ONLY option, and since PT was never written with a MBCS (multi-byte character system, introduced as the standard with Win 95, I believe, but not adopted fully, even by Microsoft till WinME/2K) PE header a complete conversion to Unicode executable would be very hard without the source code. (where it is simply a compiler switch and, maybe, a few header tweaks or API aliases)

Any 8-bit script only needs a different font, (code-page) and usually only the higher 128 characters of the set actually change. But for Asian languages, they tended to use something in-between ASCII and Unicode. Rather like UTF-8, where only certain characters where 16-bit. Those will present problems, unless you run multiple font bitmaps, and use the first byte as a control code to switch font face mid-render.

Here's an example, using Latin characters (which don't need it) assuming that your character space was too small. Say characters are stored in a nibble, not a byte. We only have 16 to work with, but there are 24 characters and two case options for each.
0 aeiousnmgh123456
1 qwrtypdfjklzxcv
2 b0123456789.,"!?
3 AEIOUSNMGH01245
4 QWRTYPDFJKLZXCV
5 B+-*/\&^%$(){}[]
6 @~#<>|`_<BEL><BS><CR><LF><CL><CR><CU><CD>

So, the first line is the 1 nibble character, the numbers in red are code page numbers for characters which will not fit in the first nibble, and the lines below are the alternate pages for 2 nibble characters. Characters in blue are, of course, control codes, Bell, Backspace, Carriage Return, Line Feed, Cursor left, right, up or down.

If you expand that from nibbles to bytes, that's basically how Asian (and UTF-8) work MBCS.

Systems similar to this where often used for text compression in Interactive Fiction games on 8-bit computer systems, where they would end up with 80K of potential text responses in a computer with 32K for the entire program, as well as that 80K of data. ;) Memory space saving is the reason you put the most commonly used characters (vowels) in the 0 page which only takes one nibble. ^_^ Aside from vowels, (which are pretty common in all European languages, and also essential in Japanese) which characters you choose vary according to the target language, even for European languages using Latin script. ;)
 
Last edited:
Custom Title Activated
Loyal Member
Joined
Jan 28, 2009
Messages
1,320
Reaction score
616
I edited thread title since its no longer related only to matrices.
Here is my progress so far:

Vormav - Matrix (WARNING: Math Ahead!) - RaGEZONE Forums


As you can see some text got double print, unsure if it's PT fault or mine, some got printed on triangles. There is no X adjustment for letters yet, only my green color... and so on and so forth... after I deal with this mess I will list my real problems >=P
PT and font colors... o it will be fun :>


Despite what font foundries would like you to believe, it is illegal to claim copyright on Fonts. Other notable exceptions to copyright law include pornography, regardless of other photographic or illustrative copyright laws. :eek:

So I can pack Arial or Lucida Console with my DLL :O

Unicode is the "one ring to rule them all" in this case. It is your ONLY option, and since PT was never written with a MBCS (multi-byte character system, introduced as the standard with Win 95, I believe, but not adopted fully, even by Microsoft till WinME/2K) PE header a complete conversion to Unicode executable would be very hard without the source code. (where it is simply a compiler switch and, maybe, a few header tweaks or API aliases)

I was thinking about font itself like ( ) but with better quality.

PT using different encodings for different PTs. In kPT I would have to convert EUC-KR to unicode, and so on.
For now I'm sticking with 0-255 char.
 
Joined
Jan 19, 2007
Messages
400
Reaction score
38
o yeah baby !!! this dev will give up the performace of PT, and, if u see, the KPT , in his last update has add Dx 9+.... and they are talking about fix this engine error too.
 
Custom Title Activated
Loyal Member
Joined
May 26, 2007
Messages
5,545
Reaction score
1,315
As you can see some text got double print, unsure if it's PT fault or mine, some got printed on triangles. There is no X adjustment for letters yet, only my green color... and so on and so forth... after I deal with this mess I will list my real problems >=P
PT and font colors... o it will be fun :>
Yes, coloured text will be fun. I guess you'd need to buffer copies of the texture in different colours. A hue adjust filter from the source should get you there no problem, but the memory waste is a pain. If you do it for each character when displayed, you may negate the speed you gained?

The "double print" is a shadow PT applies in a dark text colour. We don't really notice it in Latin, but it should make Asian languages much clearer. I've disabled the shadow before, to gain a little speed.

The characters should really pick up a box, unless you have some proportional font work? Either way, it seems to be setting a top left baseline, where text works on a bottom left base, and exceeds it with commas "p", "g", "y", "q" and sometimes "f"
So I can pack Arial or Lucida Console with my DLL :O
You sure can! :D They can get crappy, but nothing they try to do will hold up in court. GNU don't like to risk the idea that the law may change. If you choose to do the same, that's up to you.

When you are asked to pay to download a font, this is officially considered a "shipping fee" rather than the cost of the font. ^_^ However, why it should cost $30 to ship a file which is only a meg or so, but cost nothing to "ship" a Linux DVD is laughable.

I always like MS Reference Sans Serif. It's not far from the classic Helvetica font, and Microsoft *used to* give it away for free as a "reference" to clear type. Seems they are trying to squeeze some money out of people for v2.00 these days though.
 
Custom Title Activated
Loyal Member
Joined
Jan 28, 2009
Messages
1,320
Reaction score
616
Awesome work Vormav!
I am guessing this gives the client an insane FPS increase in OS's that use directX 10 and 11 (windows vista/7/8)?

Yes, so far I could not hammer FPS down, I did not implemented FPS counter but spamming text on/off have no impact whatsoever.
On top of that it should speed up PT also on 98 and XP... my test platform is 7 but it should work on any windows (or wine). As long as PT have visible import table (method I'm using is called API hijacking) all you have to do is copy 2 dlls to PTs main directory.


o yeah baby !!! this dev will give up the performace of PT, and, if u see, the KPT , in his last update has add Dx 9+.... and they are talking about fix this engine error too.

This is mostly for older clients. Newest kPT/tkPT clients are using DX9 (only for bmp font? how did they mixed devices? if they did)... I'm sticking with DX6 IM and bitmap fonts.
Not so sure about ePT, bPT, jPT... any official PT left?


Yes, coloured text will be fun. I guess you'd need to buffer copies of the texture in different colours. A hue adjust filter from the source should get you there no problem, but the memory waste is a pain. If you do it for each character when displayed, you may negate the speed you gained?

The "double print" is a shadow PT applies in a dark text colour. We don't really notice it in Latin, but it should make Asian languages much clearer. I've disabled the shadow before, to gain a little speed.

The characters should really pick up a box, unless you have some proportional font work? Either way, it seems to be setting a top left baseline, where text works on a bottom left base, and exceeds it with commas "p", "g", "y", "q" and sometimes "f"You sure can! :D They can get crappy, but nothing they try to do will hold up in court. GNU don't like to risk the idea that the law may change. If you choose to do the same, that's up to you.

No slow down at all... Its only one draw call per string, so maybe ~20 draw calls every frame for text.

Actually I was getting wrong color... I checked with color picker. Turn out to be BGR :O

R 41
G 199
B 164

B 41
G 199
R 164

Everything is fine now.
Yet there is some renter state that turn my font into semi transparent/greyish/shadow? when I close chat window (esc key). Need to track it down.

I was also able to fix some issues that kPT have by changing SPACE (' ') width :O
In Arial letters like f, j and t are too close to other letters but it can be fixed in .fnt file; I'm using AngelCode Bitmap Font Generator, if I did not mentioned it before. I also implemented kerning but nothing will replace AC BFG option "force offsets to zero"... everything look so perfect like in Lucida Console. Best font so far for kPT is surprise, surprise: gulim, font that kPT is using :>


When you are asked to pay to download a font, this is officially considered a "shipping fee" rather than the cost of the font. ^_^ However, why it should cost $30 to ship a file which is only a meg or so, but cost nothing to "ship" a Linux DVD is laughable.

I always like MS Reference Sans Serif. It's not far from the classic Helvetica font, and Microsoft *used to* give it away for free as a "reference" to clear type. Seems they are trying to squeeze some money out of people for v2.00 these days though.

I'm going to abuse that :>




OK, my progress so far:

Vormav - Matrix (WARNING: Math Ahead!) - RaGEZONE Forums



My problems so far:
- Some minor glitches, missing pixel here and there (because screen is stretched, showing up also in PT with GDI font), fixing aspect ratio should help
- No Korean text, need to implement unicode converter
- No bold or italic (kPT don't use italic) fonts yet. I don't know how to extract data from HGDIOBJ. Is there any other way? GDI does it by usign SelectObject on created font? Anyone?
 
Back
Top