Scolring - Forum

Entraides et échanges autour de la technologie Scol - Informations and exchanges on the Scol technology

Vous pouvez changer la langue de l'interface une fois inscrit - You can change the language once registered

You are not logged in.

#1 12-Jan-2014 18:23:25

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

painting text onto transparent bitmap and setting material on entity

colleagues:

how would I do the following:
[pseudo code]

//code todo with the help of you guys

//get remote user login string...I know how to do that
//create font ....I know how to do that
//get a handle to an entity's material...I can figure this out
//create transparent bitmap...I don't know how to do this
//paint font onto transparent bitmap....I don't know how to do this
//apply bitmap to material...I  don't know how to do this

I've looked a bit thorugh the scol api and the relevant plugit but you could get me to my objective with some pointers.

thx

then we can have avatars chat in an os3d hangout and know who is talking to who!

-h

Offline

#2 12-Jan-2014 18:44:20

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: painting text onto transparent bitmap and setting material on entity

Doc -> http://www.scolring.org/files/doc_html/2d_rscs.html

To create a transparent bitmap, you can load an AlphaBitmap object from a PNG file or create from an ObjBitmap already created.

ObjBitmap object have functions to modify them ! add a text, a line, a polygon, paint an area, etc
To add a text, you should define an ObjFont object (use a font like "Arial", "Helvetica", ...) or a default font (if os3d has a default font somewhere).
So, first, create an ObjBitmap if you've not a PNG file. You can create it from "empty" (_CRbitmap) or from a file (_LDbitmap, LDjpeg, _LDtga). From a PNG file, after load it, use _GETalphaBitmaps AlphaBitmap_object to get the included ObjBitmap.
Add a text, color, ... what you want.
Next, set the AlphaBitmap object with the modifued ObjBitmap, add it a transparency if any (see the doc too).

