Graphics Models and Libraries-Computer Graphics-Lab Mannual, Lecture notes of Computer Graphics

Graphics is a fascinating area in Computer Science. It has wide applications both in research and industry. This course will teach the fundamentals of Computer Graphics. It deals with science of image formation and rendering on a computer screen. This lab manual includes: Graphics, Models, Libraries, Display, Commands, Functions, Programming, Java, Pixel, Process, Platform, Bindings

Typology: Lecture notes

2011/2012

Uploaded on 08/09/2012

parnika
parnika 🇮🇳

4.6

(12)

60 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Graphics Lab 1
1 Graphics Models and Libraries
A graphics display is a drawing area composed of an array of fine points called pixels. At the heart of a
graphics system there is a magic pen, which can move at lightning speed to a specific pixel and draw the
pixel with a specific color a red, green, and blue (RGB) vector value. This pen can be controlled
directly by hand through an input device (mouse or keyboard) like a simple paintbrush. In this case, we
can draw whatever we imagine, but it takes a real artist to come up with a good painting.
Computer graphics, however, is about using this pen automatically through programming.
A real or imaginary object is represented in a computer as a model and is displayed as an image. A model
is an abstract description of the object’s shape (vertices) and attributes (colors), which can be used to find
all the points and their colors on the object corresponding to the pixels in the drawing area. Given a
model, the application program will control the pen through a graphics library to generate the
corresponding image. An image is simply a 2D array of pixels.
A graphics library provides a set of graphics commands or functions. These commands can be bound in
C, C++, Java, or other programming languages on different platforms. Graphics commands can specify
primitive 2D and 3D geometric models to be digitized and displayed. Here primitive means that only
certain simple shapes (such as points, lines, and polygons) can be accepted by a graphics library. To
draw a complex shape, we need an application program to assemble or construct it by displaying pieces of
simple shapes (primitives). We have the magic pen that draws a pixel. If we can draw a pixel, we can
draw a line, a polygon, a curve, a block, a building, an airplane, and so forth. A general application
program can be included into a graphics library as a command to draw a complex shape. Because our pen
is magically fast, we can draw a complex object, clear the drawing area, draw the object
at a slightly different location or shape, and repeat the above processes the object is now animated.
OpenGL is a graphics library that we will integrate with the Java programming language to introduce
graphics theory, programming, and applications. When we introduce program examples, we will
succinctly discuss Java-specific concepts and programming as well for C/C++ programmers.
2 OpenGL Programming in Java: JOGL
OpenGL is the most widely used graphics library (GL) or application programming interface (API), and is
supported across all popular desktop and workstation platforms, ensuring wide application deployment.
JOGL implements Java bindings for OpenGL. It provides hardware-supported 3D graphics to applications
written in Java. It is part of a suite of open-source technologies initiated by the Game Technology Group
at Sun Microsystems. JOGL provides full access to OpenGL functions and integrates with the AWT and
Swing widget sets.
3. Instructions for today
Execute the sample Netbeans code provided.
Implement the code for drawing a line through the DDA algorithm
docsity.com
pf2

Partial preview of the text

Download Graphics Models and Libraries-Computer Graphics-Lab Mannual and more Lecture notes Computer Graphics in PDF only on Docsity!

Graphics Lab 1

1 Graphics Models and Libraries

A graphics display is a drawing area composed of an array of fine points called pixels. At the heart of a graphics system there is a magic pen, which can move at lightning speed to a specific pixel and draw the pixel with a specific color — a red, green, and blue (RGB) vector value. This pen can be controlled directly by hand through an input device (mouse or keyboard) like a simple paintbrush. In this case, we can draw whatever we imagine, but it takes a real artist to come up with a good painting. Computer graphics, however, is about using this pen automatically through programming.

A real or imaginary object is represented in a computer as a model and is displayed as an image. A model is an abstract description of the object’s shape (vertices) and attributes (colors), which can be used to find all the points and their colors on the object corresponding to the pixels in the drawing area. Given a model, the application program will control the pen through a graphics library to generate the corresponding image. An image is simply a 2D array of pixels.

A graphics library provides a set of graphics commands or functions. These commands can be bound in C, C++ , Java , or other programming languages on different platforms. Graphics commands can specify primitive 2D and 3D geometric models to be digitized and displayed. Here primitive means that only certain simple shapes (such as points, lines, and polygons) can be accepted by a graphics library. To draw a complex shape, we need an application program to assemble or construct it by displaying pieces of simple shapes (primitives). We have the magic pen that draws a pixel. If we can draw a pixel, we can draw a line, a polygon, a curve, a block, a building, an airplane, and so forth. A general application program can be included into a graphics library as a command to draw a complex shape. Because our pen is magically fast, we can draw a complex object, clear the drawing area, draw the object at a slightly different location or shape, and repeat the above processes — the object is now animated.

OpenGL is a graphics library that we will integrate with the Java programming language to introduce graphics theory, programming, and applications. When we introduce program examples, we will succinctly discuss Java-specific concepts and programming as well for C/C++ programmers.

2 OpenGL Programming in Java: JOGL

OpenGL is the most widely used graphics library (GL) or application programming interface (API), and is supported across all popular desktop and workstation platforms, ensuring wide application deployment. JOGL implements Java bindings for OpenGL. It provides hardware-supported 3D graphics to applications written in Java. It is part of a suite of open-source technologies initiated by the Game Technology Group at Sun Microsystems. JOGL provides full access to OpenGL functions and integrates with the AWT and Swing widget sets.

3_. Instructions for today_

Execute the sample Netbeans code provided.

Implement the code for drawing a line through the DDA algorithm

docsity.com

DDA Algorithm

DDA works by using the pixel coordinates computed last and the slope. From the

previous section you can easily compute how far to move over (dx) or how far to move

up (dy) on the screen to draw your next point on the line.

dy = m * dx

dx =dy/m

Given that you already know you want to move over (dx) or up (dy) a certain number of

units (for computers these units equate to pixels on the screen) you then plug these

values into one of the two equations along with the slope and solve.

The DDA algorithm can be then broken down into the following cases.

1. A line with positive slope and 0 <= m <= 1 then you can take dx = 1 and compute

successive y values using.

yk+1 = yk + m

Note: remember that because m is not necessarily an integer you must

round your result.

2. A line with positive slope and m > 1 then you calculate x instead of y and take dy = 1

and compute successive x values using

xk+1 = xk +1/m

The same applies here you need to round!

Both of these calculations can generalize to lines with negative slope so you can use

case 1 when |m| <= 1 and case 2 when |m| >= 1.

docsity.com