NoufNaief.net TA: Nouf Al-harbi.

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
Computer Graphics CSCE 441
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.
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.
OpenGL and Projections
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 1: Background Mohan Sridharan Based on slides created by Edward Angel CS4395: Computer Graphics 1.
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.
Write a Simple Program with OpenGL & GLUT. Books and Web Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible.
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
Computer Graphics Bing-Yu Chen National Taiwan University.
COS 397 Computer Graphics Assoc. Prof. Svetla Boytcheva AUBG 2013 COS 397 Computer Graphics Practical Session №1 Introduction to OpenGL, GLFW and CG.
Introduction to OpenGL and GLUT GLUT. What is OpenGL? An application programming interface (API) A (low-level) Graphics rendering API Generate high-quality.
C O M P U T E R G R A P H I C S Jie chen Computer graphic -- OpenGL Howto.
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.
CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.
Graphics Architectures & OpenGL API Introduction Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
OpenGl Graphics Programming. Introduction OpenGL is a low-level graphics library specification. It makes available to the programmer a small set of geomteric.
Programming with OpenGL Part 1: Background
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. 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.
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 OpenGL Programming Jian-Liang Lin 2002.
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
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.
CGGM Lab. Tan-Chi Ho Introduction to OpenGL.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor.
Computer Graphics Lab 1 OpenGL.
NoufNaief.net 1 TA: Nouf Al-Harbi.
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
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Introduction to OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP.
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.
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.
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
The Human Visual System vs The Pinhole camera
Programming with OpenGL Part 1: Background
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
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
גרפיקה ממוחשבת: מבוא ל-OpenGL
Programming with OpenGL Part 1: Background
Drawing in the plane 455.
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 1: Background
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

NoufNaief.net TA: Nouf Al-harbi

What’s Computer Graphics..? 2 Computer Image Description Computer Graphics

How we look at an image! Color: B/W or color (RGB) Frame: length, width Size: length, width, area, height and volume if 3D Type: Static or animated Content: The scene: Objects, characters Background/ Foreground lighting, shading Textures Viewing angle: camera location

How The computer see an image!  The computer generally sees an image as a set of square points or PIXELS (Picture Elements)  Each Pixel having a defined RGB color  These pixels and their colors are processed to extract information about the image content

COMPUTER GRAPHICS LAB OBJECTIVE  To give you a good practical experience in programming graphics using C++ and OpenGL Introductiom to OpenGL 5

LAB MARKS Introductiom to OpenGL 6

LAB MATERIALS.. NoufNaief.net Introductiom to OpenGL 7

COMPUTER GRAPHICS LAB 1 Introduction to OpenGL

objectives By the end of this lab you will be able to know : What’s OpenGl..? What does it do ? And what doesn’t it do..? What’s GLUT and why do we use it..? Write the 1 st OpenGL program Introductiom to OpenGL 9

What is OpenGL? OpenGL stands of Open Graphical Library It is a software interface to graphics hardware. It consists of about 120 distinct commands to specify the objects and operations needed to produce interactive 3D applications It is developed by many companies and it is free to use You can develop OpenGL-applications without Licensing OpenGL is a system-independent interface it can work with any programming language and any operating system Introductiom to OpenGL 10

What I can do with OpenGL..? This picture may give you an idea of the kinds of things you can do with the OpenGL graphics system This picture is the cover of the ‘Red Book’: OpenGl Programming user guide Introductiom to OpenGL 11

What OpenGL doesn’t do ? Introductiom to OpenGL 12 With OpenGL you must OpenGL doesn’t Work through whatever windowing system controls the particular hardware you're using. GLUT can be used. OpenGL is window system independent  it doesn’t include commands for performing windowing tasks obtaining user input Build up your desired model from a small set of geometric primitive - points, lines, and polygons. OpenGL doesn’t provide commands that allowing you to specify complicated shapes Automobiles parts of the body airplanes

THE SUPPORT LIBRARIES GLU and GLUT Introductiom to OpenGL 13

GLUT The OpenGL Utility Toolkit (GLUT) is a Programming interface It implements a simple windowing application programming interface (API) for OpenGL The toolkit supports the following functionality : Create Display windows. Interactive with input devices and detect user input. An “idle” routine and timers. Utility routines to generate various solid and wire frame objects. Introduction to OpenGL 14

GLU GLU: OpenGL Utility Library provides functions for drawing more complex primitives than those of OpenGL such as curves and surfaces Introductiom to OpenGL 15

OpenGL Basics Function names: Begins with gl. Each component word starts with capital letter. Examples: glClear( ) glClearColor( ) Introductiom to OpenGL 16

OpenGL Basics Basic Constants: Starts with GL Component words are written in Capital letters and separated by underscore ( _ ). Examples: GL_COLOR_BUFFER_BIT GL_POINTS GL_LINES Introductiom to OpenGL 17

OpenGL Basics All the functions in GLUT starts with glut All the functions in GLU starts with glu Introductiom to OpenGL 18

