SlideShare a Scribd company logo
1 of 32
CLO1. Demonstrate simple algorithms using OpenGL Graphics primitives and
attributes.
CLO2. Implementation of line drawing and clipping algorithms using OpenGL
functions.
CLO3. Understanding the practical implementation of modelling, rendering,
viewing of objects on both 2D and 3D objects
1
Course Learning Objectives (CLO’s)
Computer Graphics & Visualization
Laboratory with Mini Project(18CSL67)
CO1.Apply the concepts of Computer graphics to create the 2D/3D Graphical Models.
CO2. Explore projections and visible surface detection techniques for display of 3D
scene on 2D screen
CO3. Design and Implement Computer Graphics applications using OpenGL.
C04. Identify and apply various approaches for rendering, lighting and shading to
animate real world problems using OpenGL
2
Course Outcomes (CO’s)
Computer Graphics & Visualization
Laboratory with Mini Project(18CSL67)
1. Implement Brenham’s line drawing algorithm for all types of slope.
2. Create and rotate a triangle about the origin and a fixed point.
3. Draw a color cube and spin it using OpenGL transformation matrices.
4. Draw a color cube and allow the user to move the camera suitably to
experiment with perspective viewing.
5. Clip the lines using Cohen-Sutherland algorithm
3
PART-A
Computer Graphics & Visualization
Laboratory with Mini Project(18CSL67)
6. To draw a simple shaded scene consisting of a tea pot on a table.
Define suitably the position and properties of the light source along
with the properties of the surfaces of the solid object used in the
scene
7. Design, develop and implement recursively subdivide a tetrahedron to
form 3D sierpinski gasket. The number of recursive steps is to be
specified by the user.
8. Develop a menu driven program to animate a flag using Bezier Curve
algorithm.
9. Develop a menu driven program to fill the polygon using scan line
4
PART-A
Computer Graphics & Visualization
Laboratory with Mini Project (18CSL67)
Develop mini project on the topics mentioned below or similar
applications using Open GL API. Consider all types of attributes like
color, thickness, styles, font, background, speed etc., while doing
mini project.
(During the practical exam: the students should demonstrate and answer
Viva-Voce)
5
PART-B
Computer Graphics & Visualization
Laboratory with Mini Project (18CSL67)
OpenGL
What is OpenGL
 OpenGL is a software interface to graphics hardware.
 Graphics rendering API
 Rendering?–converting geometric or
mathematical object descriptions into frame
buffer values.
 high-quality color images composed of geometric and
image primitives
 window system independent
 operating system independent
 This interface consists of 150 distinct commands they are
used to specify the object and operations needed to
produce interactive 2D & 3D graphics application.
Currently there are 3 major graphics
APIs currently being used right now.
• OpenGL. OpenGL was first released in 1992, by
Silicon Graphics.
• Direct3D. Microsoft DirectX is an advanced suite of
multimedia APIs built into Microsoft Windows® operating
systems. ...
• Metal. Metal provides near-direct access to the graphics
processing unit (GPU), enabling you to maximize ... Get
sample code to see how Metal APIs are implemented.
(The OpenGL Interface)
In OpenGL all graphic functions are stored in three Libraries
1. GL (OpenGL in windows)- The functions in this library have names
that begin with letters gl and are stored in library GL
2. GLU (OpenGL Utility Library)- This library uses GL functions and
contains code for generating objects and simplifying views.
Function GLU library begin with “glu". They are used for 1.
Setting up matrices for viewing transformation 2. Rendering
surfaces 3. performing polygon tessellation.
3. GLUT(OpenGL Utility Toolkit)- Used to interface with the window
system and to get input from external devices.
 GLX, Xlib and Xtk are used by x-windows
Frame
Buffer
OpenGL
Application
Program
GLU
GL
GLUT
GLX
Xlib, Xtk
8
Abstractions
GLUT
Windowing toolkit (key, mouse handler, window events)
GLU
• Viewing –perspective/orthographic
• Image scaling, polygon tessellation
• Sphere, cylinders, quadratic surfaces
GL
• Primitives - points, line, polygons
• Shading and Colour
• Translation, rotation, scaling
• Viewing, Clipping, Texture
• Hidden surface removal
To define the primitives or objects
glBegin(GL_LINES); // Draw line
glVertex2i(180, 15); // - first point
glVertex2i(10, 145); // - second point
glEnd; // Ready with line
 Definition of the primitives are defined between glBegin and glEnd functions
 Type of the primitive specified as parameter in glBegin
 glEnd doesn’t contain any parameters
 Based on the type of primitives or objects no of vertices are defined within
