PES Institute of Technology, Bangalore South Campus (Formerly PES School of Engineering) (Hosur Road, 1KM before Electronic City, Bangalore-560 100) INTERNAL TEST (SCHEME AND SOLUTION) 1 Subject Name: Computer Graphics Subject Code: (13MCA34) 1. About Open GL GLU This library uses only GL functions but contains code for creating common objects and simplifying viewing. Functions in the GLU library begin with the letter glu. GLUT To interface with the window system and to get input from external devices into our programs, we need at least one more library. GLX : OpenGL Extension for the X Window System For the X window system, this library is called GLX WGL for windows, it is wgl WGL or Wiggle is the windowing system interface to the Microsoft Windows implementation of the OpenGL specification. AGL for the macintosh it is agl or(apple graphics library). Rather than using a different library for each system,we use a readily available library called the opengl utility Toolkit(GLUT). GLUT provides minimum functionality that should be expected in any modern windowing system.
OpenGL supports two classes of primitives: Geometric primitives Image (or) raster primitives Geometric primitives Include points, line segments, polygons, curves and surfaces. These primitives pass through a geometric pipeline. where they are subject to a series of geometric operations that determine whether a primitive is visible or not Where on the display it appears if it is visible. 2.DDA Algorithm Digital Differential Analyzer DDA was a mechanical device for numerical solution of differential equations Line y=mx+ h satisfies differential equation dy/dx = m = Dy/Dx = y 2 -y 1 /x 2 -x 1 Along scan line Dx = 1 For(x=x1; x<=x2,ix++) {
y+=m; write_pixel(x, round(y), line_color) } 3.Bresenham s Algorithm DDA requires one floating point addition per step We can eliminate all fp through Bresenham s algorithm Consider only 1 m 0 Other cases by symmetry Assume pixel centers are at half integers If we start at a pixel that has been written, there are only two candidates for the next pixel to be written into the frame buffer More efficient if we look at d k, the value of the decision variable at x = k d k+1 = d k 2Dy, if d k <0 d k+1 = d k 2(Dy- Dx), otherwise For each x, we need do only an integer addition and a test Single instruction on graphics chips 4. Circle: Bresenham algorithm Choice between two pixels: Mid-point algorithm: If the midpoint between pixels is inside the circle, E is closer, draw E If the midpoint is outside, SE is closer, draw SE Error function: d = x 2 +y 2 - r 2 Compute d at the midpoint:
If the last pixel drawn is (x,y), then E = (x+1,y), and SE = (x+1,y-1). Hence, the midpoint = (x+1,y-1/2). d(x,y) = (x+1) 2 + (y - 1/2) 2 - r 2 d < 0: draw E d ³ 0: draw SE In each step (go to E or SE), i.e., increment x: x+=1: d += 2x +3 If I go to SE, i.e., x+=1, y+=-1: d += -2y + 2 The error is not linear However, what I add to the error is Keep Dx and Dy: At each step: Dx += 2, Dy += -2 d += Dx If I decrement y, d += Dy 4 additions per pixel
5. Different types of Graphical functions Primitives (WHAT) Points Line Segments Polygons
Attributes (HOW) Viewing (CAMERA) Transformations Control (GLUT) Input (GLUT) Query (Device independent programs- 2 color) Define the low level objects or atomic entities that our system can display. Depending on the API, the primitives can include Example glbegin(gl_points); glvertex2f(100.0,200.0); glend(); glbegin(gl_lines); glvertex2f(100.0,200.0); glvertex2f(300.0,400.0); glend(); points, line segments, polygons, pixels, text, and various type of curves and surfaces..about Graphical Functions To perform operations ranging from choosing the color with which we display a line segment. Eg glcolor3f(1.0,0.0,0.0); gllinewidth(width); To picking a pattern with which to fill the inside of a polygon.
To selecting a typesafe for the title on a graph. The viewing functions allows us to specify various views,although APIs differ in the degree of flexibility they provide in choosing a view. glviewport (xvmin, yvmin, vpwidth, vpheight); gluortho2d (xwmin, xwmax, ywmin, ywmax); Transformation function that allows to carry out transformations of objects. such as rotation, translation and scaling. Input function gltranslatef (tx, ty, tz); glrotatef (theta, vx, vy, vz); glscalef (sx, sy, sz); Allows us to deal with the diverse forms of input that characterize modern graphics systems. Control function void glutkeyboardfunc(void (*func) (unsigned char key, int x, int y)); Enable us to communicate with the window system, to initialize our programs and to deal with any errors that take place during the execution of our programs. Query function glutinitwindowsize(500,500); How many color are supported or The size of the display. Camera parameters or values in the frame buffer. 6.About open GL Line and Polygon Drawing Functions The primitive and their type specification include the following:.
Points(GL_POINTS): Each vertex is displayed at a size of at least one pixel. Line segments(gl_lines): Successive pairs of vertices to be interpreted as the endpoints of individual segments. Polylines(GL_LINE_STRIP,GL_LINE_LOOP): GL_LINE_STRIP If successive vertices are to be connected, we can use the line strip or polyline form. GL_LINE_LOOP will draw a line segment from the final vertex to the first, thus creating a closed path. Polygons(GL_POLYGON): successive vertices define line segments and a line segment connects the final vertex to the first. use the function glpolygonmode to tell the renderer to generate only the edges or just points for the vertices, instead of fill. glpolygonmode(gl_front_and_back, GL_LINE); Triangle and quadrilaterals (GL_TRIANGLES,GL_QUADS): Successive groups of three and four vertices are interpreted as triangles and quadrilaterals Strips and Fans(GL_TRIANGLE_STRIP, GL_QUAD_STRIP, GL_TRIANGLE_FAN)
groups of triangles or quadrilaterals that share vertices and edges. Triangle strip Each additional vertex is combined with the previous two vertices to define a new triangle. Quadstrip Combine two new vertices with the previous two vertices to define a new quadrilateral. Triangle fan Triangle fan is based on the one fixed point. The next two points determine the first triangle, and subsequent triangles are formed from one new point, the previous point and the first point.