Silverfrost Logo About Us | Contact Us

Using GDI+

You can access some features of GDI+ using a %gr - Graphics Region format code. In particular you can utilise anti-aliasing and use opacity. Simply turning on anti-aliasing will give your graphics a much smoother look. In some cases you may need to do some work to get the most out of these features.

Here is an introduction to the  main features. For further details see topic number 354 in the ClearWin+ enhancements document cwplus.enh.


Anti-aliasing is a process whereby pixels next to drawn lines are modified to produce a smoother effect. For example, if a circle was drawn in red the standard algorithm will produce a set of red pixels that approximate a circle. The actual pixels coloured red will appear jagged when view closely. When the same pixel is drawn using an anti-aliased algorithm then extra coloured pixels are used to give the illusion of a smoother line. On a screen display the effects can be dramatic with the anti-aliased graphics looking much cleaner and less jagged.

The following simple program illustrates how turning on anti-aliasing can improve a program's output.

 use clrwin
 integer ctrl
 integer last_x, last_y, mid_y
 integer new_x, new_y
 integer :: parameter, width = 500, height = 250, gutter = 20
 real sinx
 ! set up the surface to draw onto. Remove [smooth4] to see what anti-aliasing has given you
 iw=winio@('%gr[smooth4]&', width, height)
 iw=winio@('%lw', ctrl)
 ! draw axes
 mid_y = height / 2
 call draw_line_between@(gutter, gutter, gutter, width-gutter, 0 )
 call draw_line_between@(gutter, mid_y, width-gutter, mid_y, 0 )

 do i = 0,width-(2*gutter)
   ! make the width of the x-axis span 0..2pi. REAL(width-(2*gutter) is the width of that axis
   sin_x = sin((i/REAL(width-(2*gutter)))*2*3.1415926)
   new_y = mid_y + sin_x*(mid_y-gutter)
   if (i > 0) then
     call draw_line_between@(gutter+i-1, last_y, gutter+i, new_y, RGB@(255,0,0) )
   end if
   last_y = new_y
 end do
No anti-aliasing

output with no anti-aliasing

output with anti-alaising


By varying opacity you can allow some of the background to show through when you draw onto a surface. you can either set the overall opacity through a call to set_opacity@ or you can set it on a call by call basis using the nARGB@ function to create the colour. In the example below two sets of three circles are overlapped. The right hand set has the opacity set. The left hand set has just one circle drawn with opacity.

 use clrwin
 integer ctrl
 real sinx
 iw=winio@('%gr[smooth4]&', 220, 110)
 iw=winio@('%lw', ctrl)
 call draw_filled_ellipse@(40, 40, 30, 30, RGB@(255,0,0) )
 call draw_filled_ellipse@(70, 40, 30, 30, RGB@(0,255,0) )
 ! draw this circle with opacity
 call draw_filled_ellipse@(55, 70, 30, 30, nARGB@(192,0,0,255) )
 ! set general opacity to 50% 
 call set_opacity@(128)
 call draw_filled_ellipse@(150, 40, 30, 30, RGB@(255,0,0) )
 call draw_filled_ellipse@(180, 40, 30, 30, RGB@(0,255,0) )
 call draw_filled_ellipse@(165, 70, 30, 30, RGB@(0,0,255) )
Opacity Test

output with no anti-aliasing


Copyright © 1999-2017 Silverfrost Limited