glBegin and glEnd functions.
OpenGL Command Formats
11
glVertex3fv( v )
Number of
components
2 - (x,y)
3 - (x,y,z)
4 - (x,y,z,w)
Data Type
b - byte
ub - unsigned byte
s - short
us - unsigned short
i - int
ui - unsigned int
f - float
d - double
Vector
omit “v” for
scalar form
glVertex2f( x, y )
OpenGL Geometric Primitives
 All geometric primitives are specified by vertices
12
GL_QUAD_STRIP
GL_POLYGON
GL_TRIANGLE_STRIP GL_TRIANGLE_FAN
GL_POINTS
GL_LINES
GL_LINE_LOOP
GL_LINE_STRIP
GL_TRIANGLES
GL_QUADS
GL_POINTS each vertex is displayed as one
pixel
GL_LINES  Takes successive pair of
vertices(lines are disconnected)
GL_LINE_STRIP Successive vertices are
connected
GL_LINE_LOOP polyline are closed.
POLYGON
Polygon is an object that has
1.Border that can be describe by line
loop.
2.Defined interiors.
3 properties of a polygon
Simple, Convex, Flat
 If no two edges of a polygon cross each other it’s a
simple polygon.
simple not simple
 An object is convex, a line segment between two
points on the boundary never goes outside the
polygon.
convex non-convex
Suffix Data Type Typical Corresponding C-
Language Type
OpenGL Type
Definition
b 8-bit integer signed char GLbyte
s 16-bit integer Short GLshort
i 32-bit integer int or long GLint
f 32-bit floating-
point
Float GLfloat
d 64-bit floating-
point
Double GLdouble
ub 8-bit unsigned
integer
unsigned char GLubyte,
GLboolean
us 16-bit unsigned
integer
unsigned short GLushort
ui 32-bit unsigned
integer
unsigned int or unsigned long GLuint,
Glbitfield
Data types supported in OpenGL
Control functions
 Interface between the graphics system and operating system (GLUT)
 Interaction with the window system
 Window displays the content of frame buffer
 Position of window are measured in pixels
1. glutInit(int *argc, char **argv) initializes GLUT and processes any command line arguments
glutInit() should be called before any other GLUT routine.
Eg: glutInit(&argc, argv)
2. glutInitDisplayMode(unsigned int mode)
 specifies whether to use an RGBA or color-index color model.
 specify whether we want a single- or double-buffered window.
 we can use this routine to indicate that we want the window to have an associated depth, stencil,
and/or accumulation buffer.
 Eg: If we want a window with double buffering, the RGBA color model, and a depth buffer, we might
call
3. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH).
 Eg: Single buffer with RGB glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB).16
 glutInitWindowPosition(int x, int y) - Specifies the screen location for the upper-left corner of
window.
Eg: glutInitWindowPosition(0,0); // Place window top left on display
 glutInitWindowSize(int width, int size) - Specifies the size in pixels of the window.
Eg: glutInitWindowSize(500,500); //500x500 window
 int glutCreateWindow(char *string) - Creates a window with an OpenGL context. It returns a unique
identifier for the new window. Until glutMainLoop() is called , the window is not yet displayed.
Eg: glutCreateWindow(“Sierpinski Gasket”);
 glutDisplayFunc(void (*func)(void)) - It is the first and most important event callback function .
Whenever GLUT determines the contents of the window need to be redisplayed, the callback function
registered by glutDisplayFunc() is executed. Therefore, we should put all the routines you need to
redraw the scene in the display callback function.
 glutMainLoop(void)- All windows that have been created are now shown, and rendering to those
windows is now effective. Event processing begins, and the registered display callback is triggered.
Once this loop is entered, it is never exited.
Aspect Ratio and View ports: void glViewport(Glint x, Glint y, Glsizei w, Glsizei h)
(x,y)-Lower left corner of view port, w:h is the aspect ratio
17
 glFlush forces all such buffers to be emptied and the OpenGL functions to be
processed
 This is simply a routine to force execution of our OpenGL functions, which
are stored by computer systems in buffers in different locations, depending on
how OpenGL is implemented. On a busy network, for example, there could be
delays in processing some buffers.
Window size and window position
OpenGL syntax
 Functions:
