5 registered members (AndrewAMD, ozgur, Ayumi, 2 invisible),
690
guests, and 10
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: What are you working on?
[Re: FBL]
#444889
08/20/14 22:13
08/20/14 22:13
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
Err I'm not even using views atm. I just coded some functions which makes an bmap out of a string using bmap_blitpart with a bmap font that also takes care of the character width.
...and bmap_blitpart is annoyingly slow so I'm looking for another method to write the characters on that bmap.
Last edited by Kartoffel; 08/20/14 22:14.
POTATO-MAN saves the day! - Random
|
|
|
Re: What are you working on?
[Re: Kartoffel]
#444890
08/20/14 23:25
08/20/14 23:25
|
Joined: Nov 2007
Posts: 2,568 Germany, BW, Stuttgart
MasterQ32
Expert
|
Expert
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
|
#include <acknex.h>
#include <default.c>
BMAP *font = "ackfont.pcx";
BMAP *t = "#400x300x8888";
PANEL *p =
{
bmap = t;
flags = SHOW;
}
function main()
{
wait(1);
while(true)
{
bmap_rendertarget(t, 0, 0);
int i;
for(i = 0; i < 10; i++)
{
draw_quad(
font,
vector(20 * i,0,0),
vector(6, 8, 0), vector(6,8,0),
vector(2,2,0),
COLOR_RED,
100,
0);
}
bmap_rendertarget(NULL, 0, 0);
wait(1);
}
}
|
|
|
Re: What are you working on?
[Re: MasterQ32]
#444897
08/21/14 10:46
08/21/14 10:46
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
thank's a lot! but what I actually want to do is writing the characters ONCE onto the bmap, not every single frame... But since draw_quad is quite fast I might do it this way. edit:@Kartoffel
I have written a shader to do exactly what you want. BUT, your font and the target bitmap has to have dimensions that are a power of two. I process the Bitmaps with bmap_process. Until now it only supports letters with equal width. But you could input the different sizes with an additional bitmap that provides the information. nice! I actually know how to transform the texture coordinates so that image sizes which are not a power of two are possible aswell.
Last edited by Kartoffel; 08/21/14 10:48.
POTATO-MAN saves the day! - Random
|
|
|
Re: What are you working on?
[Re: Kartoffel]
#444899
08/21/14 10:58
08/21/14 10:58
|
Joined: Jul 2010
Posts: 283 Germany
jenGs
Member
|
Member
Joined: Jul 2010
Posts: 283
Germany
|
nice! I actually know how to transform the texture coordinates so that image sizes which are not a power of two are possible aswell. Ohh I need that edit: Important functions
typedef struct
{
float x;
float y;
}POS;
MATERIAL *mtlProjectText =
{
effect = "post_string.fx";
}
POS *points[128];
BMAP *bCourier = "courier10.tga";
POS *pos_new(float x, float y)
{
POS *p = sys_malloc(sizeof(POS));
p.x = x;
p.y = y;
return p;
}
void init_positions()
{
STRING *strTmp = str_create(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~°");
int i;
for(i = 1; i < str_len(strTmp); i++)
{
int pos = str_getchr(strTmp, i);
points[pos] = pos_new((i - 1) % 32, (i - 1 + 32) / 32);
}
str_remove(strTmp);
}
void paint_string(BMAP *bmpTarget, char *str, VECTOR *offset)
{
BMAP *word = bmap_createblack(64, 1, 144);
bmap_lock(word, 0);
float *bits = word.finalbits;
int i;
for(i = 0; i < str_len(str); i++)
{
int pos = str_getchr(str, i + 1);
bits[i * 2] = points[pos].x / 32.0;
bits[i * 2 + 1] = points[pos].y / 4.0;
}
bmap_unlock(word);
wait(1);
mtlProjectText.skin1 = word;
mtlProjectText.skill[0] = floatv(str_len(str));
mtlProjectText.skill[1] = floatv(offset.x);
mtlProjectText.skill[2] = floatv(offset.y);
mtlProjectText.skill[3] = floatv(bmap_width(bCourier) / 32);
mtlProjectText.skill[4] = floatv(bmap_height(bCourier) / 4);
bmap_process(bmpTarget, bmpTarget, mtlProjectText);
bmap_remove(word);
}
There is a lot of room for improvements. For example, the positions could be divided before using the array Shader: needs a lot of improvement, too
Texture TargetMap;
Texture bCourier_bmap;
Texture mtlSkin1;
sampler2D smpFont = sampler_state { texture = <bCourier_bmap>; };
sampler1D smpText = sampler_state
{
texture = <mtlSkin1>;
MipFilter = NONE;
MinFilter = NONE;
MagFilter = NONE;
};
sampler2D smpEnt = sampler_state { texture = <TargetMap>; };
float4 vecViewPort;
float4 vecSkill1;
float4 vecSkill5;
float inrange(in float2 values)
{
return values[0] > 0.0 && values[1] > 0.0 && values[0] < 1.0 && values[1] < 1.0;
}
float2 get_position(in float chr)
{
if(chr < 0) { return 0; }
float chrPos = chr / 64.0f;
float4 r = tex1D(smpText, chrPos);
float px = r.r * 32.0f;
float py = r.g * 4.0f;
return float2(px, py);
}
float4 process_text(in float2 vPos: VPOS): COLOR
{
float2 ras = vPos + 0.5;
float2 tex = ras / vecViewPort.xy;
int chrPos = (ras.x - vecSkill1[1]) / vecSkill1[3];
float2 pos = get_position(chrPos);
float offsetx = pos[0] * 0.03125f;
float offsety = pos[1] * 0.25f;
float fx = smoothstep(vecSkill1[1] + chrPos * vecSkill1[3], vecSkill1[1] + chrPos * vecSkill1[3] + vecSkill1[3], ras.x);
float fy = smoothstep(vecSkill1[2], vecSkill1[2] + vecSkill5[0], ras.y);
float4 color = 1;
float pos_x = fx * 0.03125f;
float pos_y = fy * 0.25f;
if(inrange(float2(fx, fy)) != 0.0 && chrPos < vecSkill1[0] && chrPos > -1)
{
color = tex2D(smpFont, float2(offsetx + pos_x, offsety + pos_y));
}
else
{
color = tex2D(smpEnt, tex);
}
return color;
}
technique Text
{
pass p1
{
AlphaBlendEnable = false;
PixelShader = compile ps_3_0 process_text();
}
}
[/code]
Last edited by jenGs; 08/21/14 11:25. Reason: code
|
|
|
Re: What are you working on?
[Re: jenGs]
#444901
08/21/14 11:34
08/21/14 11:34
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
thanks for sharing and nice video btw. If I modify the code with some useful improvements I'll send it to you via pm Edit: one problem, seems like calling bmap_process a lot is even slower than doing it with bmap_blitpart ._.
Last edited by Kartoffel; 08/21/14 11:47.
POTATO-MAN saves the day! - Random
|
|
|
Re: What are you working on?
[Re: Kartoffel]
#444902
08/21/14 11:51
08/21/14 11:51
|
Joined: Jul 2010
Posts: 283 Germany
jenGs
Member
|
Member
Joined: Jul 2010
Posts: 283
Germany
|
That's strange. In my demo it runs with 60 frames in fullscreen. You only need to call bmap_process once, to copy one line of text. It is not needed to call it every frame. perhaps it is another function.
Ok, my code need 2 frames to paint a word. because of the wait(1) between the bitmap writing and the shader processing.
Last edited by jenGs; 08/21/14 11:52.
|
|
|
Re: What are you working on?
[Re: jenGs]
#444903
08/21/14 11:54
08/21/14 11:54
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
Well, then there's a little misconception, I guess...
In my example I'm doing exactly the same (just by using bmap_blitpart), but if I want to change the text every frame (like when typing in some text) it needs to be done a lot, so I looked for something faster.
I'll probably use a totally different methot when this is the case..
POTATO-MAN saves the day! - Random
|
|
|
Re: What are you working on?
[Re: Kartoffel]
#444904
08/21/14 12:01
08/21/14 12:01
|
Joined: May 2005
Posts: 2,713 Lübeck
Slin
Expert
|
Expert
Joined: May 2005
Posts: 2,713
Lübeck
|
Using the way Felix proposed, with bmap_rendertarget should work perfectly for you!? Nobody forces you to redraw the bmap every frame. Just do it once and you are done. And if you want to draw additional letters into it there should even be some way to keep the textures content and render on top of it.
Edit: also why aren´t you using true type fonts?
Last edited by Slin; 08/21/14 12:03.
|
|
|
|