Lecture 3. Understanding of OPenGL programming

Similar documents
Drawing Primitives. OpenGL basics

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

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

Announcements OpenGL. Computer Graphics. Spring CS4815

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

Bob s Concise Introduction to Doxygen

Programming with OpenGL Part 3: Three Dimensions

COMPUTER GRAPHICS LAB # 3

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

Introduction to OpenGL: Part 2

Using OpenGL with CUDA

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

Assignment 1. Simple Graphics program using OpenGL

CSE4030 Introduction to Computer Graphics

Lectures OpenGL Introduction

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

Basic Graphics Programming

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

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

FAKULTI TEKNOLOGI MAKLUMAT DAN KOMUNIKASI BITM INTERACTIVE COMPUTER GRAPHICS LAB SESSION 4. C++ - OpenGL

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

CS 4204 Computer Graphics

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

Computer Graphics. Making Pictures. Computer Graphics CSC470 1


Introduction to Computer Graphics with OpenGL/GLUT

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

Precept 2 Aleksey Boyko February 18, 2011

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

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

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

C++ - OpenGL - Setting up Visual Studio

Graphics Programming

CS380: Computer Graphics Basic OpenGL Structure. Sung-Eui Yoon ( 윤성의 ) Course URL:

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

Programming with OpenGL Part 1: Background

Display Lists in OpenGL

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

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

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

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

Basic Graphics Programming

Programming using OpenGL: A first Introduction

BOUNCING BALL IMRAN IHSAN ASSISTANT PROFESSOR

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

Drawing and Coordinate Systems

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

Computer Graphics Course 2005

OpenGL Introduction Computer Graphics and Visualization

OpenGL JOGL. OpenGL & JOGL. Shaoting Zhang, or Tony. September 12, 2007

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

Computer graphics MN1

Input and Interaction. 1. Interaction. Chapter 3. Introduction: - We now turn to the development of interactive graphics programs.

1.2 Basic Graphics Programming

Lecture 3 Advanced Computer Graphics (CS & SE )

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

Books, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D

Interaction. CSCI 480 Computer Graphics Lecture 3

Computer Graphics (Basic OpenGL)

C OMPUTER G RAPHICS Thursday

Computer Graphics. Bing-Yu Chen National Taiwan University

Computer Graphics, Chapt 08

RECITATION - 1. Ceng477 Fall

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

Computer Graphics. OpenGL

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Andrew Yenalavitch Homework 1 CSE Fall 2014

Drawing and Coordinate Systems

Draw the basic Geometry Objects. Hanyang University

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

Abel J. P. Gomes LAB. 1. INTRODUCTION TO OpenGL

Hierarchical Modeling: Tree of Transformations, Display Lists and Functions, Matrix and Attribute Stacks,

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

(21) OpenGL GUI. OpenGL GUI 1 UNIX MAGAZINE UNIX. SGI (Silicon Graphics Inc.) Windows PC GUI. UNIX Windows GUI. Java. 1 prefposition() X X

Lattice Gas Cellular Automaton Model for Fluid Flow

Introduction to OpenGL

Interaction Computer Graphics I Lecture 3

Computer Graphics Introduction to OpenGL

Fourier Series. Given a periodic function, x(t), (-T <t <T): + b n sin n t T. a n cos n t T. 2 a 0 + Z T. a n = 1 T. x(t) cos n t T. b n = 1 T.

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

Books, OpenGL, GLUT, CUDA, OpenCL, OpenCV, PointClouds, G3D, and Qt

OpenGL/GLUT Intro. Week 1, Fri Jan 12

Rendering Pipeline/ OpenGL

Computer Graphics: Line Drawing Algorithms

CS 432 Interactive Computer Graphics

CS418 OpenGL & GLUT Programming Tutorial (I) Presented by : Wei-Wen Feng 1/30/2008

Graphics Hardware and OpenGL

OpenGL refresher. Advanced Computer Graphics 2012

... Print PROGRAMS\Final Project final\planes\planeshoot.c 1

Modeling Transform. Chapter 4 Geometric Transformations. Overview. Instancing. Specify transformation for objects 李同益

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