To apply on the material, you can use :
SO3TextureBlit  or SO3TextureBlitAlpha (http://redmine.scolring.org/projects/so … o3mat.html)

Offline

#3 12-Jan-2014 18:55:18

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: painting text onto transparent bitmap and setting material on entity

iri wrote:

Doc -> http://www.scolring.org/files/doc_html/2d_rscs.html

To create a transparent bitmap, you can load an AlphaBitmap object from a PNG file or create from an ObjBitmap already created.

ObjBitmap object have functions to modify them ! add a text, a line, a polygon, paint an area, etc
To add a text, you should define an ObjFont object (use a font like "Arial", "Helvetica", ...) or a default font (if os3d has a default font somewhere).
So, first, create an ObjBitmap if you've not a PNG file. You can create it from "empty" (_CRbitmap) or from a file (_LDbitmap, LDjpeg, _LDtga). From a PNG file, after load it, use _GETalphaBitmaps AlphaBitmap_object to get the included ObjBitmap.
Add a text, color, ... what you want.
Next, set the AlphaBitmap object with the modifued ObjBitmap, add it a transparency if any (see the doc too).

To apply on the material, you can use :
SO3TextureBlit  or SO3TextureBlitAlpha (http://redmine.scolring.org/projects/so … o3mat.html)

thanks Iri that should get me started
-h

Offline

#4 12-Jan-2014 20:04:30

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: painting text onto transparent bitmap and setting material on entity

Here is a simple example smile

To create an empty ObjBitmap :

let [256 256] -> [width height] in
set mybitmap = _CRbitmap _channel width height;

To set its background color :

_FILLbitmap mybitmap 0xFFFFFF;  /* white, in 32bits hexadecimal, by example or use make_rgb function, see doc (2d rscs) */

If any, with make_rgb ( http://www.scolring.org/files/doc_html/make_rgb.html ):

set mybgcolor = make_rgb 255 255 255; /* white (conponent red, green blue between 0 et 255) */
_FILLbitmap mybitmap mybgcolor;

To create a new font object :

set sizefont = 24;
set myfont = _CRfont _channel sizefont 0 FF_WEIGHT "Arial";

Write into a bitmap (the text is centered) :

set myforecolor = make_rgb 255 0 0; /* red (or directly 0xFF0000) */
let _GETbitmapSize -> [width height] in
_DRAWtext mybitmap myfont width/2 (3*height)/2 TD_BASELINE|TD_CENTER myforecolor "a text";

If you want use an AlphaBitmap :

set myalphabitmap = _CRalphaBitmap _channel mybitmap nil nil 0xFFFFFF;	/* by example */

You can use a "mask" (a 8-bits bitmap object to define the transparency). In this case,
you replace the first nil by this object :

set my8bitsmask = _LDbitmap8 _channel _checkpack "mydirectory/myfile.bmp";
set myalphabitmap = _CRalphaBitmap _channel mybitmap my8bitsmask nil 0xFFFFFF;

You can too create an empty 8bits bitmap object :

let [256 256] -> [width height] in
set my8bitsmask = _CRbitmap8 _channel width height;
_FILLbitmap8 my8bitsmask mybgcolor;
etc ...

ObjBitmap & ObjBitmap8 API : http://www.scolring.org/files/doc_html/bitmap.html
AlphaBitmap API : http://www.scolring.org/files/doc_html/ … itmap.html
ObjFont API : http://www.scolring.org/files/doc_html/font.html

Offline

#5 12-Jan-2014 23:55:22

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: painting text onto transparent bitmap and setting material on entity

thx Iri!!!!!

Offline

#6 13-Jan-2014 00:08:19

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: painting text onto transparent bitmap and setting material on entity

Offline

#7 14-Jan-2014 14:14:18

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: painting text onto transparent bitmap and setting material on entity

thx....there is alot for me to understand here. I think I will work on a project with a container that contains a window to display the bitmap and a textfield to enter the text to paint on the bitmap.

Offline

#8 14-Jan-2014 14:24:04

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: painting text onto transparent bitmap and setting material on entity

and capture the content of the container to put it in a material ? I think it's weigthly. You see smile

Offline

#9 14-Jan-2014 14:28:55

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: painting text onto transparent bitmap and setting material on entity

iri wrote:

and capture the content of the container to put it in a material ? I think it's weigthly. You see smile

I guess I can just have the window, and work on putting a string into a bitmap where the string is not input by the user:

let "hebdemnobad" -> stringtodraw in
(
//create bitmap with alpha channel
//draw text into bitmap
//paint bitmap into a window
...

Offline

#10 14-Jan-2014 14:38:30

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: painting text onto transparent bitmap and setting material on entity

ok, you don't wish to put the bitmap into a texture in a 3d material ? Only display a window with it.

Offline

#11 14-Jan-2014 14:55:05

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: painting text onto transparent bitmap and setting material on entity

iri wrote:

ok, you don't wish to put the bitmap into a texture in a 3d material ? Only display a window with it.


Yes so I can understand how do  the alpha channel bitmap creation

Offline

#12 14-Jan-2014 15:09:25

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: painting text onto transparent bitmap and setting material on entity

In this case, why directly use a simple CompText included in an ObjContainer ?

Offline

#13 14-Jan-2014 16:20:32

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: painting text onto transparent bitmap and setting material on entity

Iri I don't quite get what you are saying...let me know when we can chat in my modest os3d scene.

Offline

#14 14-Jan-2014 17:55:02

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: painting text onto transparent bitmap and setting material on entity

hebdemnobad wrote:

thx....there is alot for me to understand here. I think I will work on a project with a container that contains a window to display the bitmap and a textfield to enter the text to paint on the bitmap.

I thought you were talking about an ObjContainer to display the login ....  Sorry !

Ok, so, for that, create an empty bitmap, fill it and draw the login string in it. Next, create a new AlphaBitmap from this ObjBitmap.

1. _CRbitmap ...
2. _FILLbitmap ...
3. _DRAWtext ...

4. _CRalphaBitmap ...

Examples are in a previous post.
After, you can set the transparency and other things as you want.

Offline

#15 14-Jan-2014 18:20:53

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,161
Website

Re: painting text onto transparent bitmap and setting material on entity

to make a bitmap with text and transparent background you should :

- create a RGB bitmap with white backgound and put the text in black on it
- create a bitmap8 with a grey or nil background (depend of the background opacity you want) and draw the text in white on it.
- create an alpha bitmap with this bitmaps and draw it on the texture.

Offline

#16 14-Jan-2014 18:32:24

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: painting text onto transparent bitmap and setting material on entity

arkeon wrote:

to make a bitmap with text and transparent background you should :

- create a RGB bitmap with white backgound and put the text in black on it
- create a bitmap8 with a grey or nil background (depend of the background opacity you want) and draw the text in white on it.
- create an alpha bitmap with this bitmaps and draw it on the texture.

thx, I'll see how far I can get.  Perhaps I'm the only person in the Western Hemisphere doing this sort of programming.....if I could only turn it into a paying job.

Offline

#17 14-Jan-2014 20:30:38

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,161
Website

Re: painting text onto transparent bitmap and setting material on entity

hehe that should be great smile
I know that some companies in the world use OS3D for business. (for augmented reality as I know)

Offline

#18 15-Jan-2014 17:16:02

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: painting text onto transparent bitmap and setting material on entity

ok now I know how to create a bitmap and draw text into it.  how would I change the code below, where the image file is "transparent.png", 512x512 pixels, and the image file is completely transparent?

here is my code, a modification of iri's examples on redmine (thx iri!)

typeof window = ObjWin;;
typeof bmp = ObjBitmap;;

fun CBpaint (win, user_parameter)=
    _BLTbitmap window bmp 0 0;
    0;;

fun CBend (win, user_parameter)=
    _DSbitmap bmp;  // we destroy the bitmap object
    _closemachine;; // we exit the program

fun main ()=
   _showconsole; 
    // load a bitmap I created in gimp with a fractal rendering filter,  in the Openspace3d/tests directory.
    set bmp= _LDbitmap _channel _checkpack "tests/fractal.bmp";
    let _CRfont _channel 24 nil FF_WEIGHT "Arial" -> font in
    (
    _DRAWtext bmp font 150 50 nil 0xDddDdd "Hello wolrd !";
    0;
    );
    // create a window
    set window = _CRwindow _channel nil 0 0 512 512 WN_MENU "Bitmap Window";
    _CBwinDestroy window @CBend 0;
    //paint bitmap into window
    _CBwinPaint window @CBpaint 0;
    0;;

thx for your help, I think I am one or two steps away from making avatar names float through an os3d scene. smile

Offline

#19 15-Jan-2014 17:49:11

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: painting text onto transparent bitmap and setting material on entity

Your code is almost good.
The position flag is missing in _DRAWtext (you set it to nil)
http://www.scolring.org/files/doc_html/_drawtext.html

Choose a flag for x and a flag for y positions. See the doc to make a choice. For example :

_DRAWtext bmp font 150 50 TD_CENTER|TD_TOP 0xDddDdd "Hello wolrd !";

If you keep the value to nil, the result will not be fine.
For more secure, you can add a _PAINTwindow after _CBwinPaint :

_PAINTwindow window;
_CBwinPaint window @CBpaint 0;

If you want, to see the result, you can save the bitmap in a file (or display it in a window as you made).

_DRAWtext bmp font 150 50 TD_CENTER|TD_TOP 0xDddDdd "Hello wolrd !";
_SAVEbitmap bmp _getmodifypack "tests/fractal_sav.bmp";

( http://www.scolring.org/files/doc_html/_savebitmap.html )

Offline

#20 15-Jan-2014 18:19:23

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: painting text onto transparent bitmap and setting material on entity

Iri I put in the flags, thx.

Here is my code using an AlphaBitmap, but scol throws an error because I cannot use _BLTbitmap...so how do I paint an AlphaBitmap into a window? I couldn't find a corresponding function at http://www.scolring.org/files/doc_html/ … .html...so what step am I missing?

Here is my code, it throws an error when the vm tries to use _BLTbitmap...

typeof window = ObjWin;;
typeof bmp = AlphaBitmap;;

fun CBpaint (win, user_parameter)=
    _BLTbitmap window bmp 0 0;
    0;;

fun CBend (win, user_parameter)=
    _DSbitmap bmp;  // we destroy the bitmap object
    _closemachine;; // we exit the program

fun main ()=
   _showconsole; 
    // load a bitmap
    set bmp=_LDalphaBitmap _channel _checkpack "tests/transparent.png";
    let _CRfont _channel 24 nil FF_WEIGHT "Arial" -> font in
    (
    _DRAWtext bmp font 150 50 TD_CENTER|TD_TOP 0xDddDdd "Hello wolrd !";
    0;
    );
    // create a window
    set window = _CRwindow _channel nil 0 0 512 512 WN_MENU "Bitmap Window";
    _CBwinDestroy window @CBend 0;
    _PAINTwindow window;
    //paint bitmap into window
    _CBwinPaint window @CBpaint 0;
    0;;

thx for your help
-h

Offline

#21 15-Jan-2014 18:29:46

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: painting text onto transparent bitmap and setting material on entity

Look the doc : http://www.scolring.org/files/doc_html/_bltbitmap.html

_LDbitmap takes an ObjBitmap, not an AlphaBitmap. Same thing for other used functions.

To use an AlphaBitmap, you must make :

- Separate its basic components with _LDalphaBitmaps
- Work on the 24-bits component
- Display (or save) this modified component.

So, you could write something like that (i'm not tested it but it should work) :

typeof window = ObjWin;;
typeof abmp = AlphaBitmap;;
typeof bmp = ObjBitmap;;

fun CBpaint (win, user_parameter)=
    _BLTbitmap window bmp 0 0;
    0;;

fun CBend (win, user_parameter)=
    _DSbitmap bmp;  // we destroy the bitmap object
    _DSalphaBitmap abmp; // destroy the AlphaBitmap loaded object
    _closemachine;; // we exit the program

fun main ()=
   _showconsole; 
    // load an alpha bitmap
    set abmp=_LDalphaBitmap _channel _checkpack "tests/transparent.png";
    let _LDalphaBitmaps abmp [b24bits b8bits] in
    let _CRfont _channel 24 nil FF_WEIGHT "Arial" -> font in
    (
    set bmp = b24bits;
    _DRAWtext bmp font 150 50 TD_CENTER|TD_TOP 0xDddDdd "Hello wolrd !";
    0;
    );
    // create a window
    set window = _CRwindow _channel nil 0 0 512 512 WN_MENU "Bitmap Window";
    _CBwinDestroy window @CBend 0;
    //paint bitmap into window
    _CBwinPaint window @CBpaint 0;
    _PAINTwindow window;
    0;;

The _PAINTwindow is after the _CBpaint blablas

After, you can make a nicer code ;-)

Offline

#22 15-Jan-2014 18:44:14

hebdemnobad
Member
From: northamerica
Registered: 20-Apr-2011
Posts: 1,541
Website

Re: painting text onto transparent bitmap and setting material on entity

you had a couple of syntax errors which I fixed, but it seems that the vm won't recognize the alphabitmap as a tuple....

I encountered various error codes but got stuck with this one

(!) Line #24:
    )??;
>>> ERROR - Type mismatch (detail):
Found:    [AlphaBitmap [ObjBitmap u0] I]
Expected: [AlphaBitmap AlphaBitmap u0]
<<<

syntax error

my code:

typeof window = ObjWin;;
typeof abmp = AlphaBitmap;;
typeof bmp = ObjBitmap;;

fun CBpaint (win, user_parameter)=
    _BLTbitmap window bmp 0 0;
    0;;

fun CBend (win, user_parameter)=
    _DSbitmap bmp;  // we destroy the bitmap object
    _DSalphaBitmap abmp; // destroy the AlphaBitmap loaded object
    _closemachine;; // we exit the program

fun main ()=
   _showconsole; 
    // load an alpha bitmap
    //set abmp=_LDalphaBitmap _channel _checkpack "tests/transparent.png";
    let _LDalphaBitmap _channel  _checkpack "tests/transparent.png" -> [b24bits b8bits] in
    let _CRfont _channel 24 nil FF_WEIGHT "Arial" -> font in
    (
    set bmp = b24bits;
    _DRAWtext bmp font 150 50 TD_CENTER|TD_TOP 0xDddDdd "Hello wolrd !";
    0;
//below is line 24
    );
    // create a window
    set window = _CRwindow _channel nil 0 0 512 512 WN_MENU "Bitmap Window";
    _CBwinDestroy window @CBend 0;
    //paint bitmap into window
    _CBwinPaint window @CBpaint 0;
    _PAINTwindow window;
    0;;

Offline

#23 15-Jan-2014 18:48:18

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: painting text onto transparent bitmap and setting material on entity

you missed _GETalphaBitmaps !

This is wrong and give this error :

let _LDalphaBitmap _channel  _checkpack "tests/transparent.png" -> [b24bits b8bits] in

This should be right :

let _GETalphaBitmaps _LDalphaBitmap _channel  _checkpack "tests/transparent.png" -> [b24bits b8bits] in

or, if you prefer :

let _LDalphaBitmap _channel  _checkpack "tests/transparent.png" -> abmp in
let _GETalphaBitmaps abmp -> [b24bits b8bits] in

Offline

#24 15-Jan-2014 18:49:52

arkeon
Admin. / Scol language & OpenSpace3D developer
From: Nantes
Registered: 30-Mar-2009
Posts: 5,161
Website

Re: painting text onto transparent bitmap and setting material on entity

this is a function missing in the doc hmm

let _LDalphaBitmap _channel  _checkpack "tests/transparent.png" -> abmp in
let _GETalphaBitmaps abmp -> [b24bits b8bits] in

Offline

#25 15-Jan-2014 18:49:58

iri
Admin. / Scol language & Scol apps developer
From: France
Registered: 22-Feb-2009
Posts: 2,024
Website

Re: painting text onto transparent bitmap and setting material on entity

Remark : in this case, the global variable abmp is useless and you should remove it.

Offline

Board footer

Powered by FluxBB