Write a Simple Program with OpenGL & GLUT. Books and Web 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

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.
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.
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.
Interaction with Graphics System
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
Lecture 3 OpenGL.
Write a Simple Program with OpenGL & GLUT. Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible
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.
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);
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: –
1 Chapter 2 Graphics Programming. 2 Using OpenGL in Visual C++ – 1/3 Opengl32.dll and glu32.dll should be in the system folder Opengl32.lib and glu32.lib.
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.
Computer Graphics Lab 1 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
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 OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP.
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.
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.
Basic Program with OpenGL and GLUT
CS380 Lab Spring Myungbae Son.
Introduction to OpenGL
Computer Graphics Lecture 33
The User Interface Lecture 2 Mon, Aug 27, 2007.
גרפיקה ממוחשבת: מבוא ל-OpenGL
Introduction to OpenGL
Presentation transcript:

Write a Simple Program with OpenGL & GLUT

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

Be Prepared Windows XP, or any other Windows … Microsoft Visual Studio 6.0, 7.0 or 8.0 Don ’ t know how to get? Go to ftp://ca.nctu.edu.tw GLUT Please get “ glut bin.zip (117 KB) “

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!)

Setup for a OpenGL Program (VC 6.0) 1/5 Microsoft Visual C Step 1: create a Win32 Console Application project

Setup for a OpenGL Program(VC 6.0) 2/5 Step 2:Press Alt-F7 , brings “ Project Settings ” , select “ Link ” Step 3:add opengl32.lib glu32.lib glut32.lib into Object/library modules

Setup for a OpenGL Program(VC 6.0) 3/5 Microsoft Visual C++.Net Step 1:create Win32 console project

Setup for a OpenGL Program(VC 6.0) 4/5 Step 2: select “ empty project ”

Setup for a OpenGL Program(VC 6.0) 5/5 Step 3:select project / property … / linker / input Step 4: add glut32.lib

Setup for a OpenGL Program(VC7.0) 1/7 Microsoft Visual C New Blank Solution

Setup for a OpenGL Program(VC7.0) 2/7 Microsoft Visual C New Blank Project

Setup for a OpenGL Program(VC7.0) 3/7 New Empty Project

Setup for a OpenGL Program(VC7.0) 4/7 Set properties

Setup for a OpenGL Program(VC7.0) 5/7 Set include to the location of glut.h

Setup for a OpenGL Program(VC7.0) 6/7 Set link to the location of the lib file

Setup for a OpenGL Program(VC7.0) 7/7 Set link input, add the glut32.lib

Setup for a OpenGL Program(VC8.0) 1/8 Microsoft Visual C New Blank Project

Setup for a OpenGL Program(VC8.0) 2/8 New Win32 Project

Setup for a OpenGL Program(VC8.0) 3/8 Next

Setup for a OpenGL Program(VC8.0) 4/8 Use Console application Empty, Finish

Setup for a OpenGL Program(VC8.0) 5/8 Set properties

Setup for a OpenGL Program(VC8.0) 6/8 Set include to the location of glut.h

Setup for a OpenGL Program(VC8.0) 7/8 Set link to the location of the lib file

Setup for a OpenGL Program(VC8.0) 8/8 Set link input,add the glut32.lib

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

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); }