Programming of Graphics

Similar documents
Introduction to Computer Graphics with OpenGL/GLUT

COMP3421 Computer Graphics

RECITATION - 1. Ceng477 Fall

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

JOGL 3D GRAPHICS. Drawing a 3D line. In this chapter, let us see how to deal with 3D graphics.

An Introduction to 2D OpenGL

CSC 8470 Computer Graphics. What is Computer Graphics?

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

Computer Graphics. OpenGL

CMSC427 Fall 2017 OpenGL Notes A: Starting with JOGL and OpenGL Objectives of notes Readings Computer Graphics Programming in OpenGL with Java

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

Programming using OpenGL: A first Introduction

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

CMSC427 OpenGL and JOGL

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

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

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

Draw the basic Geometry Objects. Hanyang University

COMP 371/4 Computer Graphics Week 1

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

Graphics Programming

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

Assignment 1. Simple Graphics program using OpenGL

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

OpenGL Introduction Computer Graphics and Visualization

Drawing Primitives. OpenGL basics

CS 4204 Computer Graphics

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

Computer graphic -- Programming with OpenGL I

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

Rendering. Part 1 An introduction to OpenGL

Precept 2 Aleksey Boyko February 18, 2011

2D Drawing Primitives

Computer Graphics 1 Computer Graphics 1

OpenGL. Toolkits.

OPENGL AND GLSL. Computer Graphics

Lecture 4 of 41. Lab 1a: OpenGL Basics

OUTLINE. Learn the basic design of a graphics system Introduce pipeline architecture Examine software components for a graphics system

Computer Graphics. Bing-Yu Chen National Taiwan University

Introduction to OpenGL Week 1

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

COMP3421/9415 Computer Graphics

Exercise 1 Introduction to OpenGL

OpenGL/GLUT Intro. Week 1, Fri Jan 12

Programming with OpenGL Part 1: Background

Graphics Pipeline & APIs

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

Lecture 3. Understanding of OPenGL programming

Luiz Fernando Martha André Pereira

COMPUTER GRAPHICS LAB # 3

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

CSE528 Computer Graphics: Theory, Algorithms, and Applications

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

Basic Graphics Programming

INTRODUCTION. Computer Graphics

Lecture 2 2D transformations Introduction to OpenGL

Graphics Pipeline & APIs

Computer Graphics, Chapt 08

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

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

Building Models. 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++

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

Computer Graphics. Chapter 3 Computer Graphics Software

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

Basic Graphics Programming

Computer Graphics Introduction to OpenGL

Lecture 3 Advanced Computer Graphics (CS & SE )

Computer Graphics Primitive Attributes

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

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

Computer graphics MN1

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

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

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

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

New topic for Java course: Introduction to 3D graphics programming

GLUT. What is OpenGL? Introduction to OpenGL and GLUT

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

Lectures OpenGL Introduction

Computer Graphics Course 2005

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

An Interactive Introduction to OpenGL Programming

Simple Geometric Modeling

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

CS 428: Fall Introduction to. OpenGL primer. Andrew Nealen, Rutgers, /13/2010 1

Programming with OpenGL Part 1: Background

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

Introduction to OpenGL

Announcements OpenGL. Computer Graphics. Spring CS4815

WebGL A quick introduction. J. Madeira V. 0.2 September 2017

1.2 Basic Graphics Programming

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Graphics Hardware and OpenGL

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

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

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

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

Transcription:

Peter Mileff PhD Programming of Graphics Introduction to OpenGL University of Miskolc Department of Information Technology

OpenGL libraries GL (Graphics Library): Library of 2D, 3D drawing primitives and operations API for 3D hardware acceleration GLU (GL Utilities): Miscellaneous functions dealing with camera setup and higher-level shape descriptions GLUT (GL Utility Toolkit): Window-system independent toolkit with numerous utility functions, mostly dealing with user interface 2

Software Organization 3

The OpenGL Context... 4

OpenGL Context Before we do anything, an OpenGL Context should be created An OpenGL context represents many things: A context stores all of the state associated with this instance of OpenGL It represents the (potentially visible) default framebuffer that rendering commands will draw to Think of a context as an object that holds all of OpenGL when a context is destroyed, OpenGL is destroyed 5

A JOGL Application In order to create a Java window, we should extend the JFrame class from Swing We can access the OpenGL functionality from JOGL by implementing the GLEventListener interface public class Game extends JFrame implements GLEventListener { private static final long serialversionuid = 1L; public void display(glautodrawable drawable) { } public void dispose(glautodrawable drawable) { } public void init(glautodrawable drawable) { } } public void reshape(glautodrawable drawable, int x, int y, int width, int height){ } 6

OpenGL Context in JOGL // Get GL profile final GLProfile profile = GLProfile.get(GLProfile.GL2); GLCapabilities capabilities = new GLCapabilities(profile); // Create a canvas for 3D Graphics final GLCanvas glcanvas = new GLCanvas(capabilities); // Create Frame for canvas final JFrame frame = new JFrame("3d Triangle (solid)"); frame.getcontentpane().add(glcanvas); frame.setsize(frame.getcontentpane().getpreferredsize()); frame.setvisible(true); final FPSAnimator animator = new FPSAnimator(glcanvas, 60, true); animator.start(); 7

A JOGL Application Try and investigate the MyJoglDemoSimple application! 8

OpenGL Context in JOGL GLProfile: determines the used OpenGL version The field of computer graphics changes rapidly. Graphics APIs must often break backwards compatibility with each revision. It is important that programmers have control over which version of OpenGL is used by the application To select OpenGL 2.1, for example, a GLProfile would be created as follows: GLProfile glp = GLProfile.get(GLProfile.GL2); 9

