OpenGL Primitives. Examples: Lines. Points. Polylines. void drawdot(glint x, GLint y) { glbegin(gl_points); glvertex2i(x,y); glend(); }

Similar documents
void drawdot(glint x, GLint y) { glbegin(gl_points); glvertex2i(x,y); glend();

Computer Graphics Anatomy of GUI. Computer Graphics CSC470 1

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

Computer Graphics 1 Computer Graphics 1

Geometry Primitives. Computer Science Department University of Malta. Sandro Spina Computer Graphics and Simulation Group. CGSG Geometry Primitives

Windows and Viewports. Windows and Viewports. Windows and Viewports. Windows and Viewports. CSC 706 Computer Graphics

2D Drawing Primitives

Computer graphic -- Programming with OpenGL I

Assignment 1. Simple Graphics program using OpenGL

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall

CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II. Emmanuel Agu

CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Lecture 3 Advanced Computer Graphics (CS & SE )

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

CS 4204 Computer Graphics

Programming using OpenGL: A first Introduction

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

Programming of Graphics

Drawing Primitives. OpenGL basics

三維繪圖程式設計 3D Graphics Programming Design 第三章三維繪圖狀態設定和幾何元件繪製嘉大資工系盧天麒

How shapes are represented in 3D Graphics. Aims and objectives By the end of the lecture you will be able to describe

CSE 167: Introduction to Computer Graphics Lecture #5: Visibility, OpenGL

Scan Conversion of Polygons. Dr. Scott Schaefer

Graphics Programming

6. Make use of glviewport() to display two sine curves on the same screen, one on the

CSC 8470 Computer Graphics. What is Computer Graphics?

C O M P U T E R G R A P H I C S. Computer Graphics. Three-Dimensional Graphics I. Guoying Zhao 1 / 52

Announcement. Homework 1 has been posted in dropbox and course website. Due: 1:15 pm, Monday, September 12

Teacher Assistant : Tamir Grossinger Reception hours: by - Building 37 / office -102 Assignments: 4 programing using

OpenGL. Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University

Computer Graphics. OpenGL

Time: 3 hours Max. Marks: 80. Note: Answer FIVE full questions, choosing one full question from each module.

COMPUTER GRAPHICS LAB # 3

CSCI 2212: Intermediate Programming / C Chapter 15

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40)

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL

Introduction to OpenGL. CSCI 4229/5229 Computer Graphics Fall 2012

Introduction to Computer Graphics with OpenGL/GLUT

Computer Graphics Primitive Attributes

Graphics Programming. August 31, Programming of the Sierpinski gasket. Programming with OpenGL and C/C++

Building Models. Prof. George Wolberg Dept. of Computer Science City College of New York

Graphics and Visualization

Introduction to OpenGL Week 1

Objectives. Image Formation Revisited. Physical Approaches. The Programmer s Interface. Practical Approach. Introduction to OpenGL Week 1

Computer Graphics (CS 4731) OpenGL/GLUT(Part 1)

2. OpenGL -I. 2.1 What is OpenGL? Things OpenGL can do: -23-

Luiz Fernando Martha André Pereira

Computer Graphics Introduction to OpenGL

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

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

CS559: Computer Graphics. Lecture 12: OpenGL Li Zhang Spring 2008

Cameras (and eye) Ideal Pinhole. Real Pinhole. Real + lens. Depth of field

CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013

Computer Graphics (Basic OpenGL)

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program

Graphics Programming. 1. The Sierpinski Gasket. Chapter 2. Introduction:

CS 432 Interactive Computer Graphics

Rendering. Part 1 An introduction to OpenGL

Programming with OpenGL Part 1: Background

Polygonal Meshes: Representing 3D Objects

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4620/8626 Computer Graphics Spring 2014 Homework Set 1 Suggested Answers

CSCI 4620/8626. Primitives and Attributes

2.1 Transforming Linear Functions

Image Processing. Geometry Processing. Reading: (Not really covered in our text. See Sects 18.1, 18.2.) Overview: Display

Computer Graphics. Chapter 3 Computer Graphics Software

Andrew Yenalavitch Homework 1 CSE Fall 2014

Lecture 4 of 41. Lab 1a: OpenGL Basics

Screen Space & World Space

Filled Area Primitives. CEng 477 Introduction to Computer Graphics METU, 2007

CSE528 Computer Graphics: Theory, Algorithms, and Applications

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

CSCI 4620/8626. Coordinate Reference Frames

CS621 Lab 1 Name: Ihab Zbib

Three Main Themes of Computer Graphics

RECITATION - 1. Ceng477 Fall

Chapter 3: Graphics Output Primitives. OpenGL Line Functions. OpenGL Point Functions. Line Drawing Algorithms

Draw the basic Geometry Objects. Hanyang University

Lecture 2 2D transformations Introduction to OpenGL

