Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (Edgar_Herrera, VoroneTZ, Akow), 973 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 5
Page 400 of 554 1 2 398 399 400 401 402 553 554
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 Offline
Expert
Kartoffel  Offline
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 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart

Click to reveal.. (Works perfectly fine for me)

Code:
#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: Kartoffel] #444896
08/21/14 10:45
08/21/14 10:45
Joined: Jul 2010
Posts: 283
Germany
J
jenGs Offline
Member
jenGs  Offline
Member
J

Joined: Jul 2010
Posts: 283
Germany
@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.

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 Offline
Expert
Kartoffel  Offline
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:
Quote:
@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: jenGs] #444898
08/21/14 10:57
08/21/14 10:57
Joined: Jul 2010
Posts: 283
Germany
J
jenGs Offline
Member
jenGs  Offline
Member
J

Joined: Jul 2010
Posts: 283
Germany
Here a small example.
I did this as an intro test for my ackon documentation (which I need to finish at last)

https://www.youtube.com/watch?v=W6l5sUNslU0&feature=youtu.be

The slow framerate is not an shader issue, but a problem with my capturing method.

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
J
jenGs Offline
Member
jenGs  Offline
Member
J

Joined: Jul 2010
Posts: 283
Germany
Originally Posted By: Kartoffel
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 laugh

edit:
Important functions
Code:
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
Code:
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 Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
thanks for sharing and nice video btw. grin

If I modify the code with some useful improvements I'll send it to you via pm wink

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
J
jenGs Offline
Member
jenGs  Offline
Member
J

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 Offline
Expert
Kartoffel  Offline
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 Offline
Expert
Slin  Offline
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.
Page 400 of 554 1 2 398 399 400 401 402 553 554

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1