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

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

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

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

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

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

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

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

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

COMPUTER GRAPHICS LAB # 3

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

Drawing Primitives. OpenGL basics

Assignment 1. Simple Graphics program using OpenGL

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

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

CS 4204 Computer Graphics

Programming using OpenGL: A first Introduction

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

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

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

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

Lecture 2 2D transformations Introduction to OpenGL

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

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

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

Introduction to Computer Graphics with OpenGL/GLUT

Computer Graphics. Bing-Yu Chen National Taiwan University

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

Computer Graphics 1 Computer Graphics 1

CS 432 Interactive Computer Graphics

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

Graphics Programming

Computer Graphics (Basic OpenGL)

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

API Background. Prof. George Wolberg Dept. of Computer Science City College of New York

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

Computer Graphics. OpenGL

Programming with OpenGL Part 1: Background

An Overview GLUT GLSL GLEW

Lecture 3 Advanced Computer Graphics (CS & SE )

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

Rendering. Part 1 An introduction to OpenGL

Lecture 4 of 41. Lab 1a: OpenGL Basics

Computer Graphics CS 543 Lecture 4 (Part 2) Building 3D Models (Part 2)

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

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

Introduction to OpenGL Week 1

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

RECITATION - 1. Ceng477 Fall

Exercise 1 Introduction to OpenGL

Computer Graphics Anatomy of GUI. Computer Graphics CSC470 1

CS Computer Graphics: Intro to OpenGL

CS Computer Graphics: Intro to OpenGL

COMP 371/4 Computer Graphics Week 1

CSC 8470 Computer Graphics. What is Computer Graphics?

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

Lecture 3. Understanding of OPenGL programming

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

Computer Graphics, Chapt 08

Basic Graphics Programming

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

Draw the basic Geometry Objects. Hanyang University

Programming of Graphics

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

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

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

GLUT. What is OpenGL? Introduction to OpenGL and GLUT

CSE4030 Introduction to Computer Graphics

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

Lecture 3. Programming with OpenGL GLUT + GLEW. CS 354 Computer Graphics Sunday, January 20, 13

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

OpenGL and GLUT. COMP413 Computer Graphics. School of Computer Sci. & Eng. Kyungpook National University, Korea. Spring Semester, 2016

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

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

2/3/16. Interaction. Triangles (Clarification) Choice of Programming Language. Buffer Objects. The CPU-GPU bus. CSCI 420 Computer Graphics Lecture 3

Programming with OpenGL Part 3: Three Dimensions

Computer Graphics Course 2005

CS 432 Interactive Computer Graphics

Interaction. CSCI 420 Computer Graphics Lecture 3

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

2 Transformations and Homogeneous Coordinates

Computer Graphics. Downloaded from: LectureNotes 1 CSC-254

Programming with OpenGL Part 1: Background

Introduction to OpenGL: Part 2

Using OpenGL with CUDA

Announcements OpenGL. Computer Graphics. Spring CS4815

Early History of APIs. PHIGS and X. SGI and GL. Programming with OpenGL Part 1: Background. Objectives

Computer Graphics (CS 543) Lecture 4a: Linear Algebra for Graphics (Points, Scalars, Vectors)

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

Precept 2 Aleksey Boyko February 18, 2011

OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders

Computer Graphics CS 543 Lecture 5 (Part 2) Implementing Transformations

How OpenGL Works. Retained Mode. Immediate Mode. Introduction To OpenGL

Introduction to OpenGL

Lectures OpenGL Introduction

Bob s Concise Introduction to Doxygen

Computer Graphics: Line Drawing Algorithms

Interaction. CSCI 480 Computer Graphics Lecture 3

Introduction to OpenGL

Transcription:

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

