Computer Graphics. Making Pictures. Computer Graphics CSC470 1

Similar documents
Drawing Primitives. OpenGL basics

COMPUTER GRAPHICS LAB # 3

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

Assignment 1. Simple Graphics program using OpenGL

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

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

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

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

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

Computer Graphics (Basic OpenGL)

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

Programming using OpenGL: A first Introduction

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

Computer Graphics. OpenGL

Graphics Programming

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

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

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

Lectures OpenGL Introduction

Basic Graphics Programming

Announcements OpenGL. Computer Graphics. Spring CS4815

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

CS 4204 Computer Graphics

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

Programming with OpenGL Part 1: Background

Duc Nguyen CSE 420 Computer Graphics 10/10/2018 Homework 1

Lecture 2 CISC440/640 Spring Department of Computer and Information Science

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

Computer Graphics 1 Computer Graphics 1

Computer Graphics, Chapt 08

Introduction to Computer Graphics with OpenGL/GLUT

Lecture 3. Understanding of OPenGL programming

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

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

Lecture 3 Advanced Computer Graphics (CS & SE )

by modifying the glutinitwindowsize() function you can change the screen size to whatever you please.

Programming with OpenGL Part 3: Three Dimensions

Introduction to OpenGL Week 1

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

Computer Graphics Course 2005

Overview of Graphics Systems Hearn & Baker Chapter 2. Some slides are taken from Robert Thomsons notes.

Computer Graphics Anatomy of GUI. Computer Graphics CSC470 1

Computer Graphics (4731) Lecture 4: 2D Graphics Systems (Drawing Polylines, tiling, & Aspect Ratio)

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

COMP 371/4 Computer Graphics Week 1

CSC 8470 Computer Graphics. What is Computer Graphics?

Rendering. Part 1 An introduction to OpenGL

Draw the basic Geometry Objects. Hanyang University

Basic Graphics Programming

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

Lecture 4 of 41. Lab 1a: OpenGL Basics

11/1/13. Basic Graphics Programming. Teaching Assistant. What is OpenGL. Course Producer. Where is OpenGL used. Graphics library (API)

CSE4030 Introduction to Computer Graphics

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

CS 543 Lecture 1 (Part II): Intro to OpenGL and GLUT (Part I) Emmanuel Agu

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

Computer Graphics Primitive Attributes

VR-programming tools (procedural) More VRML later in this course! (declarative)

Precept 2 Aleksey Boyko February 18, 2011

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

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

Luiz Fernando Martha André Pereira

Introduction to OpenGL: Part 2

COS340A Assignment 1 I Pillemer Student# March 25 th 2007 p1/15

CS621 Lab 1 Name: Ihab Zbib

Computer Graphics Introduction to OpenGL

Lecture 2 2D transformations Introduction to OpenGL

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

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

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

RECITATION - 1. Ceng477 Fall

Bob s Concise Introduction to Doxygen

Computer Graphics: Line Drawing Algorithms

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

Andrew Yenalavitch Homework 1 CSE Fall 2014

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

Computer Graphics (CS 543) Lecture 1 (Part 2): Introduction to OpenGL/GLUT (Part 1)

OpenGL Introduction Computer Graphics and Visualization

Computer graphic -- Programming with OpenGL I

C++ is Fun Part 13 at Turbine/Warner Bros.! Russell Hanson

1.2 Basic Graphics Programming

UNIT 7 LIGHTING AND SHADING. 1. Explain phong lighting model. Indicate the advantages and disadvantages. (Jun2012) 10M

Graphics and Visualization

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

Computer Graphics (CS 543) Lecture 3b: Shader Setup & GLSL Introduction

Programming of Graphics

PART-I: Lab for MCS-051 (Advanced Internet Technologies)

Chapter 13 Selection and Feedback

3D computer graphics: geometric modeling of objects in the computer and rendering them

Computer Graphics. Downloaded from: LectureNotes 1 CSC-254

Computer Graphics. Bing-Yu Chen National Taiwan University

Computer Graphics. Chapter 3 Computer Graphics Software

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

Computer Graphics (CS 543) Lecture 2b: 2D Graphics Systems (Drawing Polylines, tiling, & Aspect Ratio)

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations

