CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.

Slides:



Advertisements
Similar presentations
OpenGL Open a Win32 Console Application in Microsoft Visual C++.
Advertisements

OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
Chapter 2: Graphics Programming
Pemrograman OpenGL Dasar
© 2004, Tom Duff and George Ledin Jr1 Lectures OpenGL Introduction By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
OpenGL and Projections
1 CSC461 Lecture 7: 3D Programming in OpenGL Objectives: Develop 2D and 3D examples -- Sierpinski gasket: a fractal Develop 2D and 3D examples -- Sierpinski.
Ellipses Using OpenGL.
30/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 1: Introduction.
Programming with OpenGL Part 0: 3D API March 1, 2007.
Programming with OpenGL Part 1: Background Mohan Sridharan Based on slides created by Edward Angel CS4395: Computer Graphics 1.
Introduction to OpenGL TA: Mani Thomas CISC 440/640
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
Using OpenGL in Visual C++ Opengl32.dll and glu32.dll should be in the system folder Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib.
Demetriou/Loizidou – ACSC330 – Chapter 2 Graphics Programming Dr. Giorgos A. Demetriou Dr. Stephania Loizidou Himona Computer Science Frederick Institute.
Graphics Architectures & OpenGL API Introduction Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Programming with OpenGL Part 1: Background
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
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,
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
Introduction to OpenGL Week 1 David Breen Department of Computer Science Drexel University Based on material from Ed Angel, University of New Mexico CS.
Computer Graphics I, Fall 2010 Programming with OpenGL Part 3: Three Dimensions.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Programming with OpenGL Review.
1 Chapter 2: Graphics Programming Bryson Payne CSCI 3600 NGCSU.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 43 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 43 Computer Graphics Programming with OpenGL I.
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
Pemrograman OpenGL Dasar Pertemuan 5 Hand out Komputer Grafik.
NoufNaief.net TA: Nouf Al-harbi.
Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor.
GLUT functions glutInit allows application to get command line arguments and initializes system gluInitDisplayMode requests properties for the window.
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
Chap 3 Viewing and Transformation
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
CS552: Computer Graphics Lecture 6: Viewing in 2D.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 3: Three Dimensions Ed Angel Professor of Computer Science,
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
OpenGL Basic Drawing Jian-Liang Lin A Smidgen of OpenGL Code #include main() { InitializeAWindowPlease(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear.
Introduction to Graphics Programming. Graphics API.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
INTRODUCTION TO OPENGL
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CS 480/680 Computer Graphics Programming with Open GL Part 2: Complete Programs Dr. Frederick C Harris, Jr. Fall 2011.
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
Programming with OpenGL Part 1: Background
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 1: Background
Materi Anatomi OpenGL Fungsi GLUT Posisi Kamera Proyeksi
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
גרפיקה ממוחשבת: מבוא ל-OpenGL
Introduction to OpenGL
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 3: Three Dimensions
Presentation transcript:

CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program standard structure Introduce the OpenGL program standard structure

CSC 461: Lecture 52 A Simple Program Source code: simple.c Source code: simple.c #include void mydisplay(){ glClear(GL_COLOR_BUFFER_BIT); 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(); // force to display } int main(int argc, char** argv){ glutCreateWindow("simple"); glutDisplayFunc(mydisplay); glutMainLoop(); } Generate a square on a solid background Generate a square on a solid background

CSC 461: Lecture 53 Event Loop Note that the program defines a display callback function named mydisplay Note that the program defines a display callback function named mydisplay Every glut program must have a display callback Every glut program must have a display callback The display callback is executed whenever OpenGL decides the display must be refreshed, for example when the window is opened The display callback is executed whenever OpenGL decides the display must be refreshed, for example when the window is opened The main function ends with the program entering an event loop The main function ends with the program entering an event loop

CSC 461: Lecture 54 Defaults simple.c is too simple simple.c is too simple Makes heavy use of state variable default values for Makes heavy use of state variable default values for Viewing Viewing Colors Colors Window parameters Window parameters Next version will make the defaults more explicit Next version will make the defaults more explicit

CSC 461: Lecture 55 Program Structure Most OpenGL programs have a similar structure that consists of the following functions Most OpenGL programs have a similar structure that consists of the following functions main() : main() : defines the callback functions defines the callback functions opens one or more windows with the required properties opens one or more windows with the required properties enters event loop (last executable statement) enters event loop (last executable statement) init() : sets the state variables init() : sets the state variables viewing viewing Attributes Attributes callbacks callbacks Display function Display function Input and window functions Input and window functions