glFunction: glBegin, glClear, glVertex, …
 Constants:
GL_CONSTANT: GL_2D, GL_LINE
 Datatypes:
GLtype: GLbyte, GLint, GLfloat
Example
glClearColor(1.0,1.0,1.0,0.0);// Background color
glMatrixMode(GL_PROJECTION); // Set transformation
glLoadIdentity;
gluOrtho2D(0, 200, 0, 150);
glClear(GL_COLOR_BUFFER_BIT); // Clear background
glColor3f(1.0, 0.0, 0.0); // Set color to red
glBegin(GL_LINES); // Draw line
glVertex2i(180, 15); // - first point
glVertex2i(10, 145); // - second point
glEnd; // Ready with line
glFlush; // Send
Header Files
 In all of our graphics programs, we will need to include the header file for the
OpenGL core library. For most applications we will also need GLU, and on many
systems we will need to include the header file for the window system. For
instance, with Microsoft Windows, the header file that accesses the WGL routines
is windows.h. This header file must be listed before the OpenGL and GLU
 header files because it contains macros needed by the Microsoft Windows
version of the OpenGL libraries. So the source file in this case would begin
with
 #include <windows.h>
 #include <GL/gl.h>
 #include <GL/glu.h>
Header file
 However, if we use GLUT to handle the window-managing operations, we do
not need to include gl.h and glu.h because GLUT ensures that these will be
included correctly. Thus, we can replace the header files for OpenGL and GLU
with
 #include <GL/glut.h>
 (We could include gl.h and glu.h as well, but doing so would be redundant and
could affect program portability.) On some systems, the header files for
OpenGL and GLUT routines are found in different places in the filesystem. For
instance,
 on Apple OS X systems, the header file inclusion statement would be
 #include <GLUT/glut.h
The following is a main program that works for most graphics applications
#include <GL/glut.h>
 void display(void)
 {
 glClear( GL_COLOR_BUFFER_BIT);
 glColor3f(1.0, 0.0, 0.0);
 glBegin(GL_LINES);
 glVertex3f(2.0, 4.0, 0.0);
 glVertex3f(8.0, 4.0, 0.0);
 glEnd();
 glFlush();
 }
24
The following is a main program that works for most graphics applications
#include <GL/glut.h>
void main(int *argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow(“ Sample program”);
glutdisplayFunc(display);
myinit();
glutMainLoop();
}
25
Example
Example 3D
Aim: Draw two rectangular boxes
1. Set up viewing transformation
2. Specify the colors
3. Draw the objects
Example 3D
// Set up viewing transformation
glViewport(0, 0, 500, 500); // Select part of window
glMatrixMode(GL_PROJECTION); // Set projection
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 4.0, 20.0);
glMatrixMode(GL_MODELVIEW); // Set camera
glLoadIdentity();
gluLookAt(3.0, 6.0, 5.0, - eye point
1.0, 0.0, 0.0, - center point
0.0, 0.0, 1.0); - up axis
Example 3D
// Clear background
glClearColor(1.0,1.0,1.0,0.0);// Background color
glClear(GL_COLOR_BUFFER_BIT); // Clear background
// Set color
glColor3f(0.0, 0.0, 0.0); // Set color to black
Example 3D
// Draw two rectangular boxes
glutWireCube(1.0); // unit box around origin
glTranslatef(2.0, 0.0, 0.0); // move in x-direction
glRotatef(30, 0.0, 0.0, 1.0); // rotate 30 degrees
around z-axis
glScalef(1.0, 1.0, 2.0); // scale in z-direction
glutWireCube(1.0); // translated, rotated, scaled box
Example 3D
glutWireCube(1.0); // unit box around origin
glTranslatef(3.0, 0.0, 0.0); // move in x-direction
glRotatef(30, 0.0, 0.0, 1.0); // rotate 30 degrees
around z-axis
glScalef(1.0, 1.0, 2.0); // scale in z-direction
glutWireCube(1.0); // translated, rotated, scaled box
Note:
• Objects are drawn in the current local axis-frame;
• With transformations this frame can be changed.
openGL basics for sample program.ppt

More Related Content

Similar to openGL basics for sample program.ppt

OpenGL Introduction.
OpenGL Introduction.OpenGL Introduction.
OpenGL Introduction.Girish Ghate
 
COMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORTCOMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORTvineet raj
 
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...ICS
 
Lab Practices and Works Documentation / Report on Computer Graphics
Lab Practices and Works Documentation / Report on Computer GraphicsLab Practices and Works Documentation / Report on Computer Graphics
Lab Practices and Works Documentation / Report on Computer GraphicsRup Chowdhury
 
Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming I💻 Anton Gerdelan
 
Computer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptxComputer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptxAnandM62785
 
OpenGL ES based UI Development on TI Platforms
OpenGL ES based UI Development on TI PlatformsOpenGL ES based UI Development on TI Platforms
OpenGL ES based UI Development on TI PlatformsPrabindh Sundareson
 
Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011Prabindh Sundareson
 
CS 354 Viewing Stuff
CS 354 Viewing StuffCS 354 Viewing Stuff
CS 354 Viewing StuffMark Kilgard
 
1 introduction computer graphics
1 introduction computer graphics1 introduction computer graphics
1 introduction computer graphicscairo university
 
Interactive 3D graphics for web with three.js, Andrey Vedilin, DataArt
Interactive  3D graphics for web with three.js, Andrey Vedilin, DataArtInteractive  3D graphics for web with three.js, Andrey Vedilin, DataArt
Interactive 3D graphics for web with three.js, Andrey Vedilin, DataArtAlina Vilk
 
Mini Project final report on " LEAKY BUCKET ALGORITHM "
Mini Project final report on " LEAKY BUCKET ALGORITHM "Mini Project final report on " LEAKY BUCKET ALGORITHM "
Mini Project final report on " LEAKY BUCKET ALGORITHM "Nikhil Jain
 
13th kandroid OpenGL and EGL
13th kandroid OpenGL and EGL13th kandroid OpenGL and EGL
13th kandroid OpenGL and EGLJungsoo Nam
 
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with QtConvert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with QtICS
 

Similar to openGL basics for sample program.ppt (20)

OpenGL Introduction.
OpenGL Introduction.OpenGL Introduction.
OpenGL Introduction.
 
COMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORTCOMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORT
 
Bai 1
Bai 1Bai 1
Bai 1
 
Opengl (1)
Opengl (1)Opengl (1)
Opengl (1)
 
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
 
Lab Practices and Works Documentation / Report on Computer Graphics
Lab Practices and Works Documentation / Report on Computer GraphicsLab Practices and Works Documentation / Report on Computer Graphics
Lab Practices and Works Documentation / Report on Computer Graphics
 
Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming I
 
Computer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptxComputer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptx
 
OpenGL ES based UI Development on TI Platforms
OpenGL ES based UI Development on TI PlatformsOpenGL ES based UI Development on TI Platforms
OpenGL ES based UI Development on TI Platforms
 
Introduction to OpenGL.ppt
Introduction to OpenGL.pptIntroduction to OpenGL.ppt
Introduction to OpenGL.ppt
 
Graphics Libraries
Graphics LibrariesGraphics Libraries
Graphics Libraries
 
Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011
 
CS 354 Viewing Stuff
CS 354 Viewing StuffCS 354 Viewing Stuff
CS 354 Viewing Stuff
 
Arkanoid Game
Arkanoid GameArkanoid Game
Arkanoid Game
 
1 introduction computer graphics
1 introduction computer graphics1 introduction computer graphics
1 introduction computer graphics
 
Interactive 3D graphics for web with three.js, Andrey Vedilin, DataArt
Interactive  3D graphics for web with three.js, Andrey Vedilin, DataArtInteractive  3D graphics for web with three.js, Andrey Vedilin, DataArt
Interactive 3D graphics for web with three.js, Andrey Vedilin, DataArt
 
Mini Project final report on " LEAKY BUCKET ALGORITHM "
Mini Project final report on " LEAKY BUCKET ALGORITHM "Mini Project final report on " LEAKY BUCKET ALGORITHM "
Mini Project final report on " LEAKY BUCKET ALGORITHM "
 
Open gles
Open glesOpen gles
Open gles
 
13th kandroid OpenGL and EGL
13th kandroid OpenGL and EGL13th kandroid OpenGL and EGL
13th kandroid OpenGL and EGL
 
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with QtConvert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
 