your first OpenGL Program Preparing the graphics work environment We will use VC++ You need to include t hese files to your computer Introductiom to OpenGL 19 Where to put these files? Microsoft Visual Studio/VC98/Lib opengl32.lib glu32.lib glaux.lib glut32.lib Library files Microsoft Visual Studio/VC98/Include/GL Note: all header files are in folder GL gl.h glu.h glaux.h glut.h Header files Windows/system32 Opengl32.dll Glu32.dll Glut32.dll DLL files

your first OpenGL Program Generate a square on a solid background Open VC++ New  source file Write the following code Compile and build it 20 #include void display() { 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(); } int main(int argc, char** argv) { glutInit(&argc,argv); glutCreateWindow("CS447 First OGL Program"); glutDisplayFunc(display); glutMainLoop(); }

your first OpenGL Program You have to link used libraries to your project Select Project/Settings from the main menu. A dialog box appears, select the Link tab. Add the following files to the Object/library modules: opengl32.lib glut32.lib glu32.lib Introductiom to OpenGL 21

your first OpenGL Program To write OpenGL program, we must include these files glut. h glu. h gl. h #include should automatically include the others Introductiom to OpenGL 22 #include 1

your first OpenGL Program T here are 2 functions in our program Display function Main function Each of them calls a number of OpenGL/glut functions Introductiom to OpenGL 23 #include void display() { 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(); } int main(int argc, char** argv) { glutInit(&argc,argv); glutCreateWindow("CS447 First OGL Program"); glutDisplayFunc(display); glutMainLoop(); }

Main Function Commands Initializes GLUT should be called before any OpenGL command takes the arguments from main() Introductiom to OpenGL 24 int main(int argc, char** argv) { glutInit(&argc,argv); glutCreateWindow("CS447 First OGL Program"); glutDisplayFunc(display); glutMainLoop(); }

Main Function Commands  Creates a window on the screen with the title  Parameters: Title of the window would be created  Returns an integer that can be used to refer to the window in multi- window situations. Introductiom to OpenGL 25 int main(int argc, char** argv) { glutInit(&argc,argv); glutCreateWindow("CS447 First OGL Program"); glutDisplayFunc(display); glutMainLoop(); }

Main Function Commands  The function display() is called each time there is a display callback Parameters: A function that contains what we want to draw in the screen Introductiom to OpenGL 26 int main(int argc, char** argv) { glutInit(&argc,argv); glutCreateWindow("CS447 First OGL Program"); glutDisplayFunc(display); glutMainLoop(); } In order to respond to the input event, the application must provide a function – known as a callback function – to handle the event; OpenGL automatically calls the application’s function, passing it the event data.

Main Function Commands Causes the program to enter an event-processing loop Once called, this routine will never return. It will call as necessary any callbacks that have been registered. This statement should be the last one in the main() function Introductiom to OpenGL 27 int main(int argc, char** argv) { glutInit(&argc,argv); glutCreateWindow("CS447 First OGL Program"); glutDisplayFunc(display); glutMainLoop(); }

Display Function Commands called by GLUT when the window is redrawn. we should specify what we want to output to screen. Introductiom to OpenGL 28 void display() { 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(); }

Display Function Commands clears one or more of OpenGL’s buffers. When glClear() is called, each pixel in the buffer is set to the current clear color, which is set to black by default. Parameters : GL_COLOR _BUFFER_BIT: frame buffer, which holds the pixels which will be copied to the window Introductiom to OpenGL 29 void display() { 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(); } OpenGL doesn’t draw its graphics directly to the window. It actually draws into a data structure (an array of pixels) inside OpenGL called the frame-buffer. Periodically, OpenGL copies the pixels in the frame buffer into the window.

Display Function Commands Specifies the beginning of an object of type mode Modes include: GL_POINTS GL_LINES GL_POLYGON, …etc. Introductiom to OpenGL 30 void display() { 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(); }

Display Function Commands glVertex{234}{sifd}(X_coordinate, Y_coordinate,...) {234} Specifies the location of a vertex in two, three, or four dimensions with the types short (s), int (i), float (f), or double (d) Introductiom to OpenGL 31 void display() { 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(); }

Introductiom to OpenGL 32

Display Function Commands Specifies the end of a list of vertices. Introductiom to OpenGL 33 void display() { 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(); }

Display Function Commands instructs OpenGL to make sure the screen is up to date. it causes the contents of any internal OpenGL buffers are “flushed” to the screen Introductiom to OpenGL 34 void display() { 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(); }

REFERENCES: Materials of this lab are prepared using:  An Introduction to Graphics Programming with OpenGL by : Toby Howard, School of Computer Science, University of Manchester  Lighthouse3d:  OpenGL Programming Guide 'The Red Book’  Computer Graphics Lab -1 st semester – by : Ins. Ruwaida Al-harbi & Ins. Nouf Al-harbi  Computer Graphics Lectures – 1 st semester by Dr.Ahmed Ghali Introductiom to OpenGL 35

Introductiom to OpenGL 36