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); }
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(); } }
Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy
oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de