0% found this document useful (0 votes)
6 views

ch-4 (1)

Chapter Four discusses the attributes of graphics primitives in OpenGL, including color, point, line, and fill-area attributes. It explains how to modify these attributes using specific OpenGL functions, detailing the effects of state variables on the display of primitives. The chapter concludes with examples of how to implement these attributes in OpenGL code.

Uploaded by

atinasianegash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

ch-4 (1)

Chapter Four discusses the attributes of graphics primitives in OpenGL, including color, point, line, and fill-area attributes. It explains how to modify these attributes using specific OpenGL functions, detailing the effects of state variables on the display of primitives. The chapter concludes with examples of how to implement these attributes in OpenGL code.

Uploaded by

atinasianegash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Chapter Four

Attributes of graphics
primitives

computer graphice 05/03/2025 1


Outline
 Introduction

 Colour Attribute

 OpenGL Colour Attributes

 Point Attributes

 Line Attributes

 Fill-Area Attributes

computer graphice 05/03/2025 2


Introduction
 In this chapter we will consider the subject of attributes of graphics
primitives.
 We can define an attribute of a primitive as a parameter that affects the
way the primitive is displayed.
 OpenGL is a state system: it maintains a list of current state variables
that are used to modify the appearance of each primitive as it is
displayed.
 Therefore these state variables represent the attributes of the
primitives.
 The values of state variables remain in effect until new values are
specified, and changes to state variables affects primitives drawn after
the change.
 The rest of this chapter is structured according to the type of primitive
that the attribute affects. We will look at attributes of point primitives,
line primitives, fill-area primitives.

computer graphice 05/03/2025 3


Color attribute
 In the pervious chapter example we defined values for two colour state
variables: the drawing colour and the background colour.
 We also saw that we can define colours in two different ways:

 RGB: the colour is defined as the combination of its red, green and
blue components.
 RGBA: the colour is defined as the combination of its red, green and
blue components together with an alpha value, which indicates
the degree of opacity/transparency of the colour.

computer graphice 05/03/2025 4


OpenGL Colour Attributes.…
 We have already seen how to modify the drawing and background
colours in the simple OpenGL program in pervious chapter.
 To recap, we change the current drawing colour using the glColor*
function.
 We change the current background colour using the glClearColor
function.
 The background colour is always set using an RGBA colour
representation.
 The drawing colour can be set using either RGB or RGBA
representations.

computer graphice 05/03/2025 5


Cont…
 The following are all valid examples of setting the drawing
and background colours:
 glColor3f(1.0,0.0,0.0); // set drawing colour to red
 glColor4f(0.0,1.0,0.0,0.05); // set drawing colour to
semi-transparent green
 glClearColor(1.0,1.0,1.0,1.0); // set background colour to
opaque white

computer graphice 05/03/2025 6


Cont.…

 Before we do any drawing in OpenGL, we must define a frame buffer.


 If we want to do colour drawing then we must specify that we want a
colour frame buffer.
 The following line defines a single direct storage colour frame buffer
with red, green and blue components:
 glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB).
 In order to store alpha values in the frame buffer we must change the
second argument to GLUT_RGBA.

computer graphice 05/03/2025 7


Point Attributes

 Points are the simplest type of primitive so the only attributes we can
modify are the colour and size of the point.
 To change the size of points in pixels we use:

 glPointSize(size);

 All points in OpenGL are drawn as squares with a side length equal
to the point size.
 The default point size is 1 pixel.

computer graphice 05/03/2025 8


Line Attributes
 The attributes of line primitives that we can modify include the
following:-
 Line colour

 Line width

 Line style (solid/dashed etc)

1. Line Width
 The simplest and most common technique for increasing the width of a
line is to plot a line of width 1 pixel, and then add extra pixels in either
the horizontal or vertical directions.

computer graphice 05/03/2025 9


Cont.…
 Which of these two approaches we use depends on the gradient m of
the line. We identify the following cases:-
 If |m| ≤ 1 plot extra pixels vertically.
 If |m| > 1, plot extra pixels horizontally.

computer graphice 05/03/2025 10


Cont.…
 To change the line width we use the glLineWidth routine. .

 This takes a single floating point argument (which is rounded to the


nearest integer) indicating the thickness of the line in pixels. For
example:-
 glLineWidth(4.3);
 This value will be used for all subsequent line primitives until the next