Source code: #include <iostream>

2a. The triangles scale increases (expands) when the 'e' key is pressed and decreases (contracts) when the 'c' key is pressed.

Erik Anchondo cse 520 lab 4

Introduction to MS Visual C/C++

Computer Graphics Primitive Attributes

Exercise 1 Introduction to OpenGL

Philip Calderon CSE 520 Lab 3 Color Shader

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

Introduction to OpenGL Week 1

Transcription:

Lecture 3 Understanding of OPenGL programming

What is OpenGL GL: stands for Graphic Library Software interface for rendering purposes for 2D or 3D geometric data objects.

Various Pieces gl: The basic libraries. glu: Advanced implementation of OpenGL. Higher level function calls/commands. i.e. glusphere. glut: Generic platform independent library.

Reference/Source Code Nehe s OpenGL Tutorials http://nehe.gamedev.net/ GLUT Programming Interface: The OpenGL Utility ToolKit (GLUT) Programming Interface GL Programming Interface http://www.glprogramming.com/blue/ Blue Book

Hello world.cpp #include <GL\glew.h> #include <GL\freeglut.h> #include <GL\glut.h> #include <math.h> void display( ) // Clear the background before drawing glclear(gl_color_buffer_bit); // Actual code to do the drawing glbegin(gl_polygon); glvertex2f(-0.5, -0.5); glvertex2f(-0.5, 0.5); glvertex2f(0.5, 0.5); glvertex2f(0.5, -0.5); glend(); int main(int argc, char* argv[]) glutinit(&argc, argv); glutinitdisplaymode(glut_single GLUT_RGB); glutinitwindowposition(50, 50); glutinitwindowsize(200, 200); glutcreatewindow("hello World"); glutdisplayfunc(display); glutmainloop(); return 0; // Ensure all drawing commands are executed glflush();

int main(int argc, char* argv[]) glutinit(&argc, argv); glutinitdisplaymode(glut_single GLUT_RGB); glutinitwindowposition(50, 50); glutinitwindowsize(200, 200); glutcreatewindow("hello World"); glutdisplayfunc(display); glutmainloop(); glutinitwindowposition(50, 50); Window is created 50 pixel for left of screen and 50 pixel for top of the screen glutcreatewindow("hello World"); The created windows is named as Hello World return 0; glutcreatewindow("hello World"); The size of the Hello World windows is 200 pixel x 200 pixel Task: Change the position of the windows and the size of the windows. Observe the changes.

void display( ) // Clear the background before drawing glclear(gl_color_buffer_bit); glbegin(gl_polygon); The rectangle is called as GL_POLYGON // Actual code to do the drawing glbegin(gl_polygon); glvertex2f(-0.5, -0.5); glvertex2f(-0.5, 0.5); glvertex2f(0.5, 0.5); glvertex2f(0.5, -0.5); glend(); // Ensure all drawing commands are executed glflush(); glvertex2f(-0.5, -0.5); glvertex2f(-0.5, 0.5); glvertex2f(0.5, 0.5); glvertex2f(0.5, -0.5); Task: By changing the size of the GL_POLYGON, find the size of the windows in terms Cartesian Coordinate? These are the coordinates of the GL_POLYGON. The center of the Windows is reference point (0,0)

Color Setting void display( ) // Clear the background before drawing glclear(gl_color_buffer_bit); // Actual code to do the drawing glbegin(gl_polygon); glcolor3f(1.0, 1.0, 1.0); glvertex2f(-0.5, -0.5); glcolor3f(1.0, 0.0, 0.0); glvertex2f(-0.5, 0.5); glcolor3f(0.0, 1.0, 0.0); glvertex2f(0.5, 0.5); glcolor3f(0.0, 0.0, 1.0); glvertex2f(0.5, -0.5);glEnd(); // Ensure all drawing commands are executed glflush();

