Write a Simple Program with OpenGL & GLUT. Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible

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…
CS 4731 Lecture 2: Intro to 2D, 3D, OpenGL and GLUT (Part I) Emmanuel Agu.
Hwk1- A Tutorial of OPENGL ver2.0. We will introduce… Draw a window by OpenGL Draw one/many polygons by OpenGL Rotate/Translate Matrix Push/PopMatrix.
Chapter 2 Using OpenGL Chih-Kuo Yeh.  Addison Wesley OpenGL SuperBible 4 th Edition Jun 2007 Author: Richard S. Wright, Jr. Benjamin Lipchak Nicholas.
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 Basics Donghui Han. Assignment Grading Visual Studio Glut Files of four types needed: – Source code:.cpp,.h – Executable file:.exe (build in release.
OpenGL Basics.
Computer Graphics (Fall 2008) COMS 4160, Lecture 9: OpenGL 1
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,
OpenGL (I). What is OpenGL (OGL)? OGL is a 3D graphics & modeling library Can also use it to draw 2D objects.
InteractionHofstra University1 Graphics Programming Input and Interaction.
Computer Graphics (Fall 2005) COMS 4160, Lecture 10: OpenGL 1
CSE 494/598 Intro to Applied Computer Graphics Anshuman Razdan DCST AR's Web Page AR's Web Page
InteractionHofstra University1 Graphics Programming Input and Interaction.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 GLUT Callback Functions.
Sierpinski Gasket Program
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.
Development of Interactive 3D Virtual World Applications
Introduction to OpenGL Keng Shih-Ling 2003 Spring.
Write a Simple Program with OpenGL & GLUT. Books and Web Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible.
Programming with OpenGL and GLUT
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.
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
1 Working with Callbacks Yuanfeng Zhou Shandong University.
Interaction with Graphics System
Lecture 3 OpenGL.
 “OpenGL (Open Graphics Library) is a standard specification defining a cross- language cross-platform API for writing applications that produce 2D 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:
Managing Multiple Windows with OpenGL and GLUT
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
OpenGL Programming Related Links The Official OpenGL Website OpenGL v1.1 Redbook
Modeling with OpenGL Practice with OpenGL transformations.
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: –
Computer Graphics I, Fall 2010 Working with Callbacks.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
C O M P U T E R G R A P H I C S Jie chen Computer graphic -- Programming with OpenGL 2.
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.
CGGM Lab. Tan-Chi Ho Introduction to OpenGL.
Introduction to OpenGL & HW1 Announcement 劉軒銘, 網媒所 碩二 ICG 2012 Fall.
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.
Introduction to OpenGL Programming
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
Chap 2 Write a Simple OpenGL Program. Preparing 1/2 environment : Microsoft Visual C 、 Microsoft Visual C++.Net Also need : GLUT
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.
CS559: Computer Graphics Lecture 12: OpenGL: ModelView Li Zhang Spring 2010.
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.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Working with Callbacks.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
INTRODUCTION TO OPENGL
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 and GLUT Review Daniel Ritchie Monday, October 3 rd, 2011.
Basic Program with OpenGL and GLUT
Introduction to OpenGL
Computer Graphics Lecture 33
OpenGL Event Driven Programming
The User Interface Lecture 2 Mon, Aug 27, 2007.
גרפיקה ממוחשבת: מבוא ל-OpenGL
Introduction to OpenGL
Presentation transcript:

Write a Simple Program with OpenGL & GLUT

Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible

Web

Be Prepared Windows XP, vista, 7 or any other Windows … Microsoft Visual Studio ftp://ca.nctu.edu.tw GLUT

OpenGL Utility Toolkit (GLUT) A window system-independent toolkit to hide the complexity of differing window system APIs. Providing following operations: Initializing and creating window Handling window and input events Drawing basic 3D objects Running the program

How to Use GLUT? Put these 3 files in your project directory. glut.h(Include it!) glut32.lib(Link it!) glut32.dll(Execute with it!)

A Simple OpenGL Program 1/4 #include “ glut.h ” void display(); void reshape(GLsizei, GLsizei); int main(int argc, char** argv){ glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutCreateWindow("sample"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMainLoop(); return 0; }

A Simple OpenGL Program 2/4 void display(){ glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0f, 1.0f, 1.0f); glutSolidTeapot(1.0); glFlush(); }

A Simple OpenGL Program 3/4 void reshape(GLsizei w, GLsizei h){ glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 20.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); }

A Simple OpenGL Program 4/4

GLUT Functions 1/7 void glutInit(int *argcp, char **argv); Initializing the GLUT library Should be called before any other GLUT funcitons void glutInitDisplayMode(unsigned int mode); Specify a display mode for windows created. GLUT_RGB / GLUT_RGBA / GLUT_INDEX GLUT_SINGLE / GLUT_DOUBLE GLUT_DEPTH / GLUT_STENCIL / GLUT_ACCUM

GLUT Functions 2/7 void glutInitWindowSize(int width, int height); void glutInitWindowPosition(int x, int y); Initializing the window position and size. int glutCreateWindow(char *name); Open a window with previous settings.

GLUT Functions 3/7 void glutDisplayFunc(void (*func)(void)); Called whenever the contents of the windows need to be redrawn. Put whatever you wish to draw on screen here. Use glutPostRedisplay() to manually ask GLUT to recall this display function

GLUT Functions 4/7 void glutReshapeFunc(void (*func)(int width, int height)); Called whenever the window is resized or moved. You should always call glViewport() here to resize your viewport.

GLUT Functions 5/7 void glutKeyboardFunc(void (*func)(unsigned char key, int x, int y)); Sets the keyboard callback for the current window. void glutIdleFunc(void (*func)(void)); Sets the global idle callback.

GLUT Functions 6/7 void glutMouseFunc(void (*func)(int button, int state, int x, int y)); sets the mouse callback for the current window. void glutMotionFunc(void (*func)(int x, int y)); set the motion callbacks respectively for the current window.

GLUT Functions 7/7 void glutMainLoop(void); Enter the GLUT processing loop and never return. void glutPostRedisplay(void); marks the current window as needing to be redisplayed.

GLUT Objects GLUT provides the follow objects: Sphere, cube, torus, icosahedron, ocrtahedron, tetrahedron, teapot, dodecahedron, cone. Both wireframe and solid Ex: glutSolidSphere(1.0, 24, 24) Ex: glutWireCube(1.0)

Appendix: Example of Keyboard Callback Function void keyboard(unsigned char key, int x, int y){ printf("you press the key %c \n", key); printf("the mouse is on %d %d \n", x, y); }

Appendix: Example of Mouse Callback Function int startX, startY; void mouse(int button, int state, int x, int y){ if (state == GLUT_DOWN){ startX = x; startY = y; } else if(state == GLUT_UP){ printf("the mouse moves %d %d \n", x - startX, y - startY); }

Appendix: Example of Motion Callback Function void motion(int x, int y){ printf("the mouse is moving to %d %d", x, y); }