graphics n.
Skip this Video
Loading SlideShow in 5 Seconds..
Graphics PowerPoint Presentation
Download Presentation

Loading in 2 Seconds...

play fullscreen
1 / 38

Graphics - PowerPoint PPT Presentation

  • Uploaded on

Graphics. CSE 500 Summer 1998. Graphics in X. X assumes bitmapped graphics The screen is a rectangular array of pixels Drawing consists of setting the values of pixels the array of pixels may have a depth (planes) X provides primitives to draw figures X provides the means to draw text

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript


CSE 500

Summer 1998

graphics in x
Graphics in X
  • X assumes bitmapped graphics
    • The screen is a rectangular array of pixels
    • Drawing consists of setting the values of pixels
    • the array of pixels may have a depth (planes)
  • X provides primitives to draw figures
  • X provides the means to draw text
  • X provides the means to specify images directly.
  • Drawing is to a connection called a Display.
  • A window is created to hold the drawing
  • An invisible Pixmap can be created and drawn into instead of a window.
    • Drawables are windows or pixmaps.
  • A data structure called a graphics context (GC) specifies the attributed used when drawing.
steps of drawing
Steps of drawing
  • Select the pixels to draw
  • Apply patterns, color found in GC
  • Clip the picture by rectangles in GC

(according to a clipping rule and mask in GC)

  • Draw on the screen
the graphics context gc
The Graphics Context (GC)
  • The graphics context is a C struct containing information required to render a drawing
  • There may be several GCs but they should be viewed as limited resources.
  • Common practice is to create several GC as required and use as required
  • A single GC can be used and changed.
  • 1 GC and values changed with XChangeGC degrades performance
  • 2 or more GC use memory on the server (multiple clients make problem worse)
As the workstation draws graphics sent to it by an application program it interprets those primitives using attribute values contained in the specified GC.
  • Thus every application must have at least one GC resourc and load values to it before it can issue a graphic output request.

Widget drawingArea;

Display display;

Window w;

GC gc,newgc;

drawingArea = XmCreateDrawingArea(toplevel,”da”,al,ac);

/* a drawing area comes with a gc */

gc = XtGetGC(drawingArea,mask, &values);

/* a window (or other drawable) must create a gc */

newgc = XCreateGC(display,window, mask, &values); ,

creation or copy of a gc supports changing the GC structure by masking out certain fields of the structureand setting new values

steps in setting up the values structure
Steps in setting up the values structure.
  • Define an XGCValues structures
  • set members to the desired value
  • set the “mask” to reflect the members you are changing.
  • Create the GC with XCreateGC, XtGetGC
  • Destroy any unwanted GC with


  • Change or copy a GC with XChangeGC or XCopyGC
the xgcvalues structure
The XGCValues structure
  • members of this struct have a name
    • e.g. unsigned long plane_mask;
    • int line_width;
  • a mask name
    • e.g. GCPlaneMask
    • GCLineWidth
  • and a stage in the drawing when it has an effect
    • e.g. at raster output time
    • at pixel selection time
the graphics pipeline
The graphics pipeline
  • Pixel Selection time
    • The pixels that are to be set are defined
  • Patterning stage
    • The pixels set are masked by a pattern
  • GC clip stage
    • Pixels are clipped by gc clipping rectangles
  • Window clip stage
    • Pixels are clipped by the edges of windows
  • Raster output stage
    • Pixels are drawn in the drawable
pixel selection time
Pixel Selection Time

This stage of the pipeline operates on the output of graphics primitives such as line, arc, polygon, drawing primitives.

These primitives generally generate foreground pixels, some generate background pixels, and some both (e.g. a dashed line)

Attributes in the associated GC object such as line_width, join_style, etc. effect this stage.

patterning stage
Patterning Stage

This stage applies a pattern of values (colors) to foreground and background pixels. The following gc attributes are used in this stage

  • foreground - “the draw color” sets the color to use for foreground pixels
  • background - the value to apply to background pixls
  • stipple - an X resource identifier to use for effects such as hatch-patterns or screen-door patterning
  • tile - used for repeat patterning
  • fill-style - selects way to apply patterns ( tiling, hatching, solid fill, etc.)
gc clipping stage
GC clipping stage
  • This stage discards all pixels outside a specified region. This can be a clip mask defined in the gc or the result of an XSetClipRectangles request.
  • The default is no clipping at this stage
window clipping stage
Window Clipping Stage
  • This stage discards all pixels that lie outside the boundaries of the drawable. The only control the programmer has is to create subwindows and set attributes such as
    • ClipByChildren (default)
    • IncludeInferiors (draw through subwindows)
raster output stage
Raster Output Stage
  • This final stage combines the generated values with the values already present.
  • Two GC attributes control this behavior
    • function: one of 16 boolean functions of two variables.
    • plane_mask: a value of 1 causes update a value of 0 leaves the pixel alone.
changing a gc is like creating
Changing a GC is like creating

Display display;

GC gc;

unsigned long mask;

XGCValues values;


important note
Important note
  • If the drawable is a window, a window id must exist.
  • A window id does not exist until a widget is realized.
setting and manipulating the gc
Setting and manipulating the GC
  • Setting and manipulating the GC really means dealing with the XGCValues structure, a struct with over 20 fields.

