Drawing in the plane 455.

Slides:



Advertisements
Similar presentations
OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
Advertisements

Chapter 2: Graphics Programming
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
OpenGL (I). What is OpenGL (OGL)? OGL is a 3D graphics & modeling library Can also use it to draw 2D objects.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
Device Independent Graphics and OpenGL
ITEPC 06 - Workshop on Fractal Creation Chiew-Lan Tai and Oscar Au.
Computer Graphics CS 385 February 7, Fundamentals of OpenGl and Glut Today we will go through the basics of a minimal OpenGl Glut project, explaining.
Reference1. [OpenGL course slides by Rasmus Stenholt]
CS380 LAB I OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 2.
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Graphics Programming and OpenGL.
COS 397 Computer Graphics Assoc. Prof. Svetla Boytcheva AUBG 2013 COS 397 Computer Graphics Practical Session №1 Introduction to OpenGL, GLFW and CG.
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
Drawing Basic Graphics Primitives Lecture 4 Wed, Sep 3, 2003.
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
Computer Graphics using OpenGL, 3 rd Edition F. S. Hill, Jr. and S. Kelley Chapter 2 Initial Steps in Drawing Figures Ureerat Suksawatchon Faculty of Informatics.
Interactive Computer Graphics Lecture 2: The programming approach to building graphical applications using OpenGL API.
Computer Graphics CS 385 January 31, Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.
1. OpenGL/GLU/GLUT  OpenGL v4.0 (latest) is the “core” library that is platform independent  GLUT v3.7 is an auxiliary library that handles window creation,
CD2012 Principles of Interactive Graphics Lecture 01 Introduction Abir Hussain (Rome: 6.33,Tel , Web:
P RACTICING O PEN GL- P RIMITIVES. O PEN GL O UTPUT P RIMITIVES  Each geometric object is described by a set of vertices and the type of primitive to.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
1 Graphics CSCI 343, Fall 2015 Lecture 3 Introduction to WebGL.
NoufNaief.net TA: Nouf Al-harbi.
What are Computer Graphics Basically anything that is on you Monitor – This includes the text that you will see Text isn’t Advanced Graphics But…. Understanding.
Lecture 2 Review OpenGL Libraries Graphics Overview Rendering Pipeline OpenGL command structure.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 15 Creating 3D Models.
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
CIS 681 Review: OpenGL. CIS 681 Command Syntax OpenGL commands start with a gl. This is followed by the base command such as Color. Followed by the number.
Introduction to OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP.
Graphics Graphics Korea University kucg.korea.ac.kr Graphics Programming 고려대학교 컴퓨터 그래픽스 연구실.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL: Event-driven How in OpenGL? Programmer registers callback functions Callback function called when.
INTRODUCTION TO OPENGL
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Computer Graphics -practical- Lecture 6. (visual c++) open gl library To use open GL with VC++ we add these files:- 1)Glut.h C:\program files\ Microsoft.
Hank Childs, University of Oregon Oct. 28th, 2016 CIS 441/541: Introduction to Computer Graphics Lecture 16: textures.
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
CSC Graphics Programming
The Human Visual System vs The Pinhole camera
Programming with OpenGL Part 1: Background
CS380 Lab Spring Myungbae Son.
Programming with OpenGL Part 1: Background
“Computer Science is no more about computers than astronomy is about telescopes.” Professor Edsger Dijkstra.
Programming with OpenGL Part 2: Complete Programs
Materi Anatomi OpenGL Fungsi GLUT Posisi Kamera Proyeksi
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
Graphics Programming (I)
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
OpenGL A Brief Overview.
Lab 3 Geometric Drawing Lab 3 Geometric Drawing.
Starting to draw dealing with Windows which libraries? clipping
Programming with OpenGL Part 1: Background
Introduction to OpenGL
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Interactive Computer Graphics Graphics Programming
OpenGL program.
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 1: Background
Starting to draw dealing with Windows which libraries? clipping
Programming with OpenGL Part 2: Complete Programs
University of North Carolina at Greensboro
OpenGL A Brief Overview.
Presentation transcript:

Drawing in the plane 455

Content Getting started OpenGL primitives Line Drawings in OpenGL Interaction in OpenGL Design and use of menus

Making pictures Picture created in screen window Window coordinates – integer values of pixel’s position Open GL device independent graphical library OpenGL is a State machine

Windows based programming Event driven approach Event queue – press key, click mouse, move window etc. Program is running as an event loop waiting for until receives a trigger Events are associated with callback functions

Callback functions Each callback function should be first registered Registering (callback) functions in main loop glutDisplayFunc(MyDisplay); Function MyDisplay (user function) is registered by glut - utility

Libraries of OpenGL The basic library with header gl.h contains low-level graphical commands and predefined constants and graphical types The OpenGL Utility library glu.h contains several routines that use lower-level OpenGL commands The OpenGL Utility Toolkit glut.h window system-independent toolkit for working with window system.

