2D Drawing

From Leadwerks Developer Wiki

Jump to: navigation, search

Contents

Introduction

Drawing using OpenGL

Leadwerks Engine uses OpenGL for rendering. You can also use OpenGL commands directly to draw 2D and even 3D shapes on the screen.
See "Using OpenGL for drawing (Article)" for more information on how to use OpenGL commands in Leadwerks Engine and an example.

Builtin Commands

Drawing Commands

Plot

  • C: void Plot( int x, int y)
  • C++: static void Draw::Plot( int x, int y )
  • BlitzMax: Plot( x:Int, y:Int )
  • Pascal: procedure Plot ( x:Integer; y:Integer );
Draws a single pixel on screen.
[Examples]

DrawLine

  • C: void DrawLine( int x1, int y1, int x2, int y2 )
  • C++: static void Draw::Line( int x1, int y1, int x2, int y2 )
  • BlitzMax: DrawLine( x1:Int, y1:Int, x2:Int, y2:Int )
  • Pascal: procedure DrawLine ( x1:Integer; y1:Integer; x2:Integer; y2:Integer );
Draws a line on screen between coordinates 1 and 2.
[Examples]

DrawRect

  • C: void DrawRect( int x, int y, int width, int height )
  • C++: static void Draw::Rect( int x, int y, int width, int height )
  • BlitzMax: DrawRect( x:Int, y:Int, width:Int, height:Int )
  • Pascal: procedure DrawRect ( x:Integer; y:Integer; width:Integer; height:Integer );
Draws a rectangle on screen.
[Examples]

DrawImage

  • C: void DrawImage( TEntity texture, int x, int y, int width, int height )
  • C++: static void Draw::Image( const Texture& image, int x, int y, int width = -1, int height = -1 );
  • BlitzMax: DrawImage( texture:TTexture, x:Int, y:Int [, width:Int=-1, height:Int=-1 ] )
  • Pascal: procedure DrawImage ( texture:THandle; x:Integer=0; y:Integer=0; width:Integer=-1; height:Integer=-1 );
Draws a texture on screen. The image rectangle will start at the specified coordinate and the image will be stretched to match the specified width and height.
[Examples]

DrawText

  • C: void DrawText( int x, int y, str text, ... )
  • C++: static int Draw::Text( int x, int y, const_str text, ... )
  • BlitzMax: DrawText( text:String, x:Int, y:Int )
  • Pascal: procedure DrawText ( text:PAnsiChar; x:Integer; y:Integer );
Draws a text on screen.
[Examples]

SetColor

  • C:
    • void SetColor(TVec4 &color=Vec4(1))
    • void SetColor(flt r, flt g, flt b, flt a=1)
  • C++:
    • static void Draw::SetColor( const TVec3& color )
    • static void Draw::SetColor( const TVec4& color )
    • static void Draw::SetColor( flt red, flt green, flt blue, flt alpha = 1.0f )
  • BlitzMax: SetColor( color:TVec4 )
  • Pascal: procedure SetColor ( const color:TVec4 );
Sets the drawing color.
[Examples]

SetBlend

  • C++: void SetBlend( int blendMode )
  • BlitzMax: SetBlend( blendMode:Int )
  • Pascal: procedure SetBlend ( blendmode:Integer );
Sets the drawing blend. The following values are allowed:
  • BLEND_ALPHA
  • BLEND_LIGHT
  • BLEND_SHADE
  • BLEND_MOD2X
[Examples]

Font Commands

LoadFont

  • C: TFont LoadFont(str name)
  • C++:
    • Font::Font( const std::string& fontName ) ;
    • Font::Font( const Font& font ) ;
    • virtual void Font::Create( const std::string& fontName ) ;
  • Pascal: function LoadFont ( name:PAnsiChar ): THandle;
Loads a font and returns a handle to it. Leadwerks Engine supports Font Studio fonts, which should be saved as a .dds and .ini file. E.g. when loading LoadFont("abstract::myfont"), the engine will load a font from abstract::myfont.ini and abstract::myfont.dds. See the example page for more detailed information.
[Examples]

SetFont

  • C: void SetFont( TFont font )
  • C++: void Font::Set( void )
  • Pascal: procedure SetFont ( font:THandle );
Sets the font to use when drawing text.
[Examples]

TextWidth

  • C: int TextWidth(str text)
  • C++: static int Draw::GetTextWidth( const_str text )
  • BlitzMax: TextWidth:Int( text:String )
Returns the width in pixels the specified string would have if it was drawn with the current font.
[Examples]

FontHeight

  • C: int FontHeight( void )
  • C++: int FontHeight( void )
  • BlitzMax: FontHeight:Int()
Returns the maximum height of the current font. If no font has been loaded, the default font will be used.
[Examples]

FreeFont

  • C: void FreeFont( TFont font )
  • C++: void Font::Free( void ) Note: Also called from destructor
  • Pascal: procedure FreeFont ( font:THandle );
Frees the specified font from memory.
[Examples]
Personal tools