Chi-Cheng Lin, Winona State University CS430 Computer Graphics Graphics Programming and OpenGL.

Slides:



Advertisements
Similar presentations
Computer Graphics - Graphics Programming -
Advertisements

OpenGL Open a Win32 Console Application in Microsoft Visual C++.
OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
OPEN GL. Install GLUT Download package di sini Dari devcpp, buka Tools->PackageManager-
Chapter 2: Graphics Programming
Pemrograman OpenGL Dasar
CS 4731 Lecture 2: Intro to 2D, 3D, OpenGL and GLUT (Part I) Emmanuel Agu.
What is OpenGL? Low level 2D and 3D Graphics Library Competitor to Direct3D (the rendering part of DirectX) Used in: CAD, virtual reality, scientific.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
Draw a Simple Object. Example 1/4 #include “ glut.h ” void display(); void reshape(GLsizei w, GLsizei h); void main(int argc, char** argv){ glutInit(&argc,
Chapter 3: Input and Interaction Instructor: Shih-Shinh Huang 1.
OpenGL (I). What is OpenGL (OGL)? OGL is a 3D graphics & modeling library Can also use it to draw 2D objects.
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
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.
Device Independent Graphics and OpenGL
ITEPC 06 - Workshop on Fractal Creation Chiew-Lan Tai and Oscar Au.
Programming with OpenGL Part 1: Background Mohan Sridharan Based on slides created by Edward Angel CS4395: Computer Graphics 1.
Reference1. [OpenGL course slides by Rasmus Stenholt]
CS380 LAB I OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
2003CS Hons RW778 Graphics1 Chapter 1: Introduction Admin: Admin: –Lecture slots: Monday 8-9:45, Tuesday 9:15-11:00. –Book: F. Hill, Computer Graphics.
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.
Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave.
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.
Programming with OpenGL Part 1: Background
Lecture 3 OpenGL.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 1: Background Ed Angel Professor of Computer Science, Electrical.
 “OpenGL (Open Graphics Library) is a standard specification defining a cross- language cross-platform API for writing applications that produce 2D and.
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 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
CD2012 Principles of Interactive Graphics Lecture 01 Introduction Abir Hussain (Rome: 6.33,Tel , Web:
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 Computer Graphics 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Programming with OpenGL Review.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
Intro to OpenGL (Version 2) Geb Thomas. Setting Up GLUT You will need GLUT for opening windows We can use the version made by Nate Robins: –
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
NoufNaief.net TA: Nouf Al-harbi.
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.
Doç. Dr. Cemil Öz SAÜ Bilgisayar Mühendisliği Dr. Cemil Öz.
Geometric Primitives Used in Open GL Drawing Triangles glBegin(GL_TRIANGELS); glVertex2i(p0); glVertex2i(p1); glVertex2i(p2); glVertex2i(p3); glVertex2i(p4);
Introduction to OpenGL Programming
Lecture 2 Review OpenGL Libraries Graphics Overview Rendering Pipeline OpenGL command structure.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
12/22/ :38 1 Comp 175C - Computer Graphics Dan Hebert Computer Graphics Comp 175 Chapter 3 Instructor: Dan Hebert.
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
Introduction to OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP.
Introduction to Graphics Programming. Graphics API.
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.
OpenGL API 2D Graphic Primitives
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Lab 3 Geometric Drawing Lab 3 Geometric Drawing.
Starting to draw dealing with Windows which libraries? clipping
גרפיקה ממוחשבת: מבוא ל-OpenGL
Drawing in the plane 455.
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Introduction to OpenGL
OpenGL program.
Starting to draw dealing with Windows which libraries? clipping
University of North Carolina at Greensboro
Presentation transcript:

Chi-Cheng Lin, Winona State University CS430 Computer Graphics Graphics Programming and OpenGL

2 Topics l Get Started with Graphics Programming l OpenGL l Drawing Basic Primitives l Interaction

3 Get Started with Graphics Programming l What are required? zSoftware yGraphics library (libraries) zHardware yDisplay to show graphics yInput device(s) for interaction zProgrammer’s passion (and patient :) ywilling to spend time writing and testing programs to produce different graphics with different parameters (i.e., doing experiments) to master graphics programming

4 Get Started with Graphics Programming l Steps zInitialization ySet up display mode (graphics mode) ySet up coordinate system –Coordinates x and y in (x, y) measured in pixels zBasic primitives ypoint(x,y,color), line(x1,y1,x2,y2), moveto(x,y), lineto(x,y), and cp: current pen position

5 Device-Independent Programming l Why device-independent programming? zIt’s hard to port one graphics application from one environment to another yDifferent commands required to drive different displays yDifferent libraries zDevice-independent programming make the task of porting (same program: compile  run  identical output) easy

6 OpenGL l Tool to support device-independent graphics programming zSame program works on a different environment with OpenGL library installed zExamples yX-Windows – UNIX – SUN yX-Windows – Linux – PC (MESA) yMS-Windows - PC l API, underlying hardware/OS details hidden

7 OpenGL l Powerful 3D graphics drawing l Suitable for 2D graphics, too l Unified approach to producing pictures l Libraries zGLU: OpenGL Utility Library yRoutines using lower-level OpenGL commands yPart of OpenGL zGLUT: OpenGL Utility Toolkit yWindow-system-independent toolkit yWritten by Mark Kilgard

8 Window-Based Programming l Event-driven programming zEvent queue receives messages zCallback functions created for events and executed when events occur

9 Window-Based Programming l Skeleton of even-driven OpenGL program void main() { initialize things Create a screen window glutDisplayFunc(myDisplay);//register the redraw function glutReshapeFunc(myReshape);//register the reshape function glutMouseFunc(myMouse);//register the mouse action function glutKeyboardFunc(myKeyboard);//register the keyboard action function perhaps initialize other things glutMainLoop();//enter the unending main loop } all of the callback functions are defined here

10 //appropriate #includes go here -see Appendix 1 void main(int argc, char** argv) { glutInit(&argc, argv);//initialize the toolkit glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); //set the display mode glutInitWindowSize(640, 480); //set window size glutInitWindowPosition(100, 150); //set the window position on screen glutCreateWindow("my first attempt"); //open the screen window //register the callback functions glutDisplayFunc(myDisplay); glutReshapeFunc(myReshape); glutMouseFunc(myMouse); glutKeyboardFunc(myKeyboard); myInit(); //additional initializations as necessary glutMainLoop(); //go into a perpetual loop } Opening a window for drawing

11 Window-Based Programming l “my first attempt” window l Note that (0, 0) is at the lower left corner

12 Drawing Basic Primitives l Vertices glBegin(GL_POINTS); glVertex2i(100, 50); glVertex2i(100, 130); glVertex2i(150, 130); glEnd();

13 Format of OpenGL Commands l Example: A GLU library routine begin with glu A GLUT library routine begins with glut

14 Command Suffixes and Data Types

15 Example on Data Type l Encapsulating OpenGL details in the generic function drawDot() void drawDot(int x,int y)  danger: passes ints {//draw dot at integer point (x,y) glBegin(GL_POINTS); glVertex2i(x,y); glEnd(); } void drawDot(GLint x,GLint y)// OK here {//draw dot at integer point (x,y) glBegin(GL_POINTS); glVertex2i(x,y); glEnd(); }

16 States (Attributes) l Set vertex size zglPointSize(size) l Set primitive (foreground) color zglColor3f(red, green, blue) zE.g., glColor3f(0.0, 0.0, 0.0) l Set background color zglClearColor(red, green, blue, alpha) l Clear entire window to background color zglClear(GL_COLOR_BUFFER_BIT)

17 Coordinate System l Set up in myInit() void myInit(void) { glClearColor(1.0, 1.0, 1.0, 0.0) glColor3f(0.0, 0.0, 0.0) glPointSize(4.0) glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0,640.0,0,480.0); }

18 What should be in myDisplay? void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT) glBegin(GL_POINTS); glVertex2i(100, 50); glVertex2i(100, 130); glVertex2i(150, 130); glEnd(); glFlush();// send all output to display }

19 More Primitives l glBegin(constant) vertices glEnd(); defines various primitives with different values of constant zGL_POLYGON: filled polygon zGL_TRIANGLES: triangles zGL_QUAS: quadrilaterals :

20 Interaction l Mouse zglutMouseFunc(myMouse) l Motion zglutMotionFunc(myMovedMouse) l Keyboard zglutKeyboardFunc(myKeyboard)

21 Mouse l Prototype of myMouse zvoid myMouse(int button, int state, int x, int y) zbutton yGLUT_LEFT_BUTTON yGLUT_MIDDLE_BUTTON yGLUT_RIGHT_BUTTON zstate yGLUT_UP yGLUT_DOWN z(x, y) yLocation measured in pixel from upper left corner

22 Motion l Prototype of myMotion zvoid myMovedMouse(int x, int y) z(x, y) yLocation measured in pixel from upper left corner

23 Keyboard l Prototype of myKeyboard zvoid myKeyboard(unsigned int key, int x, int y) zkey yASCII value of the key pressed z(x, y) yLocation of the mouse from upper left corner when the key is pressed