2. EXERCISE SHEET, RETURN DATE MAY 7/8TH 2015, INDIVIDUALLY. to the compiler options. I also suggest you to use the options

CSE 167: Introduction to Computer Graphics Lecture #5: Illumination Model

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

OpenGL Introduction Computer Graphics and Visualization

Geometry Shaders. And how to use them

Fundamentals of Computer Graphics. Lecture 3 Generate a simple shape using OpenGL. Yong-Jin Liu

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

COMP 371/4 Computer Graphics Week 1

Meshing and Geometry

2D Graphics Primitives II. Additional issues in scan converting lines. 1)Endpoint order. Want algorithms to draw the same pixels for each line

1 Introduction to Graphics

CSCI 4620/8626. Computer Graphics Attributes of Graphics Primitives (Chapter 5)

Basic Graphics Programming

OPENGL AND GLSL. Computer Graphics

Computer Graphics. Anders Hast. måndag 25 mars 13

Graphing with a Graphing Calculator

Computer Science 336 Fall 2017 Homework 2

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

Input/Output Machines

to OpenGL Introduction Pipeline Graphics pipeline OpenGL pipeline OpenGL syntax Modeling Arrays Conclusion 1 Introduction Introduction to OpenGL

Graphics Hardware and OpenGL

Transcription:

CSC 706 Computer Graphics Primitives, Stippling, Fitting In Examples: OpenGL Primitives GL_POINTS GL_LINES LINES GL _ LINE _ STRIP GL_POLYGON GL_LINE_LOOP GL_TRIANGLES GL_QUAD_STRIP GL_TRIANGLE_STRIP GL_TRIANGLE_FAN Graphics Primitives Graphics Primitives cont d Points Lines void drawdot(glint x, GLint y) { glbegin(gl_points); glvertex2i(x,y); } glbegin(gl_lines); glvertex2i(10,50); glvertex2i(80,20); glvertex2i(10,45); Graphics Primitives cont d Polygon types Polylines glvertex2i(50,10); glvertex2i(20,80); glvertex2i(50,80); 1

Polygon Graphics Primitives cont d glbegin(gl_line_loop); glvertex2i(50,10); glvertex2i(20,80); glvertex2i(50,80); Remember to Flush To ensure graphics are output to the drawing window, you must follow the plotting process with: Remember to Flush glbegin(gl_line_loop); glvertex2i(50,10); glvertex2i(20,80); glvertex2i(50,80); Polygon Issues OpenGL will only display polygons correctly that are -Simple: edges cannot cross - Convex: All points on line segment between two points in a polygon are also in the polygon - Flat: all vertices are in the same plane User program can check if above true - OpenGL will produce output if these conditions are violated but it may not be what is desired Triangles satisfy all conditions nonsimple polygon nonconvex polygon Stippling Stippling means to add a pattern to a simple line or the filling of a polygon. OpenGL allows stippling to be performed using bit patterns. Turn stippling on with: glenable(gl_line_stipple); glenable(gl_poly_stipple); Turn off with: gldisable(gl_line_stipple); gldisable(gl_poly_stipple); Line Stippling Defining a line stippling pattern: gllinestipple(glint factor, GLushort pattern); The pattern is a 16 bit sequence of 1s and 0s e.g. 1110111011101110 The factor is a bit multiplier for the pattern (it enlarges it) e.g. factor = 2 turns the above pattern into: 11111100111111001111110011111100 The pattern can be expressed in hexadecimal notation e.g. 0xEECC = 1110111011001100 e.g. gllinestipple(2, 0x7733); 2