call to glLineWidth.
2. Line Style
 The style of a line refers to whether it is plotted as a solid line, dotted,
or dashed.
 The normal approach to changing line style is to define a pixel mask.

 A pixel mask specifies a sequence of bit values that determine


whether pixels in the plotted line should be on or off.
computer graphice 05/03/2025 11
Cont.…
 For example, the pixel mask 11111000 means a dash length of 5 pixels

followed by a spacing of 3 pixels.

 In other words, if the bit in the pixel mask is a 1, we plot a pixel, and if

it is a zero, we leave a space.

 The line style is specified using a pixel mask.

 First we must enable the line stipple feature of OpenGL using the

following line: glEnable(GL_LINE_STIPPLE);

computer graphice 05/03/2025 12


 Next, we use the glLineStipple function to define the line style.
 glLineStipple takes two arguments: a repeat factor, which specifies
how many times each bit in the pixel mask should be repeated, and a
pattern, which is a 16-bit pixel mask.
 If factor is 3, for example, each bit in the pattern will be used three
times before the next bit in the pattern is used.

computer graphice 05/03/2025 13


Cont.…
 For example, the code shown below draws the dashed line shown to
the right.
 glEnable(GL_LINE_STIPPLE);
 glLineWidth(3.0);
 glLineStipple(1, 0x00FF);
 glBegin(GL_LINE_STRIP);
 glVertex2i(100,100);
 glVertex2i(150,100);
 glVertex2i(150,200);
 glVertex2i(250,250);
 glEnd();
 glDisable(GL_LINE_STIPPLE);

computer graphice 05/03/2025 14


Fill-Area Attributes
 The most important attribute for fill-area polygons is whether they are
filled or not.
 We can either draw a filled polygon or drawn the outline only. Drawing
the outline only is known as wireframe rendering.
 If the polygon is to be filled we can specify a fill style.

 OpenGL provides a number of features to modify the appearance of fill-


area polygons.
 First, we can choose to fill the polygon or just display an outline (i.e.
wireframe rendering).
 We do this by changing the display mode using the glPolygonMode
routine. The basic form of this function is:-
 glPolygonMode(face, displayMode);

computer graphice 05/03/2025 15


Cont.…
 Here, the face argument can take any of the following values:-

 GL_FRONT: apply changes to front-faces of polygons only.

 GL_BACK: apply changes to back-faces of polygons only.

 GL_FRONT_AND_BACK: apply changes to front and back faces of


polygons.
 The displayMode argument can take any of these values:

 GL_FILL: fill the polygon faces.

 GL_LINE: draw only the edges of the polygons (wireframe


rendering)
 GL_POINT: draw only the vertices of the polygons.

computer graphice 05/03/2025 16


Cont.….
 glPolygonMode (GL_FRONT, GL_LINE);

 glBegin(GL_POLYGON);

 glVertex2i(350,250);
 glVertex2i(400,300);
 glVertex2i(400,350);
 glVertex2i(300,250);
 glEnd();

 In addition to changing the polygon drawing mode, we can also specify


a fill pattern for polygons.
 We do this using the polygon stipple feature of OpenGL.

computer graphice 05/03/2025 17


Cont.…
 The steps can be summarised as:-
 Define a fill pattern
 Enable the polygon stipple feature of OpenGL
 Draw polygons
 For example, the following code draws an eight-sided polygon with a fill pattern .
GLubyte fillPattern[] = {0x00, 0xFF};
glPolygonStipple(fillPattern);
glEnable(GL_POLYGON_STIPPLE);
glBegin(GL_POLYGON);
glVertex2i(350,250);
glVertex2i(400,300);
glVertex2i(400,350);
glVertex2i(350,400);
glVertex2i(300,400);
glVertex2i(250,350);
glVertex2i(250,300);
glVertex2i(300,250);
glEnd();
glDisable(GL_POLYGO_STIPPLE);

computer graphice 05/03/2025 18


Exercise
 Write an OpenCL program that display the following image.

computer graphice 05/03/2025 19


Next class
Chapter five Transformation ????

Thank you .

computer graphice 05/03/2025 20

You might also like