Recall: OpenGL Skeleton void main(int argc, char** argv){ // First initialize toolkit, set display mode and create window glutinit(&argc, argv); // initialize toolkit glutinitdisplaymode(glut_single GLUT_RGB); glutinitwindowsize(640, 480); glutinitwindowposition(100, 150); glutcreatewindow( my first attempt ); glewinit( ); // now register callback functions glutdisplayfunc(mydisplay); glutreshapefunc(myreshape); p glutmousefunc(mymouse); glutkeyboardfunc(mykeyboard); 100 150 my first attempt } myinit( ); glutmainloop( ); 480 640

Old Way: OpenGL Drawing Drawing done in display function Display function called once when program starts Recall: First register callback in main( ) function glutdisplayfunc( mydisplay ); Then, implement mydisplay function void mydisplay( void ) { // put drawing commands here }

Old way: Drawing Primitives Drawpoints points, lines, polylines, polygons Primitives specified using glbegin, glend format: glbegin(primtype) pe) // define your primitives here glend( ) primtype: GL_ POINTS, GL_ LINES, GL_ POLYGON.

Old way: Drawing Example Example: draw three dots. How? Specify vertices Vertices connected in manner determined by primtype Immediate mode Generate points, render them (points not stored) void mydisplay( void ) {.. Forces drawing to complete glbegin(gl_points) glvertex2i(100,50); glvertex2i(100,130); glvertex2i(150, 130); glflush( ); glend( ) x primtype y

Immediate Mode Graphics Geometry specified by vertices Locations in space( 2 or 3 dimensional) Points, lines, circles, polygons, curves, surfaces Immediate mode Each time a vertex is specified in application, its location is sent to the GPU Old style uses glvertex Creates bottleneck between CPU and GPU RemovedfromOpenGL 3.1

Better Way of Drawing: Retained Mode Graphics 1. Generate points 2. Store vertices into an array 3. Draw points from array using gldrawarray 4. First declare types for points and vectors Useful to declare types point3 for <xy> <x,y> locations, vec3 for <xyz> <x,y,z> vector coordinates with their constructors put declarations in header file vec.h #include vec.h Vec3 vector1;

New Way of Drawing Generate points & store vertices into an array point3 points[3] = { point2(100,50), point2(100,130), point2(150, 130); } Drawpointsfromarrayusing array gldrawarray

Move points GPU memory Rendering from GPU memory significantly faster. Move data there Fast GPU memory for data called Buffer Objects Three steps: 1. Create VBO and give it name (unique ID number) GLuint buffer; glgenbuffers(1, &buffer); // create one buffer object Number of Buffer Objects to return 2. Make created VBO currently active one glbindbuffer(gl_array_buffer, buffer); //data is array

Move points GPU memory 3. Move points generated earlier to VBO glbufferdata(gl_array_buffer, buffer, sizeof(points), points, GL_STATIC_DRAW ); //data is array Data to be transferred to GPU memory (generated earlier) GL_STATIC_DRAW: buffer object data will be specified once by application and used many times to draw GL_DYNAMIC_DRAW: buffer object data will be specified repeatedly and used many times to draw

Draw points gldrawarrays(gl_points, 0, N); Render buffered data as points Display function using gldrawarrays: void mydisplay(void){ glclear(gl_color_buffer_bit); // clear screen gldrawarrays(gl_points, 0, N); glflush( ); // force rendering to show } Other possible arguments to gldrawarrays instead of GL_POINTS?

gldrawarrays( ) Parameters gldrawarrays(gl_points,.) draws dots gldrawarrays((gl_lines, ) Connect vertex pairs to draw lines

gldrawarrays( ) Parameters gldrawarrays(gl_line_strip,..) polylines gldrawarrays(gl_polygon,..) convex filled polygon gldrawarrays(gl_line_loop) Close loop of polylines p p y (Like GL_LINE_STRIP but closed)

gldrawarrays( ) Parameters Ti Triangles: Connect t3 vertices GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN Quad: Connect 4 vertices GL_QUADS, GL_QUAD_STRIP

Triangulation Generally OpenGL breaks polygonsdownintotriangles triangles which are then rendered c d b a

Line Attributes Color, thickness, stippling. glcolor3f() sets color. gllinewidth(4.0) sets thickness. Default Df thickness is 1.0. 10 a). thin lines b). thick lines c). stippled lines

OpenGL State Variables OpenGL maintains state variables for drawing attributes Current drawing color Current point size Current line thickness Current background color All drawings use current value of state variables State variables retain and use old value until changed Example: If you set drawing color to blue All drawing is in blue till drawing color changed

OpenGL Command Format glvertex2i( ) library gl glut basic command Vertex Color Clear Flush number of arguments 2 (x,y) 3 (x,y,z) 4 (x,y,z,w) or (r,g,b,a) type of argument b byte ub- unsigned byte s - short us unsigned short i int ui unsigned int f float d - double * - wildcard

Some OpenGL Commands glpointsize( ) sets point size used in drawing glcolor3f(r,g,b,alpha) set RGB color Sets RGB color and transparency (alpha). RGB color in range 0 to 1.0 Alpha: 0.0 = fully opaque, 1.0 = fully transparent glclearcolor(r,g,b,alpha) alpha) glclear(gl_color_buffer_bit ) Clears screen to background color glflush( ) forces image drawing

Double Buffering Set display mode to double buffers (front and back framebuffers) glutinitdisplaymode(glut_double GLUT_RGB); Double buffering with RGB colors Front buffer visible on screen Drawing done in back buffers (not visible to user) until swapped in using glutswapbuffers( ) void mydisplay(void){ glclear(gl_color_buffer_bit); // clear screen } gldrawarrays(gl_points, 0, N); glutswapbuffers( ) Back buffer drawing swapped in, becomes visible here

OpenGL Data Types C++ OpenGL Signed char Short Int Float Double Unsigned char Unsigned short Unsigned int GLByte GLShort GLInt GLFloat GLDouble GLubyte GLushort GLuint Example: Integer is 32 bits on 32 bit machine but 64 bits on a 64 bit machine

References Angel and Shreiner, Chapter 2 Hill, chapter 2