Friday, 29 April 2011

Computer Graphics and Geometric Transformations

2D Transformations
2D computer graphics is the computer-based generation of digital images—mostly from two-dimensional models.There are three types of transformations that are essential in computer graphics

1-Translation
Moving an object to a new location by adding to objects x and y co-ordinates.
2-Scaling
Changing the size of the object.This can be uniform where both dimensions are re-sized by same factor or non-uniform.
3-Rotation
Object is rotated around the origin by specified angle.

Homogeneous Transformations
In order to represent a translation as a matrix operation we use 3 x 3 matrices and pad our points to become 1 x 3 matrices.

Computer Graphics and Geometric Transformations

Wednesday, 27 April 2011

A program (Objects, Lights, Camera)






Lighting

  1. Direction light source
  2. Position light source
  3. glLightfv( Light#, Attribute, …)
  4. GLfloat position[] = {10, 10, 10, W} glLightfv(GL_LIGHT0, GL_POSITION, position) If (W) is zero the position is treated as a direction (a 1x3 vector); otherwise, it is treated as a position (a 1x4 vector)
  5. glEnable(GL_LIGTHING)
  6. glEnable(GL_LIGHT0)

Drawing in 3D

 Depth buffer
   Allows scene to remove hidden surfaces. Use glEnable(GL_DEPTH_TEST) to enable it.
   1-glPolygonMode( Face, Mode )
       Face: GL_FRONT, GL_BACK, GL_FRONT_AND_BACK
      Mode: GL_LINE, GL_POINT, GL_FILL
  2-glCullFace( Mode )
      Mode: GL_FRONT, GL_BACK, GL_FRONT_AND_BACK
  3-glFrontFace( Vertex_Ordering )
      Vertex Ordering: GL_CW or GL_CCW

OpenGL States

On/off (e.g., depth buffer test)
  1. glEnable( GLenum )
  2. glDisable( GLenum )
  3. Examples:
  4. glEnable(GL_DEPTH_TEST);
  5. glDisable(GL_LIGHTING);
Mode States
  1. Once the mode is set the effect stays until reset
     Examples:
    glShadeModel(GL_FLAT) or glShadeModel(GL_SMOOTH)
    glLightModel(…) etc.

OpenGL Primitives

Drawing two lines
glBegin(GL_LINES);
    glVertex3f(_,_,_); // start point of line 1
    glVertex3f(_,_,_); // end point of line 1
    glVertex3f(_,_,_); // start point of line 2
    glVertex3f(_,_,_); // end point of line 2
glEnd();
We can replace GL_LINES with GL_POINTS, GL_LINELOOP, GL_POLYGON etc.

OpenGL Syntax

All functions have the form: gl*
1-glVertex3f() – 3 means that this function take three arguments, and f means that the type of those arguments is float.
2-glVertex2i() – 2 means that this function take two arguments, and i means that the type of those arguments is integer.
All variable types have the form: GL*
1-In OpenGL program it is better to use OpenGL variable types (portability)
2-GLfloat instead of float
3-Glint instead of int

OpenGL Order of Operations

Construct shapes 
1-Vertices
2-Edges
3-Polygons
Use OpenGL to:
1-Arrange shape in 3D (using transformations)
2-Select your vantage point (and perhaps lights)
3-Calculate color and texture properties of each object
4-Convert shapes into pixels on screen

Overview of an OpenGL Program

Main
1-Open window and configure frame buffer (using GLUT for example).
2-Initialize GL states and display (Double buffer, color mode, etc.).
Loop
1-Check for events
    a)if window event (resize, unhide, maximize etc.)
    b)modify the viewport and Redraw
    c)else if input event (keyboard and mouse etc.)
    d)handle the event (such as move the camera or change the state) and usually draw the scene
Redraw
1-Clear the screen (and buffers e.g., z-buffer)
2-Change states (if desired)
3-Render
4-Swap buffers (if double buffer)

OpenGL

A high-performance, window-system independent, software interface to graphics hardware.
OpenGL














GLUT (Provides and easy access to the underlying windowing system – creating windows and looking for mouse and keyboard events etc.)
GLU (Provides helper routines built on top of OpenGL rendering capabilities)

Sutherland-Hodgman Polygon Clipping

Sutherland-Hodgman Polygon Clipping

Sutherland-Hodgman Polygon Clipping



1-The Sutherland-Hodgman polygon clipping algorithm clips polygons against convex clipping windows.
2-It does so by clipping the subject polygon against each clip edge producing intermediate subject polygons.
3-The Sutherland-Hodgman may produce connecting lines that were not in the original polygon. When the subject polygon is concave (not convex) these connecting lines may be undesirable artifacts.

Polygon Clipping

Polygon clipping differs from line clipping in several respects:
1-The input to the clipper is a polygon, which for simplicity we will view as a list of n >= 3 vertices (v0; v1; : : : ; vn-1).
2-The output from the clipper is one or more polygons
3-The clipping process may generate vertices that do not lie on any of the edges of the original polygon.
4-Complex polygons (that is, non-convex) may lead to strange artifacts.

2D Clipping

Liang-Barsky 2D Clipping
Liang-Barsky 2D Clipping

Cohen Sutherland 2D Clipping


Cohen Sutherland 2D Clipping
Cohen Sutherland 2D Clipping

2D Raster Algorithms

1-DDA Algorithm
The digital differential analyzer (DDA) samples the line at unit intervals in one coordinate corresponding integer values nearest the line path of the other coordinate.
Major deficiency in the above approach :
   1-Uses floats
   2-Has rounding operations

2-Bresenham’s Line drawing Algo
An accurate, efficient raster line drawing algorithm  developed by Bresenham, scan converts lines using only incremental integer calculations that can be adapted to display circles and other curves.

Display Primitives | Computer Graphics

Computer Graphics Display Primitives

1- Graphics (modeling & rendering) primitives
2- Points, lines, polygons
3- Various line-drawing algorithms
4- DDA and Mid-point Line Drawing Algorithms
5- Circles drawing
6- Mathematical concepts
      a)line equations
      b)parametric representation, implicit
7- Functions, vectors and matrices

Tuesday, 26 April 2011

Computer Graphics Design

Computer Graphics Design

Mechanism for video display
1-CRT principle and structure
2-Frame buffer
3-Dot size, resolution
4-Refresh rate
5-Shadow masking in colored CRTs
Logic structure for other display
1-LCD
2-Plasma display
Conceptual Models for CG
1-Application Model
2-Application Program
3-Graphics System

Computer Graphics Design







I/O Devices
1-Printers and Plotters

Key Components of a Computer Graphics Design System

1-Video controller
2-Display processor

Components of Computer Graphics and Design

Components of Computer Graphics and Design

Modeling:
Defining objects in terms of primitives, coordinates and characteristics.
Storing:
Storing scenes and images in memory and on disk.
Manipulating:
Changing the shape, position and characteristics of objects.
Rendering:
Applying physically based procedures to generate (photo-realistic) images from scenes (using lighting and shading).
Viewing:
Displaying images from various viewpoints on various devices.

Computer Graphics and Design

Computer Graphics and Design

“A human oriented system that uses the capabilities of a computer to create, transform and display pictorial and symbolic data”.

Why study Computer Graphics?

1-Core component of every computer system.
2-Essential part of computer science curriculum.
3-Plays an important role in every day life applications.

Computer Graphics and Design











Broad range of applications 
1-CAD
2-Educations and Trainings
3-Graphical Representations
4-Entertainment
5-Visualization
6-Image processing
7-Medical