OpenGL Context in JOGL GLCapabilities: This object describes some specific capabilities a rendering context should support The default settings are usually fine, but many options are available: E.g: effects such as full-scene anti-aliasing, stereo rendering. This object takes an instance of GLProfile as a parameter. GLCapabilities caps = new GLCapabilities(glp); 10

OpenGL Context in JOGL GLCanvas: A heavyweight AWT component which provides OpenGL rendering support. Everything will be drawn to this component. GLCanvas glcanvas = new GLCanvas(capabilities); 11

The rendering / game loop... 12

Rendering Loop / Game loop Loop: Graphics are repeatedly drawn on screen and interactive (frames) This is real-time rendering This is the type of rendering used in games This style of rendering contrasts offline rendering where single images or frames are calculated over a long period of time Rendering loop should reach 50-60 Frames per Secundum (FPS) 13

Rendering Loop / Game loop 14

Rendering Loop / Game loop Initialization: Choosing a GLProfile and configuring GLCapabilities for a rendering context Creating a window and GLContext through the GLAutoDrawable Making an animator thread Loading resources needed by program Process Input: Listen for mouse and keyboard events Update user's view (often called a camera) 15

Rendering Loop / Game loop Update (Simulate Game World): Calculate geometry Rearrange data Perform computations Render: Draw scene geometry from a particular view Shut Down: Save persistent data Clean up resources on graphics card 16

Animating the loop in JOGL JOGL provides some utility classes for animating our program. An Animator object can be created to ensure the display method of a GLAutoDrawable is repeatedly called. An FPSAnimator allows us make the framerate relatively consistent and can reduce the resource consumption of the program FPSAnimator animator = new FPSAnimator(canvas, 60); animator.start(); 17

Animating the loop in JOGL The animator is attached to the GLCanvas and asked to render at roughly 60 frames per second The display method will be called approximately every 17 ms (1000 / 60) 18

The Basics of OpenGL... 19

Geometry Basics Geometric objects are represented using vertices A vertex is a collection of generic attributes positional coordinates colors texture coordinates any other data associated with that point in space 20

Basics OpenGL is not object oriented so that there are multiple functions for a given logical function E.g.: glvertex3f glvertex2i glvertex3dv OpenGL is a state machine: We put it into various states (or modes) that then remain in effect until you change them E.g: colors, current viewing and projection transformations, line and polygon stipple patterns, etc Every state has a default value 21

Geometry Basics 22

Rendering Loop Every rendering loop has three phases: Start part: usually reinitialises the view and states reset events, clears screen, etc. E.g. glclear( GL_COLOR_BUFFER_BIT ); Drawing part: draw geometry glbegin( XXXX );.. glend(); End part: closes the rendering process OpenGL should be informed about the end of rendering Command: glflush(); 23

void Display() { Basic Example glclear(gl_color_buffer_bit); glcolor4f(1,1,0,1); glbegin(gl_polygon); glvertex2f(-0.5, -0.5); glvertex2f(-0.5, 0.5); glvertex2f(0.5, 0.5); glvertex2f(0.5, -0.5); glend(); glflush(); } 24

Vertices and Primitives... 25

Vertices and Primitives Geometry object are built from primitives OpenGL support many primitive types Game models are usually based on Triangles 26

Vertices and Primitives Points, GL_POINTS Individual points Point size can be altered glpointsize(float size) Example: glbegin(gl_points); glcolor3fv( color ); glvertex2f( P0.x, P0.y ); glvertex2f( P1.x, P1.y ); glvertex2f( P2.x, P2.y ); glvertex2f( P3.x, P3.y ); glvertex2f( P4.x, P4.y ); glvertex2f( P5.x, P5.y ); glvertex2f( P6.x, P6.y ); glvertex2f( P7.x, P7.y ); glend(); 27

Vertices and Primitives Lines, GL_LINES Pairs of vertices interpreted as individual line segments Can specify line width using: gllinewidth (float width) Example: glbegin(gl_lines); glcolor3fv( color ); glvertex2f( P0.x, P0.y ); glvertex2f( P1.x, P1.y ); glvertex2f( P2.x, P2.y ); glvertex2f( P3.x, P3.y ); glvertex2f( P4.x, P4.y ); glvertex2f( P5.x, P5.y ); glvertex2f( P6.x, P6.y ); glvertex2f( P7.x, P7.y ); glend(); 28

Vertices and Primitives Line Strip, GL_LINE_STRIP series of connected line segments 29

Vertices and Primitives Line Loop, GL_LINE_LOOP Line strip with a segment added between last and first vertices 30

Vertices and Primitives Polygon, GL_POLYGON boundary of a simple, convex polygon 31

Vertices and Primitives Triangles, GL_TRIANGLES triples of vertices interpreted as triangles 32

Vertices and Primitives Triangle Strip, GL_TRIANGLE_STRIP linked strip of triangles 33

Vertices and Primitives Triangle Fan, GL_TRIANGLE_FAN linked fan of triangles 34

Vertices and Primitives Quads, GL_QUADS quadruples of vertices interpreted as four-sided polygons 35

Vertices and Primitives Between glbegin / glend, those opengl commands are allowed: glvertex*() : set vertex coordinates glcolor*() : set current color glindex*() : set current color index glnormal*() : set normal vector coordinates (Light.) gltexcoord*() : set texture coordinates (Texture) 36

Transformations... 37

Transformations is OpenGL Modeling transformation Refer to the transformation of models (i.e., the scenes, or objects) Viewing transformation Refer to the transformation on the camera Projection transformation Refer to the transformation from scene to image 38

39