CSC 461: Lecture 56 Simple.c revisited In this version, we will see the same output but have defined all the relevant state values through function calls with the default values In this version, we will see the same output but have defined all the relevant state values through function calls with the default values In particular, we set In particular, we set Colors Colors Viewing conditions Viewing conditions Window properties Window properties

CSC 461: Lecture 57 Source: main.c #include #include int main(int argc, char** argv) {glutInit(&argc,argv);glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);glutInitWindowSize(500,500);glutInitWindowPosition(0,0);glutCreateWindow("simple");glutDisplayFunc(mydisplay); init(); glutMainLoop();} includes gl.h define window properties set OpenGL state enter event loop display callback

CSC 461: Lecture 58 Source code: init.c void init() { glClearColor (0.0, 0.0, 0.0, 1.0); glColor3f(1.0, 1.0, 1.0); glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho(-1.0, 1.0, -1.0, 1.0, - 1.0, 1.0); } black clear color opaque window fill with white viewing volume

CSC 461: Lecture 59 Source code: mydisplay.c void mydisplay() {glClear(GL_COLOR_BUFFER_BIT);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();}

CSC 461: Lecture 510 GLUT functions glutInit allows application to get command line arguments and initializes system glutInit allows application to get command line arguments and initializes system gluInitDisplayMode requests properties of the window (the rendering context) gluInitDisplayMode requests properties of the window (the rendering context) RGB color RGB color Single buffering Single buffering Properties logically ORed together Properties logically ORed together glutWindowSize in pixels glutWindowSize in pixels glutWindowPosition from top-left corner of display glutWindowPosition from top-left corner of display glutCreateWindow create window with title “simple” glutCreateWindow create window with title “simple” glutDisplayFunc display callback glutDisplayFunc display callback glutMainLoop enter infinite event loop glutMainLoop enter infinite event loop

CSC 461: Lecture 511 Coordinate Systems The units in glVertex are determined by the application and are called world or problem coordinates The units in glVertex are determined by the application and are called world or problem coordinates The viewing specifications are also in world coordinates and it is the size of the viewing volume that determines what will appear in the image The viewing specifications are also in world coordinates and it is the size of the viewing volume that determines what will appear in the image Internally, OpenGL will convert to camera coordinates and later to screen coordinates Internally, OpenGL will convert to camera coordinates and later to screen coordinates

CSC 461: Lecture 512 OpenGL Camera OpenGL places a camera at the origin pointing in the negative z direction OpenGL places a camera at the origin pointing in the negative z direction The default viewing volume The default viewing volume is a box centered at the origin with a side of length 2 is a box centered at the origin with a side of length 2

CSC 461: Lecture 513 Orthographic Viewing In the default orthographic view, points are projected forward along the z axis onto the plane z=0 z=0

CSC 461: Lecture 514 Transformations and Viewing In OpenGL, the projection is carried out by a projection matrix (transformation) In OpenGL, the projection is carried out by a projection matrix (transformation) There is only one set of transformation functions so we must set the matrix mode first There is only one set of transformation functions so we must set the matrix mode first glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION); Transformation functions are incremental so we start with an identity matrix and alter it with a projection matrix that gives the view volume Transformation functions are incremental so we start with an identity matrix and alter it with a projection matrix that gives the view volume glLoadIdentity(); glLoadIdentity(); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);

CSC 461: Lecture 515 Three-dimensional viewing glOrtho(left,right,bottom,top,near,far) Left, right, bottom, top, near and far specify the six sides Left, right, bottom, top, near and far specify the six sides The near and far distances are measured from the camera The near and far distances are measured from the camera

CSC 461: Lecture 516 Two-dimensional viewing Two-dimensional vertex commands place all vertices in the plane z=0 Two-dimensional vertex commands place all vertices in the plane z=0 If the application is in two dimensions, we can use the function If the application is in two dimensions, we can use the function gluOrtho2D(left, right,bottom,top) gluOrtho2D(left, right,bottom,top) z=0 In two dimensions, the view or clipping volume becomes a clipping window In two dimensions, the view or clipping volume becomes a clipping window