typedef struct {

int function; /* GCFunction */

unsigned long plane_mask;/*GCPlaneMask */

unsigned long foreground /*GCForeground*/

the xgcvalues structure1
The XGCValues Structure
  • function:

as previously noted, this applies to raster output and can be one of 16 boolean values that indicate the logical meaning of new applied to old bits

GXClear - the new value is 0

GXSet - the new value is 1

GXxor - xor the new and old values

Gxor - or the new and old values

GXcopy - (default) overwrite old with new

the xgcvalues structure2
The XGCValues Structure
  • function:

a convenience function can be used to alter this without using XChangeGC or creating a new GC

XSetFunction(display,gc, GXxor);

the xgcvalues structure3
The XGCValues Structure
  • plane_mask

the bits set can be set in different planes. The default value is AllPlanes but one can set bits in planes indicated by a 1 in the mask

XSetPlaneMask(display, 0x0a);

  • foreground
  • background

foreground and background are pixel values for the draw color. Default foreground is 0, background in 1

the xgcvalues structure4
The XGCValues Structure
  • foreground
  • background

Safest black and white and using a convenience function

Display *display

GC mygc;

XSetForeground(display, mygc, BlackPixel(display), DefaultScreen(display))

XSetBackground(display, mygc, WhitePixel(display), DefaultScreen(display))

the xgcvalues structure5
The XGCValues Structure

The next group of entries in the struct effect line attributes,

  • int line_width;
  • int line_style;

line styles such as LineSolid, LineOnOffDash, LineDoubleDash are provided

line styles such as LineOnOffDash allow one to set 3 pixels on and 3 pixels off, or with LineDoubleDash 3 on 2 off 4 on 2 off, values can be set with the XSetDashes function.

the xgcvalues structure6
The XGCValues Structure
  • int cap_style,determines how drawing ends a line. CapNotLast, CapButt,CapRound CapProjecting are values.
  • int join_style;

defines how lines are joined together. JoinMiter, JoinBevel,JoinRound.

  • and a convenience function XSetLineAttributes(display,gc,line_width,line_style, cap_style,join_style);
the xgcvalues structure7
The XGCValues Structure
  • int fill_style;

has constants such as FillSolid, FillTiled, FillStippled

FillTiled uses the associated field Pixmap tile;

FillStippled uses the associated field Pixmap stipple;

  • int fill_rule

addresses the issue of what is the inside of a drawn polygonal figure. Rules such as EvenOddRule, say that if a line from the point to the outside crosses an odd number of lines it is inside. A WindingRule considers a line from test point to each vertex in both counter clockwise and clockwise directions to determine fill.

the xgcvalues structure8
The XGCValues Structure
  • int arc_mode;

supports filling of arcs drawn as either a

ArcPieSlice or ArcChord

  • Pixmap tile,stipple

have been mentioned already as associated with the fill rules.

  • int ts_x_orgin, ts_y_origin

x,y specify the relationship between the picture and the stipple mask or tile mask.. i.e shift the resulting design up or down, right or left.

the xgcvalues structure9
The XGCValues Structure
  • Font font;

is the default text font to be used.

  • int subwindow_mode;
  • Bool graphics_exposures;.

are concerned with window clipping and whether exposure events should be generated

  • int ts_x_orgin, ts_y_origin

x,y specify the relationship between the picture and the stipple mask or tile mask.. i.e shift the resulting design up or down, right or left.

the xgcvalues structure10
The XGCValues Structure
  • int clip_x_origin, clip_y_origin;

are used to define the region for a clipping mask.

  • Pixmap clipMask;

defines the clipping mask

  • int dash_offset;

defines dash behavior, and

  • char dashes;

defines dash appearance

it s time to draw
It’s time to draw
  • Having defined how the graphics pipeline is to behave, X routines provide input to the pipeline.
  • A Classification of routines is:



Arc and Circle Outlines

Filled Arcs and Circles

Rectangle Outlines

Filled Rectangles


  • XDrawPoint


  • XDrawPoints

XPoint points[1000];

int npts=1000;

for(..) { points[i].x = ; ..}

XDrawPoints(display,window,points,npts,CoordModeOrigin);/* relative to window origin */

  • XDrawLine

XDrawLine(display, window,gc,x1,y1,x2,y2);

  • XDrawLines

XDrawLines(display,window,points,npts, CoordModeOrigin);

  • XDrawSegment

XSegment segments[2]= { {x1,y1,x2,y2},



arcs and circle outlines
Arcs and Circle Outlines
  • Defining an arc:
    • x,y position of the upper left corner of bounding rectangle
    • width, height of bounding rectangle
    • angle1 is the starting angle (in 64th of degrees) of the arc to be drawn
    • angle 2 is the angle to draw the arc beginning at angle1. (angle1 = 0 and angle2=23040 (64*360) is a closed arc)
  • XDrawArc

XDrawArc(display, window,gc,x,y,width,height angle1,angle2);

arcs and circle outlines1
Arcs and Circle Outlines
  • using the Xtypedef struct { short x,y;

unsigned short width,height;

short angle1,angle2 } XArc;

  • XDrawArcs

XArc arcs[];

XDrawArc(display, window,gc,arcs,narcs);

filled arcs
Filled Arcs
  • Important to set the mode
    • ArcPieSlice specifies that the filled arc is to be drawn as a pie slice (default value)
    • ArcChord fills the arc that is closed b drawing a line from start to end of arc
  • XSetArcMode(display,gc,ArcChord);

XFillArc(display,window,gc,x,y,width, height,angle1,angle2);

filled arcs1
Filled Arcs
  • XFillArcs corresponds to XDrawArcs





XRectangle r[]


XDrawFillRectangles( . . .)

  • A polygon is defined by lines connecting vertices. XDrawLines can be used to draw polygons. XFillPolygon looks like the XDrawLines call, but it fills the polygon acording to a rule specified in the GC.


XFillPolygon(display,window,gc,points, npoints,shape,mode);

  • Shape is Convex,NonConvex,Complex, and allows a speedup of filling.