Recently uploaded

Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptAfnanAhmad53
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...jabtakhaidam7
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...ppkakm
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...drmkjayanthikannan
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesChandrakantDivate1
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfsumitt6_25730773
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...Amil baba
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxNANDHAKUMARA10
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdfKamal Acharya
 

Recently uploaded (20)

Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .ppt
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Signal Processing and Linear System Analysis
Signal Processing and Linear System AnalysisSignal Processing and Linear System Analysis
Signal Processing and Linear System Analysis
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To Curves
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptx
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 

openGL basics for sample program.ppt

  • 1. CLO1. Demonstrate simple algorithms using OpenGL Graphics primitives and attributes. CLO2. Implementation of line drawing and clipping algorithms using OpenGL functions. CLO3. Understanding the practical implementation of modelling, rendering, viewing of objects on both 2D and 3D objects 1 Course Learning Objectives (CLO’s) Computer Graphics & Visualization Laboratory with Mini Project(18CSL67)
  • 2. CO1.Apply the concepts of Computer graphics to create the 2D/3D Graphical Models. CO2. Explore projections and visible surface detection techniques for display of 3D scene on 2D screen CO3. Design and Implement Computer Graphics applications using OpenGL. C04. Identify and apply various approaches for rendering, lighting and shading to animate real world problems using OpenGL 2 Course Outcomes (CO’s) Computer Graphics & Visualization Laboratory with Mini Project(18CSL67)
  • 3. 1. Implement Brenham’s line drawing algorithm for all types of slope. 2. Create and rotate a triangle about the origin and a fixed point. 3. Draw a color cube and spin it using OpenGL transformation matrices. 4. Draw a color cube and allow the user to move the camera suitably to experiment with perspective viewing. 5. Clip the lines using Cohen-Sutherland algorithm 3 PART-A Computer Graphics & Visualization Laboratory with Mini Project(18CSL67)
  • 4. 6. To draw a simple shaded scene consisting of a tea pot on a table. Define suitably the position and properties of the light source along with the properties of the surfaces of the solid object used in the scene 7. Design, develop and implement recursively subdivide a tetrahedron to form 3D sierpinski gasket. The number of recursive steps is to be specified by the user. 8. Develop a menu driven program to animate a flag using Bezier Curve algorithm. 9. Develop a menu driven program to fill the polygon using scan line 4 PART-A Computer Graphics & Visualization Laboratory with Mini Project (18CSL67)
  • 5. Develop mini project on the topics mentioned below or similar applications using Open GL API. Consider all types of attributes like color, thickness, styles, font, background, speed etc., while doing mini project. (During the practical exam: the students should demonstrate and answer Viva-Voce) 5 PART-B Computer Graphics & Visualization Laboratory with Mini Project (18CSL67)
  • 6. OpenGL What is OpenGL  OpenGL is a software interface to graphics hardware.  Graphics rendering API  Rendering?–converting geometric or mathematical object descriptions into frame buffer values.  high-quality color images composed of geometric and image primitives  window system independent  operating system independent  This interface consists of 150 distinct commands they are used to specify the object and operations needed to produce interactive 2D & 3D graphics application.
  • 7. Currently there are 3 major graphics APIs currently being used right now. • OpenGL. OpenGL was first released in 1992, by Silicon Graphics. • Direct3D. Microsoft DirectX is an advanced suite of multimedia APIs built into Microsoft Windows® operating systems. ... • Metal. Metal provides near-direct access to the graphics processing unit (GPU), enabling you to maximize ... Get sample code to see how Metal APIs are implemented.
  • 8. (The OpenGL Interface) In OpenGL all graphic functions are stored in three Libraries 1. GL (OpenGL in windows)- The functions in this library have names that begin with letters gl and are stored in library GL 2. GLU (OpenGL Utility Library)- This library uses GL functions and contains code for generating objects and simplifying views. Function GLU library begin with “glu". They are used for 1. Setting up matrices for viewing transformation 2. Rendering surfaces 3. performing polygon tessellation. 3. GLUT(OpenGL Utility Toolkit)- Used to interface with the window system and to get input from external devices.  GLX, Xlib and Xtk are used by x-windows Frame Buffer OpenGL Application Program GLU GL GLUT GLX Xlib, Xtk 8
  • 9. Abstractions GLUT Windowing toolkit (key, mouse handler, window events) GLU • Viewing –perspective/orthographic • Image scaling, polygon tessellation • Sphere, cylinders, quadratic surfaces GL • Primitives - points, line, polygons • Shading and Colour • Translation, rotation, scaling • Viewing, Clipping, Texture • Hidden surface removal
  • 10. To define the primitives or objects glBegin(GL_LINES); // Draw line glVertex2i(180, 15); // - first point glVertex2i(10, 145); // - second point glEnd; // Ready with line  Definition of the primitives are defined between glBegin and glEnd functions  Type of the primitive specified as parameter in glBegin  glEnd doesn’t contain any parameters  Based on the type of primitives or objects no of vertices are defined within glBegin and glEnd functions.
  • 11. OpenGL Command Formats 11 glVertex3fv( v ) Number of components 2 - (x,y) 3 - (x,y,z) 4 - (x,y,z,w) Data Type b - byte ub - unsigned byte s - short us - unsigned short i - int ui - unsigned int f - float d - double Vector omit “v” for scalar form glVertex2f( x, y )
  • 12. OpenGL Geometric Primitives  All geometric primitives are specified by vertices 12 GL_QUAD_STRIP GL_POLYGON GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_POINTS GL_LINES GL_LINE_LOOP GL_LINE_STRIP GL_TRIANGLES GL_QUADS
  • 13. GL_POINTS each vertex is displayed as one pixel GL_LINES  Takes successive pair of vertices(lines are disconnected) GL_LINE_STRIP Successive vertices are connected GL_LINE_LOOP polyline are closed. POLYGON Polygon is an object that has 1.Border that can be describe by line loop. 2.Defined interiors. 3 properties of a polygon Simple, Convex, Flat
  • 14.  If no two edges of a polygon cross each other it’s a simple polygon. simple not simple  An object is convex, a line segment between two points on the boundary never goes outside the polygon. convex non-convex
  • 15. Suffix Data Type Typical Corresponding C- Language Type OpenGL Type Definition b 8-bit integer signed char GLbyte s 16-bit integer Short GLshort i 32-bit integer int or long GLint f 32-bit floating- point Float GLfloat d 64-bit floating- point Double GLdouble ub 8-bit unsigned integer unsigned char GLubyte, GLboolean us 16-bit unsigned integer unsigned short GLushort ui 32-bit unsigned integer unsigned int or unsigned long GLuint, Glbitfield Data types supported in OpenGL
  • 16. Control functions  Interface between the graphics system and operating system (GLUT)  Interaction with the window system  Window displays the content of frame buffer  Position of window are measured in pixels 1. glutInit(int *argc, char **argv) initializes GLUT and processes any command line arguments glutInit() should be called before any other GLUT routine. Eg: glutInit(&argc, argv) 2. glutInitDisplayMode(unsigned int mode)  specifies whether to use an RGBA or color-index color model.  specify whether we want a single- or double-buffered window.  we can use this routine to indicate that we want the window to have an associated depth, stencil, and/or accumulation buffer.  Eg: If we want a window with double buffering, the RGBA color model, and a depth buffer, we might call 3. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH).  Eg: Single buffer with RGB glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB).16
  • 17.  glutInitWindowPosition(int x, int y) - Specifies the screen location for the upper-left corner of window. Eg: glutInitWindowPosition(0,0); // Place window top left on display  glutInitWindowSize(int width, int size) - Specifies the size in pixels of the window. Eg: glutInitWindowSize(500,500); //500x500 window  int glutCreateWindow(char *string) - Creates a window with an OpenGL context. It returns a unique identifier for the new window. Until glutMainLoop() is called , the window is not yet displayed. Eg: glutCreateWindow(“Sierpinski Gasket”);  glutDisplayFunc(void (*func)(void)) - It is the first and most important event callback function . Whenever GLUT determines the contents of the window need to be redisplayed, the callback function registered by glutDisplayFunc() is executed. Therefore, we should put all the routines you need to redraw the scene in the display callback function.  glutMainLoop(void)- All windows that have been created are now shown, and rendering to those windows is now effective. Event processing begins, and the registered display callback is triggered. Once this loop is entered, it is never exited. Aspect Ratio and View ports: void glViewport(Glint x, Glint y, Glsizei w, Glsizei h) (x,y)-Lower left corner of view port, w:h is the aspect ratio 17
  • 18.  glFlush forces all such buffers to be emptied and the OpenGL functions to be processed  This is simply a routine to force execution of our OpenGL functions, which are stored by computer systems in buffers in different locations, depending on how OpenGL is implemented. On a busy network, for example, there could be delays in processing some buffers.
  • 19. Window size and window position
  • 20. OpenGL syntax  Functions: glFunction: glBegin, glClear, glVertex, …  Constants: GL_CONSTANT: GL_2D, GL_LINE  Datatypes: GLtype: GLbyte, GLint, GLfloat
  • 21. Example glClearColor(1.0,1.0,1.0,0.0);// Background color glMatrixMode(GL_PROJECTION); // Set transformation glLoadIdentity; gluOrtho2D(0, 200, 0, 150); glClear(GL_COLOR_BUFFER_BIT); // Clear background glColor3f(1.0, 0.0, 0.0); // Set color to red glBegin(GL_LINES); // Draw line glVertex2i(180, 15); // - first point glVertex2i(10, 145); // - second point glEnd; // Ready with line glFlush; // Send
  • 22. Header Files  In all of our graphics programs, we will need to include the header file for the OpenGL core library. For most applications we will also need GLU, and on many systems we will need to include the header file for the window system. For instance, with Microsoft Windows, the header file that accesses the WGL routines is windows.h. This header file must be listed before the OpenGL and GLU  header files because it contains macros needed by the Microsoft Windows version of the OpenGL libraries. So the source file in this case would begin with  #include <windows.h>  #include <GL/gl.h>  #include <GL/glu.h>
  • 23. Header file  However, if we use GLUT to handle the window-managing operations, we do not need to include gl.h and glu.h because GLUT ensures that these will be included correctly. Thus, we can replace the header files for OpenGL and GLU with  #include <GL/glut.h>  (We could include gl.h and glu.h as well, but doing so would be redundant and could affect program portability.) On some systems, the header files for OpenGL and GLUT routines are found in different places in the filesystem. For instance,  on Apple OS X systems, the header file inclusion statement would be  #include <GLUT/glut.h
  • 24. The following is a main program that works for most graphics applications #include <GL/glut.h>  void display(void)  {  glClear( GL_COLOR_BUFFER_BIT);  glColor3f(1.0, 0.0, 0.0);  glBegin(GL_LINES);  glVertex3f(2.0, 4.0, 0.0);  glVertex3f(8.0, 4.0, 0.0);  glEnd();  glFlush();  } 24
  • 25. The following is a main program that works for most graphics applications #include <GL/glut.h> void main(int *argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(0,0); glutCreateWindow(“ Sample program”); glutdisplayFunc(display); myinit(); glutMainLoop(); } 25
  • 27. Example 3D Aim: Draw two rectangular boxes 1. Set up viewing transformation 2. Specify the colors 3. Draw the objects
  • 28. Example 3D // Set up viewing transformation glViewport(0, 0, 500, 500); // Select part of window glMatrixMode(GL_PROJECTION); // Set projection glLoadIdentity(); glFrustum(-1.0, 1.0, -1.0, 1.0, 4.0, 20.0); glMatrixMode(GL_MODELVIEW); // Set camera glLoadIdentity(); gluLookAt(3.0, 6.0, 5.0, - eye point 1.0, 0.0, 0.0, - center point 0.0, 0.0, 1.0); - up axis
  • 29. Example 3D // Clear background glClearColor(1.0,1.0,1.0,0.0);// Background color glClear(GL_COLOR_BUFFER_BIT); // Clear background // Set color glColor3f(0.0, 0.0, 0.0); // Set color to black
  • 30. Example 3D // Draw two rectangular boxes glutWireCube(1.0); // unit box around origin glTranslatef(2.0, 0.0, 0.0); // move in x-direction glRotatef(30, 0.0, 0.0, 1.0); // rotate 30 degrees around z-axis glScalef(1.0, 1.0, 2.0); // scale in z-direction glutWireCube(1.0); // translated, rotated, scaled box
  • 31. Example 3D glutWireCube(1.0); // unit box around origin glTranslatef(3.0, 0.0, 0.0); // move in x-direction glRotatef(30, 0.0, 0.0, 1.0); // rotate 30 degrees around z-axis glScalef(1.0, 1.0, 2.0); // scale in z-direction glutWireCube(1.0); // translated, rotated, scaled box Note: • Objects are drawn in the current local axis-frame; • With transformations this frame can be changed.

Editor's Notes

  1. 11
  2. 12