Main function int main() { glutInitWindowSize(480,480);//size of initial window glutCreateWindow("My first attemt");//crete default window glutDisplayFunc(MyDisplay);//register user function MyInit();//initialization function glutMainLoop();// looping return 0; }

Initial function void MyInit(void) { glClearColor(1.0,1.0,1.0,.0);//color of background glColor3f(1.0,0.0,0.0);//color for drawing glMatrixMode(GL_PROJECTION);//matrix state glLoadIdentity(); //initialization of projection matrix gluOrtho2D(0,480.0,0,480);//Size of world window }

Opening window for drawing glutInitWindowSize(480,480) – size of the first occurrence of the window glutCreateWindow("My first attemt") – creating a window with given title glutDisplayFunc(MyDisplay) – registering of a drawing function glutMainLoop(); - looping the function

Basic primitives Each graphical object defined in OpenGL is composed by graphical primitives. Each primitive is described by its type, position and properties. Properties are given by the state of OpenGL

Basic primitives - example1 glBegin(GL_LINES);//line glVertex2d(0,240);//coordinates glVertex2d(480,240); glVertex2d(240,0); glVertex2d(240,480); glEnd();

Basic primitives - example 2 glColor4f(0.0,0.0,1.0,0.0);//new color glBegin(GL_TRIANGLES);//first triangle glVertex2d(100,100); glVertex2d(100,300); glVertex2d(300,100); glEnd();

Graphical primitives GL_POINTS individual points GL_LINES pairs of vertices as individual line segments GL_LINE_STRIP series of connected line segments GL_LINE_LOOP closed series of connected line segments GL_TRIANGLES series of triangles GL_TRIANGLE_STRIP linked strip of triangles GL_TRIANGLE_FAN linked fan of triangles GL_QUADS quadruples interpreted as 4-gons GL_QUAD_STRIP linked list of 4-gons GL_POLYGON simple convex polygon

Including graphical libraries #include <GL/glut.h> Prefixes gl – basic graphical functions glu, glut – graphical utilities (glut – graphical utilities toolbox)

First program in OpenGL We draw too line segments in a square window Line segments are of different color and different thickness.

First program in OpenGL void MyInit(void) { glClearColor(1.,1.,1.,.0);//white color of background glMatrixMode(GL_PROJECTION);//initialization of projection matrix glLineWidth(1.0);//initial width of lines glLoadIdentity(); gluOrtho2D(0,480,0,480);//size of world window }

First program in OpenGL void MyDisplay(void) { glClear(GL_COLOR_BUFFER_BIT);//clear background glColor4f(0.0,0.0,1.0,0.0);//blue color of first line glBegin(GL_LINES);//first line glVertex2d(480,0);//coordinates glVertex2d(0,240); glEnd(); glLineWidth(2.0);//width of second line glColor4f(1.0,0.0,0.0,0.0);//red color of second line glBegin(GL_LINES); glVertex2d(0,0); glVertex2d(480,480); glFlush();//draw all primitives }

First program in OpenGL int main() { glutInitWindowSize(480,480);// size o initial window glutCreateWindow("My first attemt");//crete default window glutDisplayFunc(MyDisplay);//register user display function MyInit(); glutMainLoop(); return 0; }

Drawing triangles The first triangle is filled with a default color The second triangle has different colors of vertices. The fill color is an interpolation of vertex-colors.

Definition of primitives-triangles glColor4f(0.0,0.0,1.0,0.0);//blue color of a triangle glBegin(GL_TRIANGLES);//first triangle glVertex2d(100,100);//coordinates of 1.triangle glVertex2d(100,300); glVertex2d(300,100); glColor4f(1.0,1.0,0.0,0.0);//changing color glVertex2d(300,300); //2.triangle glColor4f(0.0,1.0,0.0,0.0);//changing color glVertex2d(200,400); glColor4f(1.0,.0,0.0,0.0);//changing color glVertex2d(50,50); glEnd(); }

Drawing set of points Sierpinski gasket Choose 3 points T0,T1,T2 in the plane Choose one of points p0 in random Choose one of points T0,T1,T2 , T in random Construct point pk as midpoint of pk-1 and T Draw point pk.

Implementation of Sierpinski gasket class GLintPoint //definition of a class point { public: int x, y; }; void drawDot(GLintPoint p) //drawing a point glBegin(GL_POINTS); glVertex2i(p.x,p.y); glEnd(); }

Implementation of Sierpinski gasket void Sierpinski(void) { int index=1; GLintPoint T[3]={{100,100},{500,100},{300,400}}; GLintPoint point=T[index]; glClear(GL_COLOR_BUFFER_BIT); drawDot(point); for (int i=0; i<10000; i++) index=rand()%3; point.x=(point.x+T[index].x)/2; point.y=(point.y+T[index].y)/2; } glFlush();

Drawing from the file void DrawDino(void) { inStream.open("dino1.dat");//data of dinosaurus if(inStream.fail()) return; while(inStream) inStream>>numLines; glBegin(GL_LINE_STRIP);//different graphical primitives for(int i=0; i<numLines; i++) inStream>>x>>y; glVertex2i(x,y); } glEnd();

Drawing from the file Exaple of data file: 21 29 32 435 10 439 4 438 2 433 4 428 6 425 10 420 15 416 21 413 30 408 42 406 47 403 56 398 63 391 71 383 ………….. ………………

Graph of a function float func(float t) { float value; value=exp(-t)* cos(2*3.14159265*t); return value; } // y=e-t.cos(2πt)

Graph of a function Real values of coordinates does not fit to integer coordinates of the window Necessary transformation of coordinates point.x=A*x+B ; point.y=C*func(x) +D; glVertex2d(point.x,point.y); Problem : how to find parameters A,B,C,D ?

Graph of a function Possible solution: A=screenWidth/4.0; B=screenWidth/2.0; C=screenHeight/6.0; D=screenHeight/2.0