void glcolor3 (TYPE red, TYPE green, TYPE blue); glcolor3f(1.0, 0.0, 0.0); glvertex2f(-0.5, 0.5); (red : 1, green: 0, blue : 0) red glcolor3f(0.0, 1.0, 0.0); glvertex2f(0.5, 0.5); (red : 0, green: 1, blue : 0) green glcolor3f(1.0, 1.0, 1.0); glvertex2f(-0.5, -0.5); (red : 1, green: 1, blue : 1) white glcolor3f(0.0, 0.0, 1.0); glvertex2f(0.5, -0.5); (red : 0, green: 0, blue : 1) blue Task: Observe the square by just by setting the colored once before glbegin

Shape of different sizes void display( ) // Clear the background before drawing glclear(gl_color_buffer_bit); glmatrixmode(gl_projection); glloadidentity(); gluortho2d(-5.0, 5.0, -5.0, 5.0); glmatrixmode(gl_modelview); // Actual code to do the drawing glcolor3f(0.0, 1.0, 0.0); glbegin(gl_polygon); glvertex2f(-3, -3); glvertex2f(-3, 3); glvertex2f(3, 3); glvertex2f(3, -3); glend(); glflush();

Animation Concept Changing the one or more variables that will change the position of the entity or entities. By displaying each frame with different coordinates, animation can be formed. Frame 1 Frame 2 Frame 3 Frame 4 Therefore, shape must be drawn using variable/s and by changing the value of variable/s, animation can be created.

Animation: Development of the equations X1 = R * cos (pi/2 + q) Y1 = R * sin (pi/2 + q) X2 = R * cos (pi + q) Y2 = R * sin (pi + q) X0 = R * cos (0 + q) Y0= R * sin (0 + q) X3 = R * cos (1.5*pi + q) Y3 = R * sin (1.5*pi + q) Additional Codes #include <GL\glew.h> #include <GL\freeglut.h> #include <math.h> #define pi 4 * atan(1.0) GLfloat theta =0 ; glbegin(gl_polygon); glvertex2f(3*cos(0+theta), 3*sin(0+theta)); glvertex2f(3 * cos(0.5*pi + theta), 3 * sin(0.5*pi + theta)); glvertex2f(3 * cos(pi + theta), 3 * sin(pi + theta)); glvertex2f(3 * cos(1.5*pi + theta), 3 * sin(1.5*pi + theta)); glend();

Animation: Modification of the programs int main(int argc, char* argv[]) glutinit(&argc, argv); glutinitdisplaymode(glut_double GLUT_RGB); glutinitwindowposition(100, 100); glutinitwindowsize(600, 600); glutcreatewindow("hello World"); glutdisplayfunc(display); glutidlefunc(myidle); glutmainloop(); glvertex2f(3 * cos(0.5*pi + theta), 3 * sin(0.5*pi + theta)); glvertex2f(3 * cos(pi + theta), 3 * sin(pi + theta)); glvertex2f(3 * cos(1.5*pi + theta), 3 * sin(1.5*pi + theta)); glend(); // Ensure all drawing commands are executed glutswapbuffers(); //replacing glflush() return 0; void myidle() theta += 0.01 * pi / 180.0;; if (theta > 2 *pi) theta -= -2*pi; glutpostredisplay();

Animation: two or more variables Two or more entities are animated at the same time - In myidle function, more than one variables can be used. Therefore, var1, var2 varn can be used. void myidle() theta1 += 0.01 * pi / 180.0;; if (theta1 > 2 *pi) theta -= -2*pi; theta2 += 1 * pi / 180.0;; if (theta2 > 2 *pi) theta -= -2*pi thetan += 10 * pi / 180.0;; if (thetan > 2 *pi) theta -= -2*pi glutpostredisplay();

Animation: in sequence The task is to make the rectangle travels along three designated routes. Therefore, the rectangle will travel along path 1, then follows with Path 2 and finally Path 3. Soln: a flag that indicates which path to follow should be used here. Common practice is that the value flag will be either 0 or 1. void myidle() if ( flag_path1 == 0 && flag_path2 == 0 && flag_path3 = 0) var1 += 1; if ( point.x == P1.x && point.y == P1.y) flag_path1 = 1 else if (flag_path2 == 0 && flag_path3 = 0) then glutpostredisplay();