Computer graphics MN1

Display Lists in OpenGL

2D Drawing Primitives

Transcription:

Computer Graphics Making Pictures Computer Graphics CSC470 1

Getting Started Making Pictures Graphics display: Entire screen (a); windows system (b); [both have usual screen coordinates, with y-axis y down]; windows system [inverted coordinates] (c) Computer Graphics CSC470 2

Making Pictures OpenGL Inverted Windows glutinitwindowsize(640,480); void gluortho2d(gldouble left, glutinitwindowposition(100, 150); GLdouble right, glutcreatewindow( An OpenGL GLdouble Window"); bottom, GLdouble top) gluortho2d(0.0, 640.0, 480.0, 0.0); Computer Graphics CSC470 3

OpenGL Inverted Windows Computer Graphics CSC470 4

Making Pictures OpenGL Right-side Up Windows glutinitwindowsize(640,480); glutinitwindowposition(100, 150); glutcreatewindow( An OpenGL Window"); gluortho2d(0.0, 640.0, 0.0, 480.0); Computer Graphics CSC470 5

OpenGL Right-side Up Windows Computer Graphics CSC470 6

Making Pictures OpenGL Full Screen Mode glutinitwindowsize(640,480); glutinitwindowposition(100, 150); glutcreatewindow( An OpenGL Window"); glutfullscreen(); Computer Graphics CSC470 7

Making Pictures OpenGL Full Screen Windows (0,0) Window size = Screen Resolution (100,410) (640,480) Computer Graphics CSC470 8

Making Pictures OpenGL Full Screen Windows (0,0) Window size = Screen Resolution (100,410) (640,480) Computer Graphics CSC470 9

Basic System Drawing Commands setpixel(x,, y, color) Pixel at location (x,( y) ) gets color specified by color Other names: putpixel(), setpixel(), or drawpoint() line(x1, y1, x2, y2) Draws a line between (x1, y1) and (x2, y2) Other names: drawline() or Line(). Computer Graphics CSC470 10

Alternative Basic Drawing current position (cp( cp),, specifies where the system is drawing now. moveto(x,y) moves the pen invisibly to the location (x, y) and then updates the current position to this position. lineto(x,y) draws a straight line from the current position to (x, y) and then updates the cp to (x, y). Computer Graphics CSC470 11

Example: A Square moveto(4, 4); //move to starting corner lineto(-2, 4); lineto(-2, -2); lineto(4, -2); lineto(4, 4); //close the square Computer Graphics CSC470 12

A GL Program to Open a Window // appropriate #includes go here void main(int argc,, char** argv) { glutinit(&argc, argv); // initialize the toolkit glutinitdisplaymode(glut_single GLUT_RGB); // set the display mode glutinitwindowsize(640,480); // set window size glutinitwindowposition(100, 150); // set window upper left corner position on screen glutcreatewindow("my first attempt"); // open the screen window (Title: my first attempt) Computer Graphics CSC470 13

Open a Window cont d } // register the callback functions glutdisplayfunc(mydisplay); glutreshapefunc(myreshape); glutmousefunc(mymouse); glutkeyboardfunc(mykeyboard); myinit(); // additional initializations as necessary glutmainloop(); // go into a perpetual loop Computer Graphics CSC470 14

What the Code Does glutinit (&argc argc, argv) ) initializes Open-GL Toolkit glutinitdisplaymode (GLUT_SINGLE GLUT_RGB) allocates a single display buffer and uses colors to draw glutinitwindowsize (640, 480) makes the window 640 pixels wide by 480 pixels high Computer Graphics CSC470 15

What the Code Does cont d glutinitwindowposition (100, 150) puts upper left window corner at position 100 pixels from left edge and 150 pixels down from top edge glutcreatewindow ( my first attempt ) opens and displays the window with the title my first attempt Remaining functions register callbacks Computer Graphics CSC470 16

What the Code Does cont d The call-back functions you write are registered, and then the program enters an endless loop, waiting for events to occur. When an event occurs, GL calls the relevant handler function. Computer Graphics CSC470 17

Drawing Dots in OpenGL We start with a coordinate system based on the window just created: 0 to 679 in x and 0 to 479 in y. OpenGL drawing is based on vertices (corners). To draw an object in OpenGL, you pass it a list of vertices. The list starts with glbegin(arg); and ends with glend(); arg determines what is drawn. glend() sends drawing data down the OpenGL pipeline. Computer Graphics CSC470 18

Example glbegin (GL_POINTS); glvertex2i (100, 50); glvertex2i (100, 130); glvertex2i (150, 130); glend(); GL_POINTS is constant built-into into Open-GL (also GL_LINES, GL_POLYGON, ) Complete code to draw the 3 dots is in next slide Computer Graphics CSC470 19

Display for Dots Computer Graphics CSC470 20

Example of Construction glvertex2i ( ) takes integer values glvertex2d ( ) takes floating point values OpenGL has its own data types to make graphics device-independent independent Use these types instead of standard ones Computer Graphics CSC470 21

Open-GL Data Types suffix data type C/C++ type OpenGL type name b 8-bit integer signed char GLbyte s 16-bit bit integer Short GLshort i 32-bit integer int or long GLint, GLsizei f 32-bit float Float GLfloat, GLclampf d 64-bit float Double GLdouble,GLclampd ub us ui 8-bit unsigned number 16-bit unsigned number 32-bit unsigned number unsigned char unsigned short unsigned int or unsigned long GLubyte,GLboolean GLushort GLuint,Glenum,GLbitfield Computer Graphics CSC470 22

Colors in OpenGL OpenGL uses RGB color model The values of red, green, and blue are numbers from 0.0 to 1.0. Computer Graphics CSC470 23

Colors in OpenGL The instruction glcolor3f( float red,, float green,, float blue ) sets a color. Syntax of OpenGL instructions: FunctionName2i or FunctionName3f 2 or 3 means number of parameters: 2 or 3 i - integer values, f-f float values, d-double d double values. All the following instructions will give the same color - red: glcolor1f( 1.0 ); glcolor1d( 1.0 ); glcolor4i( 1, 0, 0, 0 );. Computer Graphics CSC470 24

Colors in OpenGL There is an optional fourth value in the color definition called the alpha value. Alpha values are used for displaying different effects, e.g., blending, transparency, lighting and shadows. OpenGL may interpolate different colors. Problem: Use the sample triangle program and assign different colors for each vertex. Describe the result. Computer Graphics CSC470 25

Setting Drawing Colors in GL glcolor3f(red, green, blue); // set drawing color glcolor3f(1.0, 0.0, 0.0); glcolor3f(0.0, 1.0, 0.0); glcolor3f(0.0, 0.0, 1.0); glcolor3f(0.0, 0.0, 0.0); glcolor3f(1.0, 1.0, 1.0); glcolor3f(1.0, 1.0, 0.0); glcolor3f(1.0, 0.0, 1.0); // red // green // blue // black // bright white // bright yellow // magenta Computer Graphics CSC470 26

Setting the Foreground Colour glcolor3f(r, G, B); glcolor4f(r, G, B, α); - colourexample.exe Computer Graphics CSC470 27

Setting Background Color in GL glclearcolor (red, green, blue, alpha); Sets background color. Alpha is degree of transparency; use 0.0 for now. glclear(gl_color_buffer_bit); clears window to background color Computer Graphics CSC470 28

Setting the Background Colour glclearcolour(r,, G, B, α); glclearcolour(1,0,0,0); glclearcolour(0,1,0,0); glclearcolour(0,0,1,0); Computer Graphics CSC470 29

Colors in OpenGL glbegin( ( GL_TRIANGLES ); // Begin a triangle glcolor3f( 1.0, 0.0, 0.0 ); // Red color glvertex3f( 0.25, 0.25, 0.0 ); glcolor3f( 0.0, 1.0, 0.0 ); // Green color glvertex3f( 0.75, 0.25, 0.0 ); glcolor3f( 0.0, 0.0, 1.0 ); // Blue color glvertex3f( 0.75, 0.75, 0.0 ); glend(); // End the triangle Computer Graphics CSC470 30

Setting Up a Coordinate System void myinit(void) { glmatrixmode(gl_projection); glloadidentity(); gluortho2d(0, 640.0, 0, 480.0); } // sets up coordinate system for window from (0,0) to (679, 479) Computer Graphics CSC470 31

Drawing Lines glbegin (GL_LINES); //draws one line glvertex2i (40, 100); // between 2 vertices glvertex2i (202, 96); glend (); glflush(); If more than two vertices are specified between glbegin(gl_lines) ) and glend() they are taken in pairs, and a separate line is drawn between each pair. Computer Graphics CSC470 32

Setting Line Parameters Polylines and Polygons: lists of vertices. Polygons are closed (right); polylines need not be closed (left). Computer Graphics CSC470 33

Polygons - object with border and interior Polygon can be simple, convex, and flat. Convex polygon: a polygon is convex if a line connecting any two points of the polygon lies entirely within the polygon. Computer Graphics CSC470 34

Rectangles A special type of polygon with four sides and with aligned with the coordinate axis is called an aligned rectangle. Computer Graphics CSC470 35

Aligned Rectangles glrecti(glint x1, GLint y1, GLint x2, GLint y2); (x1,y1) (x2,y2) Computer Graphics CSC470 36

Drawing rectangles void mydisplay(void) { glclear(gl_color_buffer_bit); glclearcolor(1.0,1.0,1.0,0.0); // white background glcolor3f(0.6,0.6,0.6); // bright gray glrecti(20,20,100,70); glcolor3f(0.2,0.2,0.2); // dark gray glrecti(70, 50, 150, 130); glflush(); } by the opposite corners by the center point, height and width by the upper left corner, width and aspect ratio Computer Graphics CSC470 37

Aligned Rectangles glrecti(glint x1, GLint y1, GLint x2, GLint y2); The rectangle will be drawn, filled with the current foreground colour. Computer Graphics CSC470 38

Aligned Rectangles Aspect Ratio The shape of a rectangle can be described as it s aspect ratio. The aspect ratio is calculated thus: AR = Width/Height Landscape 29.5/21.2 Portrait 21.2/29.5 Golden Rectangle ɸ = 1.61803399 Computer Graphics CSC470 39

OpenGL Primitives GL_POINTS GL_LINES GL_LINE_STRIP GL_POLYGON GL_LINE_LOOP GL_TRIANGLES GL_QUAD_STRIP GL_TRIANGLE_STRIP GL_TRIANGLE_FAN Computer Graphics CSC470 40

Primitives and attributes glbegin(gl_points); ; glend(); Points Lines Polylines House Computer Graphics CSC470 41

Graphics Primitives Points glbegin(gl_points); glvertex2i(100,50); glvertex2i(100,130); glvertex2i(150,130); glend(); Computer Graphics CSC470 42

Graphics Primitives Points void drawdot(glint x, GLint y) { glbegin(gl_points); glvertex2i(x,y); glend(); } Computer Graphics CSC470 43

Graphics Primitives Lines glbegin(gl_lines); glvertex2i(10,50); glvertex2i(80,20); glvertex2i(20,10); glvertex2i(10,45); glend(); Computer Graphics CSC470 44

Graphics Primitives Polylines glbegin(gl_line_strip); glvertex2i(20,10); glvertex2i(50,10); glvertex2i(20,80); glvertex2i(50,80); glend(); Computer Graphics CSC470 45

Polygon types Computer Graphics CSC470 46

Graphics Primitives Polygon glbegin(gl_line_loop); glvertex2i(20,10); glvertex2i(50,10); glvertex2i(20,80); glvertex2i(50,80); glend(); Computer Graphics CSC470 47

Remember to Flush To ensure graphics are output to the drawing window, you must follow the plotting process with: glflush(); Computer Graphics CSC470 48

Remember to Flush glbegin(gl_line_loop); glvertex2i(20,10); glvertex2i(50,10); glvertex2i(20,80); glvertex2i(50,80); glend(); glflush(); Computer Graphics CSC470 49

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 Computer Graphics CSC470 50

Attributes Attributes are part of the OpenGL state and determine the appearance of objects Color (points, lines, polygons) Size and width (points, lines) Stipple pattern (lines, polygons) Polygon mode Display as filled: solid color or stipple pattern Display edges Display vertices Computer Graphics CSC470 51