Stippled Lines cont d To make stippled (dotted or dashed) lines, you use the command gllinestipple( ) to define the stipple pattern; Then you enable line stippling with glenable( ): gllinestipple(1, 0x3F07); glenable(gl_line_stipple); Line stippling is disabled by passing argument GL_LINE_STIPPLE to gldisable( ). gldisable(gl_line_stipple); Wait a minute.. How do I convert binary to hexadecimal? Hexadecimal character equivalents to 4 bit binary expressions 2. Split the binary into groups of four digits and assign hex values 0100 0010 = 42 1110 1001 = E9 0001 1100 0011 = 1C3 3. Then put 0x in front of the number in your code, e.g. 0xE9 Line Stippling Example gllinestipple(1, 0x3F07); Lets see it in action glenable(gl_line_stipple); gllinestipple(1, 0x7733); glvertex2i(10,10); glvertex2i(600,450); gllinestipple(2, 0xFF00); LINE glvertex2i(10,30); glvertex2i(600,470); gllinestipple(5, 0xFF00); glvertex2i(130,0); glvertex2i(600,430); gldisable(gl_line_stipple); The above example and the pattern 0x3F07 (which translates to 0011111100000111 in binary), a line would be drawn with 3 pixels on, then 5 off, 6 on, and 2 off. (If this seems backward, remember that the low-order order bits are used first.) If factor had been 2, the pattern would have been elongated: 6 pixels on, 10 off, 12 on, and 4 off. Figure 4.1 shows lines drawn with different patterns and repeat factors. If you don't enable line stippling, drawing proceeds as if pattern were 0xFFFF and factor 1. (Use gldisable() with GL_LINE_STIPPLE to disable stippling.) Note that stippling can be used in combination with wide lines to produce wide stippled lines. Fig. 4.1: Stippled Lines Polygon Stippling Defining a polygon stippling pattern: glpolygonstipple(glubyte mask); The pattern is a 128 byte array of 1s and 0s (32 bits across and 32 bits down) e.g. GLubyte mask[ ] = {0xff, 0xfe, 0x34,..}; The pattern is tiled inside the polygon. e.g. glpolygonstipple(mask); Polygon stippling is enabled and disabled by using glenable( ) and gldisable( ) with GL_POLYGON_STIPPLE as an argument. Polygon Stippling The argument mask is a pointer to a 32 x 32 bitmap that's interpreted as a mask of 0s and 1s. Where a 1 appears, the corresponding pixel in the polygon is drawn, and where a 0 appears, nothing is drawn. Figure 4.2 shows how a stipple pattern is constructed from the characters in mask. 3

Polygon Stippling cont d Example 2 - Polygon Stippling Example 2 - output /* draw one solid, unstippled rectangle, */ /* then two stippled rectangles */ glrectf (25.0, 25.0, 125.0, 125.0); glenable (GL_POLYGON_STIPPLE); glpolygonstipple (fly); glrectf (125.0, 25.0, 225.0, 125.0); glpolygonstipple (fire); glrectf (225.0, 10.0, 400.0, 325.0); gldisable (GL_POLYGON_STIPPLE); Polygon Stippling Lets see it in action glenable(gl_polygon_stipple); GLubyte mask[] = {0x31, 0xfe, 0x34, 0x12, 0xff, 0xfc, 0x00, 0x12, 0xaa, 0xfe, 0x00, 0x12, 0xaa, 0xfe, 0x00, 0x12, 0xfc, 0xfe, 0x00, 0x12, 0xff, 0xfe, 0x00, 0x12, }; glpolygonstipple(mask); glbegin(gl_polygon); glvertex2i(10,10); glvertex2i(600,450); glvertex2i(45,300); glvertex2i(240,460); gldisable(gl_polygon_stipple); Sometimes you may want to print out a plot of some data when the data ranges are unknown. However, you want them to appear in the window presented in a visually pleasing manner. e x E.g. Let s plot cos( 2πx) Plotted with screen coordinates of 640 x 480 we will get: A data plot is no good if we can t see it!! 4

How do we MAGNIFY the data? Stretch out X Stretch out Y Simple Dot Plots Draw a function for values of x between 0 and 4? Steps: sample it at a collection of equispaced x- values; plot a dot at each coordinate pair (xi, f(xi)); choose some suitable increment, say 0.005, between consecutive x-values. Simple Dot Plots cont d glbegin(gl_points); for(gldouble x = 0; x < 4.0 ; x += 0.005) glvertex2d(x, f(x)); Problems: The picture produced will be impossibly tiny because values of x between 0 and 4 map to the first four pixels at the bottom left of the screen window. Further, the negative values of f(.) will lie below the window and will not be seen at all. We therefore need to scale and position the values to be plotted so they cover the screen window area appropriately. The X coordinates of the window range over 640 values (from 0 to 639). The X values for the data range from 0 to 4. We need to modify the data values so that data point 0 maps to window coordinate 0 and data point 4 maps to window coordinate 640. In essence we want 4 to be plotted at 640. 4 * A = 640; A = 160;.. or for all cases A = SCREENWIDTH/x max Therefore, x = x * A. if x ranges from 0.. x max If x ranges from say 1 to 4 then we will want to stretch a range of 3 out instead of 4, therefore: A = SCREENWIDTH/(x max x min ) The same applies for the y coordinates: C = SCREENHEIGHT/(y max -y min ) 5

Dot Plots: scaling and shifting Scaling x: Fitting In x = Ax + B and y = Cy + D A = SCREENWIDTH/(xmax-xmin) B = -xmin*a C = SCREENHEIGHT/(ymax-ymin) D = ymin *C Scaling and shifting y: A and C are scalars B and D are translators Moving it around Setting Values for A, B, C and D The conversions from x to sx,, and from y to sy,, have the form: sx = A * x + B sy = C * y + D where Example void mydisplay(void) { for(glfloat x = -4.0; x < 4.0; x += 0.1) { GLfloat y = sin(3.14159 * x) / (3.14159 * x); glvertex2f(x, y); } } 6