OSSL TextureDrawing

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
m (Add PenColor)
 
(10 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
{{Template:Quicklinks}}
+
{{Quicklinks}}
 
<br />
 
<br />
  
<source lang="lsl">
+
== General Capabilities ==
  
string osMovePen(string drawList, int x, int y);
+
The OSSL Texture Drawing functions allow the scripter to dynamically generate a texture on the fly, from within the context of an script. (It can be written in LSL, C# or any other supported scripting language.)
string osDrawLine(string drawList, int startX, int startY, int endX, int endY);
+
 
string osDrawLine(string drawList, int endX, int endY);
+
The scripting language supports text and images, as well as three simple drawing primitives: line, rectangle and ellipse. Color and pen attributes are included. Font, size and style are supported for text. An image is specified as an URL.
string osDrawText(string drawList, string text);
+
 
string osDrawEllipse(string drawList, int width, int height);
+
A drawing script can be directly specified in the texture drawing language, or can be built by using helper functions in the scripting language. Examples of both approaches are shown below.
string osDrawRectangle(string drawList, int width, int height);
+
 
string osDrawFilledRectangle(string drawList, int width, int height);
+
Several extra parameters are available for the texture rendering operation. These include the height and width of the texture, as well as the background color and alpha value. A statement terminator can also be specified.
string osDrawPolygon(string drawList, LSL_List x, LSL_List y);
+
 
string osSetFontSize(string drawList, int fontSize);
+
'''LSL Helper Functions'''
string osSetPenSize(string drawList, int penSize);
+
 
string osSetPenColour(string drawList, string colour);
+
<source lang="lsl">
string osSetPenCap(string drawList, string direction, string type);
+
string osMovePen(string drawList, int x, int y);
string osDrawImage(string drawList, int width, int height, string imageUrl);
+
string osDrawLine(string drawList, int startX, int startY, int endX, int endY);
 +
string osDrawLine(string drawList, int endX, int endY);
 +
string osDrawText(string drawList, string text);
 +
string osDrawEllipse(string drawList, int width, int height);
 +
string osDrawRectangle(string drawList, int width, int height);
 +
string osDrawFilledRectangle(string drawList, int width, int height);
 +
string osDrawPolygon(string drawList, LSL_List x, LSL_List y);
 +
string osSetFontSize(string drawList, int fontSize);
 +
string osSetPenSize(string drawList, int penSize);
 +
string osSetPenColor(string drawList, string colour);
 +
string osSetPenCap(string drawList, string direction, string type);
 +
string osDrawImage(string drawList, int width, int height, string imageUrl);
 
</source>
 
</source>
 
----
 
----
  
'''Code'''
+
'''C# Code Example'''
 
<source lang="lsl">
 
<source lang="lsl">
//cs
+
//cs
public void default_event_state_entry()
+
public void default_event_state_entry()
{
+
{
 
     string drawList = "";
 
     string drawList = "";
 
     drawList = osDrawLine (drawList, 10,20,240,20);
 
     drawList = osDrawLine (drawList, 10,20,240,20);
Line 47: Line 58:
  
 
     drawList = osSetFontSize (drawList, 7);  
 
     drawList = osSetFontSize (drawList, 7);  
     drawList = osSetPenColour (drawList, "blue");
+
     drawList = osSetPenColor (drawList, "blue");
 
     drawList = osMovePen (drawList, 70,220);
 
     drawList = osMovePen (drawList, 70,220);
 
     drawList = osDrawText (drawList, "The End");
 
     drawList = osDrawText (drawList, "The End");
 
     osSetDynamicTextureData("", "vector", drawList, "", 0);
 
     osSetDynamicTextureData("", "vector", drawList, "", 0);
}
+
}
 
</source>
 
</source>
  
==OS Dynamic Texture Language==
+
== OS Dynamic Texture Language ==
  
 
Many of the OSSL drawing functions are convenience functions to help build the command line for the osSetDynamicTextureData data parameter. You may find it easier to build the string yourself using the drawing commands directly. Do this by declaring a string then appending sets of commands and parameters until it is ready. Each command is separated by a semi-colon ";". Additional parameters may be set for the image with the extraParams parameter.
 
Many of the OSSL drawing functions are convenience functions to help build the command line for the osSetDynamicTextureData data parameter. You may find it easier to build the string yourself using the drawing commands directly. Do this by declaring a string then appending sets of commands and parameters until it is ready. Each command is separated by a semi-colon ";". Additional parameters may be set for the image with the extraParams parameter.
Line 60: Line 71:
 
;osSetDynamicTextureData(string dynamicID, string contentType, string data, string extraParams, int timer)
 
;osSetDynamicTextureData(string dynamicID, string contentType, string data, string extraParams, int timer)
  
:*dynamicID not used yet – send “”
+
:* '''dynamicID:''' not used yet – send “”
:*contentType use “vector” for drawing commands or use “image” for loadurl
+
:* '''contentType:''' use “vector” for drawing commands or use “image” for loadurl
:*data the graphics commands in the string with the format of: “MoveTo 20, 20; FillRectangle 60, 60;”;
+
:* '''data:''' the graphics commands in the string with the format of: “MoveTo 20, 20; FillRectangle 60, 60;”;
:*extraParams width, height, alpha, bgcolour, altdatadelim
+
:* '''extraParams:''' width, height, alpha, bgcolour, altdatadelim
:*timer set an update interval
+
:* '''timer:''' set an update interval
  
===Commands (data)===
+
=== Commands (data) ===
;MoveTo int x, int y;
+
;MoveTo int x, int y;  
 
:Places the brush at the x/y coordinate
 
:Places the brush at the x/y coordinate
  
;LineTo int x,int y;  
+
;LineTo int x,int y;  
 
:Draws line from present pen position to the x/y coordinate
 
:Draws line from present pen position to the x/y coordinate
  
;Text string content;
+
;Text string content;  
 
:Text to write to the image
 
:Text to write to the image
  
;Image float x, float y, string URL
+
;Image float x, float y, string URL  
 
:The x/y placement coordinates and URL of an image to load
 
:The x/y placement coordinates and URL of an image to load
  
;Rectangle float x, float y;
+
;Rectangle float x, float y;  
 
:Draws a rectangle with the current pen from the current pen location to the x/y coordinates
 
:Draws a rectangle with the current pen from the current pen location to the x/y coordinates
  
Line 85: Line 96:
 
:Draws a filled rectangle with the current brush from the current pen location to the x/y coordinates
 
:Draws a filled rectangle with the current brush from the current pen location to the x/y coordinates
  
;Ellipse float x, float y;
+
;Ellipse float x, float y;  
 
:Draws an ellipse with the current brush from the current brush location to the x/y coordinates
 
:Draws an ellipse with the current brush from the current brush location to the x/y coordinates
  
;FontSize int size;
+
;FontSize int size;  
 
:The size of the font for text
 
:The size of the font for text
  
;FontProp char;
+
;FontProp char;
 
:'''[B|I|U|S|R]'''
 
:'''[B|I|U|S|R]'''
  
::*'''B''' Bold
+
::* '''B''' Bold
::*'''I''' Italic
+
::* '''I''' Italic
::*'''U''' Underline
+
::* '''U''' Underline
::*'''S''' Strikeout
+
::* '''S''' Strikeout
::*'''R''' Regular
+
::* '''R''' Regular
  
;FontName string name;
+
;FontName string name;  
 
:The name of the font to use
 
:The name of the font to use
  
;PenSize float size;
+
;PenSize float size;  
 
:Size of the drawing pen
 
:Size of the drawing pen
  
;PenColour string color;  
+
;PenColour string color; or PenColor string color;  
 
:Drawing color of the pen
 
:Drawing color of the pen
  
Line 113: Line 124:
  
 
'''Example'''
 
'''Example'''
<source lang="lsl">
+
<source lang="lsl">
        string drawData;
+
string drawData;
 
+
drawData += "PenColour Teal; FillRectangle 1024, 512;";
        drawData += "PenColour Teal; FillRectangle 1024, 512;";
+
drawData += "PenColour PowderBlue;";
        drawData += "PenColour PowderBlue;";
+
drawData += "MoveTo 40, 30; FontSize 25; Text 2000 UTC:;";
        drawData += "MoveTo 40, 30; FontSize 25; Text 2000 UTC:;";
+
drawData += "MoveTo 250, 30; Text Speed Build Competition;";
        drawData += "MoveTo 250, 30; Text Speed Build Competition;";
+
drawData += "MoveTo 40, 70; Text 0120 UTC:;";
        drawData += "MoveTo 40, 70; Text 0120 UTC:;";
+
drawData += "MoveTo 250, 70;Text Working On Sign;";
        drawData += "MoveTo 250, 70;Text Working On Sign;";
+
drawData += "MoveTo 40, 110; Text 0500 UTC:;";
        drawData += "MoveTo 40, 110; Text 0500 UTC:;";
+
drawData += "MoveTo 250, 110; Text Going To Sleep!;";
        drawData += "MoveTo 250, 110; Text Going To Sleep!;";
+
drawData += "MoveTo 40, 150; Text 0600 UTC:;";
        drawData += "MoveTo 40, 150; Text 0600 UTC:;";
+
drawData += "MoveTo 250, 150; FontProp B,I;Text Waking Up!;";
        drawData += "MoveTo 250, 150; FontProp B,I;Text Waking Up!;";
+
drawData += "FontProp R;";
        drawData += "FontProp R;";
+
drawData += "MoveTo 40, 190; Text Have a great day!!;";
        drawData += "MoveTo 40, 190; Text Have a great day!!;";
+
drawData += "PenCap end,arrow; LineTo 50,250; MoveTo 50,250;";
        drawData += "PenCap end,arrow; LineTo 50,250; MoveTo 50,250;";
+
osSetDynamicTextureData("","vector", drawData,"width:1024,height:512,alpha:254", 0);
       
+
</source>
        osSetDynamicTextureData("","vector", drawData,"width:1024,height:512,alpha:254", 0);
+
 
+
</source>
+
  
===Extra Parameters (extraParams)===
+
=== Extra Parameters (extraParams) ===
 
;height
 
;height
 
:the height for the image in pixels
 
:the height for the image in pixels
Line 149: Line 157:
 
:the background color of the image
 
:the background color of the image
  
[[http://msdn.microsoft.com/en-us/library/aa358802.aspx .net colors]]
+
[http://msdn.microsoft.com/en-us/library/aa358802.aspx Microsoft .net colors]
  
 
;altdatadelim
 
;altdatadelim
 
:an alternative delimiter for each parameter - useful if you want to display text that contains semicolons, for example C# or LSL code.
 
:an alternative delimiter for each parameter - useful if you want to display text that contains semicolons, for example C# or LSL code.
 +
 +
[[Category:OSSL]]
 +
[[Category:Scripting]]

Latest revision as of 12:12, 19 October 2019


[edit] General Capabilities

The OSSL Texture Drawing functions allow the scripter to dynamically generate a texture on the fly, from within the context of an script. (It can be written in LSL, C# or any other supported scripting language.)

The scripting language supports text and images, as well as three simple drawing primitives: line, rectangle and ellipse. Color and pen attributes are included. Font, size and style are supported for text. An image is specified as an URL.

A drawing script can be directly specified in the texture drawing language, or can be built by using helper functions in the scripting language. Examples of both approaches are shown below.

Several extra parameters are available for the texture rendering operation. These include the height and width of the texture, as well as the background color and alpha value. A statement terminator can also be specified.

LSL Helper Functions

string osMovePen(string drawList, int x, int y);
string osDrawLine(string drawList, int startX, int startY, int endX, int endY);
string osDrawLine(string drawList, int endX, int endY);
string osDrawText(string drawList, string text);
string osDrawEllipse(string drawList, int width, int height);
string osDrawRectangle(string drawList, int width, int height);
string osDrawFilledRectangle(string drawList, int width, int height);
string osDrawPolygon(string drawList, LSL_List x, LSL_List y);
string osSetFontSize(string drawList, int fontSize);
string osSetPenSize(string drawList, int penSize);
string osSetPenColor(string drawList, string colour);
string osSetPenCap(string drawList, string direction, string type);
string osDrawImage(string drawList, int width, int height, string imageUrl);

C# Code Example

//cs
public void default_event_state_entry()
{
    string drawList = "";
    drawList = osDrawLine (drawList, 10,20,240,20);
    drawList = osMovePen (drawList, 50,100); 
    drawList = osDrawImage(drawList, 100,100,"http://opensimulator.org/images/d/de/Opensim_Wright_Plaza.jpg" );
    drawList = osSetPenSize (drawList, 1); 
    drawList = osSetPenCap(drawList, "end", "arrow");
    drawList = osMovePen (drawList, 50,70);
    drawList = osDrawEllipse (drawList, 20,20);
    drawList = osMovePen(drawList, 90,70); 
    drawList = osDrawRectangle (drawList, 20,20 );
    drawList = osMovePen (drawList,130,70); 
    drawList = osDrawFilledRectangle(drawList, 20,20);
    drawList = osDrawPolygon(drawList, [50,100,150], [50,100,50]); 
    drawList = osDrawFilledPolygon(drawList, ["50","100","150"], ["50","100","50"]); // It works with integers, float or string as the x and y points
    drawList = osSetFontSize (drawList, 12 );
    drawList = osMovePen (drawList,15,32); 
 
    string regionName = llGetRegionName();
    drawList = osDrawText (drawList, "Hello and welcome to " + regionName );
 
    drawList = osSetFontSize (drawList, 7); 
    drawList = osSetPenColor (drawList, "blue");
    drawList = osMovePen (drawList, 70,220);
    drawList = osDrawText (drawList, "The End");
    osSetDynamicTextureData("", "vector", drawList, "", 0);
}

[edit] OS Dynamic Texture Language

Many of the OSSL drawing functions are convenience functions to help build the command line for the osSetDynamicTextureData data parameter. You may find it easier to build the string yourself using the drawing commands directly. Do this by declaring a string then appending sets of commands and parameters until it is ready. Each command is separated by a semi-colon ";". Additional parameters may be set for the image with the extraParams parameter.

osSetDynamicTextureData(string dynamicID, string contentType, string data, string extraParams, int timer)
  • dynamicID: not used yet – send “”
  • contentType: use “vector” for drawing commands or use “image” for loadurl
  • data: the graphics commands in the string with the format of: “MoveTo 20, 20; FillRectangle 60, 60;”;
  • extraParams: width, height, alpha, bgcolour, altdatadelim
  • timer: set an update interval

[edit] Commands (data)

MoveTo int x, int y;
Places the brush at the x/y coordinate
LineTo int x,int y;
Draws line from present pen position to the x/y coordinate
Text string content;
Text to write to the image
Image float x, float y, string URL
The x/y placement coordinates and URL of an image to load
Rectangle float x, float y;
Draws a rectangle with the current pen from the current pen location to the x/y coordinates
FillRectangle float x, float y;
Draws a filled rectangle with the current brush from the current pen location to the x/y coordinates
Ellipse float x, float y;
Draws an ellipse with the current brush from the current brush location to the x/y coordinates
FontSize int size;
The size of the font for text
FontProp char;
[B|I|U|S|R]
  • B Bold
  • I Italic
  • U Underline
  • S Strikeout
  • R Regular
FontName string name;
The name of the font to use
PenSize float size;
Size of the drawing pen
PenColour string color; or PenColor string color;
Drawing color of the pen
PenCap string direction, string type;
Cap of a line, consists of 3 possible directions ("start","end","both") and 4 possible types ("flat","diamond","arrow","round")

Example

string drawData;
drawData += "PenColour Teal; FillRectangle 1024, 512;";
drawData += "PenColour PowderBlue;";
drawData += "MoveTo 40, 30; FontSize 25; Text 2000 UTC:;";
drawData += "MoveTo 250, 30; Text Speed Build Competition;";
drawData += "MoveTo 40, 70; Text 0120 UTC:;";
drawData += "MoveTo 250, 70;Text Working On Sign;";
drawData += "MoveTo 40, 110; Text 0500 UTC:;";
drawData += "MoveTo 250, 110; Text Going To Sleep!;";
drawData += "MoveTo 40, 150; Text 0600 UTC:;";
drawData += "MoveTo 250, 150; FontProp B,I;Text Waking Up!;";
drawData += "FontProp R;";
drawData += "MoveTo 40, 190; Text Have a great day!!;";
drawData += "PenCap end,arrow; LineTo 50,250; MoveTo 50,250;";
osSetDynamicTextureData("","vector", drawData,"width:1024,height:512,alpha:254", 0);

[edit] Extra Parameters (extraParams)

height
the height for the image in pixels
width
the width of the image in pixels
alpha
the opacity of the image
0-255 to set the opacity for an image with an alpha channel
false for an image with no alpha channel
bgcolour
the background color of the image

Microsoft .net colors

altdatadelim
an alternative delimiter for each parameter - useful if you want to display text that contains semicolons, for example C# or LSL code.
Personal tools
General
About This Wiki