Rendering. A simple X program to illustrate rendering

Similar documents
Rendering. A simple X program to illustrate rendering

From Ver(ces to Fragments: Rasteriza(on

CPSC / Scan Conversion

1 Introduction to Graphics

CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines. Emmanuel Agu

OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives.

From Vertices to Fragments: Rasterization. Reading Assignment: Chapter 7. Special memory where pixel colors are stored.

Scan Conversion. Lines and Circles

Tópicos de Computação Gráfica Topics in Computer Graphics 10509: Doutoramento em Engenharia Informática. Chap. 2 Rasterization.

Rasterization: Geometric Primitives

CS 130. Scan Conversion. Raster Graphics

Computer Graphics. - Rasterization - Philipp Slusallek

Department of Computer Sciences Graphics Fall 2003 (Lecture 2) Pixels

Graphics System. Processor. Output Display. Input Devices. Frame Buffer. Memory. Array of pixels. Resolution: # of pixels Depth: # of bits/pixel

COMP371 COMPUTER GRAPHICS

Scan Converting Lines

EF432. Introduction to spagetti and meatballs

CSC Computer Graphics

CS Rasterization. Junqiao Zhao 赵君峤

Line Drawing. Foundations of Computer Graphics Torsten Möller

Chapter 8: Implementation- Clipping and Rasterization

Line Drawing Week 6, Lecture 9

Computer Graphics D Graphics Algorithms

Rasterization, or What is glbegin(gl_lines) really doing?

Output Primitives. Dr. S.M. Malaek. Assistant: M. Younesi

Line Drawing. Introduction to Computer Graphics Torsten Möller / Mike Phillips. Machiraju/Zhang/Möller

Scan Conversion. Drawing Lines Drawing Circles

CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE

Rasteriza2on and Clipping

Scan Converting Circles

Raster Displays and Scan Conversion. Computer Graphics, CSCD18 Fall 2008 Instructor: Leonid Sigal

Announcements. Midterms graded back at the end of class Help session on Assignment 3 for last ~20 minutes of class. Computer Graphics

Computer Graphics D Graphics Algorithms

EF432. Introduction to spagetti and meatballs

Rendering approaches. 1.image-oriented. 2.object-oriented. foreach pixel... 3D rendering pipeline. foreach object...

Raster Scan Displays. Framebuffer (Black and White)

Computer Graphics (CS 543) Lecture 10: Rasterization and Antialiasing

Topic 0. Introduction: What Is Computer Graphics? CSC 418/2504: Computer Graphics EF432. Today s Topics. What is Computer Graphics?

Chapter - 2: Geometry and Line Generations

Computer Graphics. Lecture 2. Doç. Dr. Mehmet Gokturk

0. Introduction: What is Computer Graphics? 1. Basics of scan conversion (line drawing) 2. Representing 2D curves

CS 543: Computer Graphics. Rasterization

Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling

UNIT -8 IMPLEMENTATION

Topic #1: Rasterization (Scan Conversion)

Rasterization. CS4620/5620: Lecture 12. Announcements. Turn in HW 1. PPA 1 out. Friday lecture. History of graphics PPA 1 in 4621.

Display Technologies: CRTs Raster Displays

Graphics (Output) Primitives. Chapters 3 & 4

Painter s HSR Algorithm

Output Primitives Lecture: 3. Lecture 3. Output Primitives. Assuming we have a raster display, a picture is completely specified by:

CS-184: Computer Graphics. Today

Computer Graphics, Lecture 2 October 31, Department of Information Technology. - Scientific Computing. Department of Information Technology

R asterisation. Part I: Simple Lines. Affine transformation. Transform Render. Rasterisation Line Rasterisation 2/16

CS-184: Computer Graphics. Today. 2D Scan Conversion. Tuesday, October 7, Drawing Lines Drawing Curves Filled Polygons Filling Algorithms

CS-184: Computer Graphics

An Improved Algorithm for Scan-converting a Line

Realtime 3D Computer Graphics Virtual Reality

CSCI 420 Computer Graphics Lecture 14. Rasterization. Scan Conversion Antialiasing [Angel Ch. 6] Jernej Barbic University of Southern California

Efficient Plotting Algorithm

Rasterization. Rasterization (scan conversion) Digital Differential Analyzer (DDA) Rasterizing a line. Digital Differential Analyzer (DDA)

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14

From 3D World to 2D Screen. Hendrik Speleers

(Refer Slide Time: 00:03:51)

2D Image Synthesis. 2D image synthesis. Raster graphics systems. Modeling transformation. Vectorization. u x u y 0. o x o y 1

Fall CSCI 420: Computer Graphics. 7.1 Rasterization. Hao Li.

Rasterization. CS 4620 Lecture Kavita Bala w/ prior instructor Steve Marschner. Cornell CS4620 Fall 2015 Lecture 16

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

Lecture 2 October 31, 2005

Lecture 2 March 24, 2004

UNIT 2 GRAPHIC PRIMITIVES

MODULE - 4. e-pg Pathshala

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Scan Conversion. CMP 477 Computer Graphics S. A. Arekete

CS488 2D Graphics. Luc RENAMBOT

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Computer Graphics

Computer Graphics Lecture 5

Rasterization. CS4620 Lecture 13

Output Primitives Lecture: 4. Lecture 4

Unit 2 Output Primitives and their Attributes

CSCI 4620/8626. Coordinate Reference Frames

Lecture 6 of 41. Scan Conversion 1 of 2: Midpoint Algorithm for Lines and Ellipses

Lecture 6 of 41. Scan Conversion 1 of 2: Midpoint Algorithm for Lines and Ellipses

CS 4300 Computer Graphics. Prof. Harriet Fell Fall 2012 Lecture 5 September 13, 2012

The Traditional Graphics Pipeline

A New Line Drawing Algorithm Based on Sample Rate Conversion

The graphics pipeline. Pipeline and Rasterization. Primitives. Pipeline

Line Drawing Algorithms

The Traditional Graphics Pipeline

The Traditional Graphics Pipeline

This library uses only GL functions but contains code for creating common objects and simplifying viewing.

Clipping and Scan Conversion

Overview of Computer Graphics

CS475m - Computer Graphics. Lecture 1 : Rasterization Basics

Computer Graphics. Chapter 4 Attributes of Graphics Primitives. Somsak Walairacht, Computer Engineering, KMITL 1

Surface shading: lights and rasterization. Computer Graphics CSE 167 Lecture 6

Points and lines. x x 1 + y 1. y = mx + b

1 Some easy lines (2, 17) (10, 17) (18, 2) (18, 14) (1, 5) (8, 12) Check with a ruler. Are your lines straight?

Computer Graphics. Attributes of Graphics Primitives. Somsak Walairacht, Computer Engineering, KMITL 1

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

Transcription:

Rendering A simple X program to illustrate rendering The programs in this directory provide a simple x based application for us to develop some graphics routines. Please notice the following: All points are integers. The line drawing algorithm is very simple and has some definite flaws. 1/18/2000 CS 4/57101 Lecture 1 1

A simple X program 1/18/2000 CS 4/57101 Lecture 1 2

A simple X program 1/18/2000 CS 4/57101 Lecture 1 3

Syntax Point point x y where x and y are integers Line line x1 y1 x2 y2 where x1, x2, y1 and y2 are integers 1/18/2000 CS 4/57101 Lecture 1 4

Point and line drawing routines These are the primitives in the simple package!! Point drawing routines point.c point.h Line drawing routines line.c line.h 1/18/2000 CS 4/57101 Lecture 1 5

Other routines The main routine main.c Include file with the definitions of the data structures mygraph.h The routines to Access X functions directly. Xroutines.c Xroutines.h 1/18/2000 CS 4/57101 Lecture 1 6

Line Drawing and Scan Conversion A preliminary step to drawing lines is choosing a suitable representation for them. There are three possible choices which are potentially useful. Explicit: y = f(x) y = m (x - x0) + y0 where m = dy/dx Parametric: x = f(t), y = f(t) x = x0 + t(x1 - x0), t in [0,1] y = y0 + t(y1 - y0) 1/18/2000 CS 4/57101 Lecture 1 7

Point and line drawing routines (ctd) Implicit: f(x,y) = 0 F(x,y) = (x-x0)dy - (y-y0)dx if F(x,y) = 0 then (x,y) is on line F(x,y) > 0 then (x,y) is below line F(x,y) < 0 then (x,y) is above line 1/18/2000 CS 4/57101 Lecture 1 8

Rasterization or Scan Conversion Drawing lines on a raster grid implicitly involves approximation. The general process : rasterization or scan-conversion. What is the best way to draw a line from the pixel (x1,y1) to (x2,y2)? Such a line should ideally have the following properties. straight pass through endpoints smooth independent of endpoint order uniform brightness brightness independent of slope efficient 1/18/2000 CS 4/57101 Lecture 1 9

Line Drawing - Algorithm 1 A Straightforward Implementation Drawline(x1,y1,x2,y2) int x1,y1,x2,y2; { float y; int x; for (x=x1; x<=x2; x++) { y = y1 + (x-x1)*(y2-y1)/(x2-x1) SetPixel(x, Round(y) ); } } 1/18/2000 CS 4/57101 Lecture 1 10

Line Drawing - Algorithm 2 A Better Implementation DrawLine(x1,y1,x2,y2) int x1,y1,x2,y2; { float m,y; int dx,dy,x; dx = x2 - x1; dy = y2 - y1; m = dy/dx; y = y1 + 0.5; for (x=x1; x<=x2; x++) { SetPixel(x, Floor(y) ); y = y + m; } } 1/18/2000 CS 4/57101 Lecture 1 11

Line Drawing Algorithm Comparison Advantages over Algorithm 1 eliminates multiplication improves speed Disadvantages round-off error builds up get pixel drift rounding and floating point arithmetic still time consuming works well only for m < 1 need to loop in y for m > 1 need to handle special cases 1/18/2000 CS 4/57101 Lecture 1 12

Point and line drawing routines Implicit: f(x,y) = 0 F(x,y) = (x-x0)dy - (y-y0)dx if F(x,y) = 0 then (x,y) is on line F(x,y) > 0 then (x,y) is below line F(x,y) < 0 then (x,y) is above line 1/18/2000 CS 4/57101 Lecture 1 13

Line Drawing - Midpoint Algorithm The Midpoint or Bresenham s Algorithm The midpoint algorithm is even better than the above algorithm in that it uses only integer calculations. It treats line drawing as a sequence of decisions. For each pixel that is drawn the next pixel will be either E or NE, as shown below. 1/18/2000 CS 4/57101 Lecture 1 14

Midpoint Algorithm The midpoint algorithm makes use of the the implicit definition of the line, F(x,y) = 0. The N/NE decisions are made as follows. d = F(x p + 1, y p + 0.5) if d < 0 line below midpoint choose E if d > 0 line above midpoint choose NE if E is chosen d new = F(x p + 2, y p + 0.5) d new -d old = F(x p + 2, y p + 0.5) - F(x p + 1, y p + 0.5) d = d new -d old = dy 1/18/2000 CS 4/57101 Lecture 1 15

Midpoint Algorithm If NE is chosen d new = F(x p + 2, y p + 1.5) d = dy - dx Initialization d start = F(x 0 + 1, y 0 + 0.5) = (x 0 + 1 - x 0 ) dy - (y 0 + 0.5 - y 0 )dx = dy - dx/2 Integer only algorithm F (x,y) = 2 F(x,y) ; d = 2d d start = 2dy - dx d = 2 d 1/18/2000 CS 4/57101 Lecture 1 16

Midpoint Algorithm for x1 < x2 and slope <= 1 drawline(x1, y1, x2, y2, colour) int x1, y1, x2, y2, colour; { int dx, dy, d, ince, incne, x, y; dx = x2 - x1; dy = y2 - y1; d = 2*dy - dx; ince = 2*dy; incne = 2*(dy - dx); y = y1; for (x=x1; x<=x2; x++) { setpixel(x, y, colour); if (d>0) { d = d + incne; y = y + 1; } else { d = d + ince; } } } 1/18/2000 CS 4/57101 Lecture 1 17

General Bresenham s Algorithm To generalize to lines with arbitrary slope consider symmetry between various octants and quadrants for m > 1, interchange roles of x and y, that is step in y direction, and decide whether x value is above or below line if m > 1, and right endpoint is the first point, both x and y decrease. To ensure uniqueness, independent of direction, always choose upper (or lower) point if the line goes through the mid-point handle special cases without invoking algorithm: horizontal, vertical and diagonal lines 1/18/2000 CS 4/57101 Lecture 1 18

Additional Issues End-point order cannot just interchange end-points does not work when we use line styles since we need the pattern to go the same way on all segments of a polygon later we must deal with issue of clipping varying the intensity of a line with the slope consider horizontal line and diagonal line both have same number of pixels diagonal 2 times horizontal line in length intensity per unit length less for diagonal 1/18/2000 CS 4/57101 Lecture 1 19