SlideShare a Scribd company logo
OpenGL
Opengl
OpenGL has been around for over 16 years. Its
development is overseen by the Khronos group.

OpenGL has undergone some radical changes in its most
recent release.
OpenGL Architecture

internal state machine
In programmable it is up to the
programmer to not only pass in
the correct information (for
example the color of the vertex)
but also apply this information
to the vertex in the shader.
What is opengl?
Pipeline
Fixed-Function vs.
 Programmability
Related Libraries

GLUT (OpenGL Utility Toolkit)
SDL
GLUT
OpenGL Utility Toolkit
windowing, menus, or input
SDL

The Simple Direct Media Layer

audio, input, 2D graphics, and many other things
WGL
prevent multiple OpenGL applications from interfering with
each other. This is done through the use of a rendering
context

Only one rendering context per thread.

HGLRC wglCreateContext(HDC hDC);

BOOL wglDeleteContext(HGLRC hRC);

BOOL wglMakeCurrent(HDC hDC, HGLRC hRC);
WGL
HGLRC wglGetCurrentContext();


HDC wglGetCurrentDC();
Pixel Formats
typedef struct tagPIXELFORMATDESCRIPTOR {

WORD nSize;
WORD nVersion;
DWORD dwFlags;
BYTE iPixelType;
BYTE cColorBits;
BYTE cRedBits;
BYTE cRedShift;
BYTE cGreenBits;
BYTE cGreenShift; BYTE cBlueBits;
BYTE cBlueShift;
BYTE cAlphaBits;
BYTE cAlphaShift; BYTE cAccumBits;
BYTE cAccumRedBits; BYTE cAccumGreenBits; BYTE cAccumBlueBits; BYTE
cAccumAlphaBits; BYTE cDepthBits;
BYTE cStencilBits; BYTE cAuxBuffers; BYTE iLayerType;
BYTE bReserved;
DWORD dwLayerMask; DWORD dwVisibleMask; DWORD dwDamageMask;

} PIXELFORMATDESCRIPTOR;
Pixel Formats
  nSize

  dwFlags

  iPixelType
        PFD_TYPE_RGBA. RGBA pixels. Each pixel has four
        components in this order: red, green, blue, and alpha.
        PFD_TYPE_COLORINDEX. Paletted mode. Each pixel uses a
        color-index value.

• cColorBits the bits per pixel
Setting the Pixel Format
int ChoosePixelFormat(HDC hdc, CONST
PIXELFORMATDESCRIPTOR *ppfd); (modify pixel
format to match supported and return id for pixel format)

BOOL SetPixelFormat(HDC hdc, int pixelFormat, const
PIXELFORMATDESCRIPTOR *ppfd);
State Functions
void glGetBooleanv(GLenum pname, GLboolean
*params); void glGetDoublev(GLenum pname, GLdouble
*params); void glGetFloatv(GLenum pname, GLfloat
*params); void glGetIntegerv(GLenum pname, GLint
*params);
Enabling and Disabling States

void glEnable(GLenum cap);

void glDisable(GLenum cap);

GLboolean glIsEnabled(GLenum cap);
Querying String Values
const GLubyte *glGetString(GLenum name);

GL_VENDOR , GL_RENDERER , GL_VERSION ,
GL_EXTENSIONS
Finding Errors
GLenum glGetError();
Colors in OpenGL
void glColor (T components);

void glColorv(T components);
Primitives
Handling Primitives
Immediate Mode

Vertex Arrays
Immediate Mode
void glBegin(GLenum mode);

glBegin()

glEnd()

GL_INVALID_OPERATION

void glVertex{234}{dfis}();

void glVertex{234}{dfis}v();
Demo 1
Vertex Arrays
void glEnableClientState(GLenum cap);

void glDisableClientState(GLenum cap);

gl*Pointer()

void glVertexPointer(GLint size, GLenum type, GLsizei
stride, const GLvoid *array);
        size must be 2, 3, or 4 and
        Type can be set to GL_SHORT, GL_INT, GL_FLOAT, or
        GL_DOUBLE.
        Stride padding in bytes between each vertex
Vertex Arrays
void glColorPointer(GLint size, GLenum type, GLsizei
stride, const GLvoid *array);
void glEdgeFlagPointer(GLsizei stride, const GLboolean
*array);
        Array of Boolean

void glNormalPointer(GLenum type, GLsizei stride, const
GLvoid *array); normals always (x,y,z) so no need for the
size.
void glTexCoordPointer(GLint size, GLenum type, GLsizei
stride, const GLvoid *array); size = number of coordinate
per vertex
Rendering Uesing Vertex
           Arrays
void glDrawArrays(GLenum mode, GLint first, GLsizei
count);



void glDrawElements(GLenum mode, GLsizei count,
GLenum type, const GLvoid *indices); [count is the
number of indices that you want to render ]

void glDrawRangeElements(GLenum mode, GLuint start,
GLuint end, GLsizei count, GLenum type, const GLvoid *
indices);
Demo vertix_with_indcies
Rendering Uesing Vertex
           Arrays
void glMultiDrawArrays(GLenum mode, GLint *first,
GLsizei *count, GLsizei primcount)
Vertex Buffer Objects
(VRAM) instead of (RAM)

To use a VBO, you need to perform the following steps:
     1. Generate a name for the buffer.
     2. Bind (activate) the buffer.
     3. Store data in the buffer.
     4. Use the buffer to render the data. 5. Destroy the buffer.
     5. Destroy the buffer.
Generating a Name
void glGenBuffers(GLsizei n, GLuint *buffers);

void glDeleteBuffers(GLsizei n, const GLuint *buffers);
Binding the Buffer
Binding a buffer makes it current; all buffer-related OpenGL calls
and rendering will operate on the currently bound buffer.

void glBindBuffer(GLenum target, GLuint buffer);

target can be GL_ARRAY_BUFFER,
GL_ELEMENT_ARRAY_BUFFER, GL_PIXEL_PACK_BUFFER,
or GL_PIXEL_UNPACK_BUFFER

GL_ARRAY_BUFFER for vertices data and
GL_ELEMENT_ARRAY_BUFFER for indices data.

if buffer is zero, the call will unbind any currently bound buffer.
Filling the Buffer
void glBufferData(GLenum target, GLsizeiptr size, const
GLvoid *data, GLenum usage);
usage is a hint to OpenGL telling it how you intend to use
this buffer. It can be GL_STREAM_DRAW,
GL_STREAM_READ, GL_STREAM_COPY,
GL_STATIC_DRAW, GL_STATIC_READ,
GL_STATIC_COPY, GL_DYNAMIC_DRAW,
GL_DYNAMIC_READ, or GL_DYNAMIC_COPY
Calling glBufferData() on a buffer object that already
contains data will cause the old data to be destroyed and
replaced with the new data
Rendering with Buffers and
      Vertex Arrays
When rendering with VBOs you use gl*Pointer() functions
as an offset.
Demo simple point
Modifying Point Size
void glPointSize(GLfloat size)

If point anti-aliasing is disabled then the point size is
rounded to the nearest integer never zero.

More Related Content

PPTX
What is OpenGL ?
PPTX
OpenGL Introduction
PPT
Programming with OpenGL
PPT
OpenGL Basics
PPT
Open gl
PDF
OpenGL Introduction.
PDF
Introduction of openGL
PDF
Opengl basics
What is OpenGL ?
OpenGL Introduction
Programming with OpenGL
OpenGL Basics
Open gl
OpenGL Introduction.
Introduction of openGL
Opengl basics

What's hot (20)

PPTX
4K Checkerboard in Battlefield 1 and Mass Effect Andromeda
PPT
OpenGL 3.2 and More
PPTX
Approaching zero driver overhead
PPT
SIGGRAPH Asia 2008 Modern OpenGL
PPTX
Shader Programming With Unity
PPTX
Triangle Visibility buffer
PPT
NVIDIA OpenGL 4.6 in 2017
PDF
OpenGL 4.4 - Scene Rendering Techniques
PPTX
Physically Based and Unified Volumetric Rendering in Frostbite
PPTX
Lecture 6 introduction to open gl and glut
PPT
Open Graphics Library
PDF
Unreal Engine 4 Introduction
PDF
OpenGL NVIDIA Command-List: Approaching Zero Driver Overhead
PDF
Modern OpenGL Usage: Using Vertex Buffer Objects Well
PPT
Terrain Rendering in Frostbite using Procedural Shader Splatting (Siggraph 2007)
PDF
Shaders in Unity
PPTX
Game optimization techniques - Most Commons
PPTX
Relic's FX System
PDF
The Rendering Technology of 'Lords of the Fallen' (Game Connection Europe 2014)
PPT
Crysis Next-Gen Effects (GDC 2008)
4K Checkerboard in Battlefield 1 and Mass Effect Andromeda
OpenGL 3.2 and More
Approaching zero driver overhead
SIGGRAPH Asia 2008 Modern OpenGL
Shader Programming With Unity
Triangle Visibility buffer
NVIDIA OpenGL 4.6 in 2017
OpenGL 4.4 - Scene Rendering Techniques
Physically Based and Unified Volumetric Rendering in Frostbite
Lecture 6 introduction to open gl and glut
Open Graphics Library
Unreal Engine 4 Introduction
OpenGL NVIDIA Command-List: Approaching Zero Driver Overhead
Modern OpenGL Usage: Using Vertex Buffer Objects Well
Terrain Rendering in Frostbite using Procedural Shader Splatting (Siggraph 2007)
Shaders in Unity
Game optimization techniques - Most Commons
Relic's FX System
The Rendering Technology of 'Lords of the Fallen' (Game Connection Europe 2014)
Crysis Next-Gen Effects (GDC 2008)
Ad

Viewers also liked (20)

PDF
OpenGL L01-Primitives
PDF
OpenGL Introduction
PDF
OpenGL Transformation
PDF
OpenGL Starter L01
PDF
OpenGL L07-Skybox and Terrian
PPT
NVIDIA's OpenGL Functionality
PDF
Presentatie Lucas Hulsebos DWWA 2008
PPT
Instancing
PDF
XNA L01–Introduction
PDF
Introdução à OpenGL
PPTX
Protein structure by Pauling & corey
PPT
KARNAUGH MAP using OpenGL (KMAP)
PDF
CG OpenGL polar curves & input display color-course 4
PDF
Interaction Design L06 - Tricks with Psychology
PPT
LUDO BOARD GAME OPENGL COMPUTER GRAPHICS
PPTX
Nvidia
PPT
Open gles
PPTX
Computer Graphics Project Development Help with OpenGL computer graphics proj...
PPT
SIGGRAPH 2012: NVIDIA OpenGL for 2012
PDF
Unity L01 - Game Development
OpenGL L01-Primitives
OpenGL Introduction
OpenGL Transformation
OpenGL Starter L01
OpenGL L07-Skybox and Terrian
NVIDIA's OpenGL Functionality
Presentatie Lucas Hulsebos DWWA 2008
Instancing
XNA L01–Introduction
Introdução à OpenGL
Protein structure by Pauling & corey
KARNAUGH MAP using OpenGL (KMAP)
CG OpenGL polar curves & input display color-course 4
Interaction Design L06 - Tricks with Psychology
LUDO BOARD GAME OPENGL COMPUTER GRAPHICS
Nvidia
Open gles
Computer Graphics Project Development Help with OpenGL computer graphics proj...
SIGGRAPH 2012: NVIDIA OpenGL for 2012
Unity L01 - Game Development
Ad

Similar to Opengl presentation (20)

PPT
PDF
Open gl
PPTX
UNIT 1 OPENGL_UPDATED .pptx
PDF
Computer Graphics - Lecture 01 - 3D Programming I
PDF
OpenGL 4.4 Reference Card
PDF
Opengl4 quick reference card
PPT
Introduction to OpenGL modern OpenGL program
PDF
lectureAll-OpenGL-complete-Guide-Tutorial.pdf
PPT
CS 354 Viewing Stuff
PDF
OpenGL L06-Performance
PPTX
3 CG_U1_P2_PPT_3 OpenGL.pptx
PPT
september11.ppt
PPT
Intro to Computer Graphics.ppt
PPT
opengl.ppt
DOC
Data structures graphics library in computer graphics.
PPTX
Computer Graphics with OpenGL presentation Slides.pptx
PPT
Hill ch2ed3
PPTX
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
 
PPTX
Opengl lec 3
Open gl
UNIT 1 OPENGL_UPDATED .pptx
Computer Graphics - Lecture 01 - 3D Programming I
OpenGL 4.4 Reference Card
Opengl4 quick reference card
Introduction to OpenGL modern OpenGL program
lectureAll-OpenGL-complete-Guide-Tutorial.pdf
CS 354 Viewing Stuff
OpenGL L06-Performance
3 CG_U1_P2_PPT_3 OpenGL.pptx
september11.ppt
Intro to Computer Graphics.ppt
opengl.ppt
Data structures graphics library in computer graphics.
Computer Graphics with OpenGL presentation Slides.pptx
Hill ch2ed3
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
 
Opengl lec 3

Opengl presentation

  • 2. Opengl OpenGL has been around for over 16 years. Its development is overseen by the Khronos group. OpenGL has undergone some radical changes in its most recent release.
  • 3. OpenGL Architecture internal state machine In programmable it is up to the programmer to not only pass in the correct information (for example the color of the vertex) but also apply this information to the vertex in the shader.
  • 7. Related Libraries GLUT (OpenGL Utility Toolkit) SDL
  • 9. SDL The Simple Direct Media Layer audio, input, 2D graphics, and many other things
  • 10. WGL prevent multiple OpenGL applications from interfering with each other. This is done through the use of a rendering context Only one rendering context per thread. HGLRC wglCreateContext(HDC hDC); BOOL wglDeleteContext(HGLRC hRC); BOOL wglMakeCurrent(HDC hDC, HGLRC hRC);
  • 12. Pixel Formats typedef struct tagPIXELFORMATDESCRIPTOR { WORD nSize; WORD nVersion; DWORD dwFlags; BYTE iPixelType; BYTE cColorBits; BYTE cRedBits; BYTE cRedShift; BYTE cGreenBits; BYTE cGreenShift; BYTE cBlueBits; BYTE cBlueShift; BYTE cAlphaBits; BYTE cAlphaShift; BYTE cAccumBits; BYTE cAccumRedBits; BYTE cAccumGreenBits; BYTE cAccumBlueBits; BYTE cAccumAlphaBits; BYTE cDepthBits; BYTE cStencilBits; BYTE cAuxBuffers; BYTE iLayerType; BYTE bReserved; DWORD dwLayerMask; DWORD dwVisibleMask; DWORD dwDamageMask; } PIXELFORMATDESCRIPTOR;
  • 13. Pixel Formats nSize dwFlags iPixelType PFD_TYPE_RGBA. RGBA pixels. Each pixel has four components in this order: red, green, blue, and alpha. PFD_TYPE_COLORINDEX. Paletted mode. Each pixel uses a color-index value. • cColorBits the bits per pixel
  • 14. Setting the Pixel Format int ChoosePixelFormat(HDC hdc, CONST PIXELFORMATDESCRIPTOR *ppfd); (modify pixel format to match supported and return id for pixel format) BOOL SetPixelFormat(HDC hdc, int pixelFormat, const PIXELFORMATDESCRIPTOR *ppfd);
  • 16. void glGetBooleanv(GLenum pname, GLboolean *params); void glGetDoublev(GLenum pname, GLdouble *params); void glGetFloatv(GLenum pname, GLfloat *params); void glGetIntegerv(GLenum pname, GLint *params);
  • 17. Enabling and Disabling States void glEnable(GLenum cap); void glDisable(GLenum cap); GLboolean glIsEnabled(GLenum cap);
  • 18. Querying String Values const GLubyte *glGetString(GLenum name); GL_VENDOR , GL_RENDERER , GL_VERSION , GL_EXTENSIONS
  • 20. Colors in OpenGL void glColor (T components); void glColorv(T components);
  • 23. Immediate Mode void glBegin(GLenum mode); glBegin() glEnd() GL_INVALID_OPERATION void glVertex{234}{dfis}(); void glVertex{234}{dfis}v();
  • 25. Vertex Arrays void glEnableClientState(GLenum cap); void glDisableClientState(GLenum cap); gl*Pointer() void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *array); size must be 2, 3, or 4 and Type can be set to GL_SHORT, GL_INT, GL_FLOAT, or GL_DOUBLE. Stride padding in bytes between each vertex
  • 26. Vertex Arrays void glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *array); void glEdgeFlagPointer(GLsizei stride, const GLboolean *array); Array of Boolean void glNormalPointer(GLenum type, GLsizei stride, const GLvoid *array); normals always (x,y,z) so no need for the size. void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *array); size = number of coordinate per vertex
  • 27. Rendering Uesing Vertex Arrays void glDrawArrays(GLenum mode, GLint first, GLsizei count); void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices); [count is the number of indices that you want to render ] void glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid * indices);
  • 29. Rendering Uesing Vertex Arrays void glMultiDrawArrays(GLenum mode, GLint *first, GLsizei *count, GLsizei primcount)
  • 30. Vertex Buffer Objects (VRAM) instead of (RAM) To use a VBO, you need to perform the following steps: 1. Generate a name for the buffer. 2. Bind (activate) the buffer. 3. Store data in the buffer. 4. Use the buffer to render the data. 5. Destroy the buffer. 5. Destroy the buffer.
  • 31. Generating a Name void glGenBuffers(GLsizei n, GLuint *buffers); void glDeleteBuffers(GLsizei n, const GLuint *buffers);
  • 32. Binding the Buffer Binding a buffer makes it current; all buffer-related OpenGL calls and rendering will operate on the currently bound buffer. void glBindBuffer(GLenum target, GLuint buffer); target can be GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, GL_PIXEL_PACK_BUFFER, or GL_PIXEL_UNPACK_BUFFER GL_ARRAY_BUFFER for vertices data and GL_ELEMENT_ARRAY_BUFFER for indices data. if buffer is zero, the call will unbind any currently bound buffer.
  • 33. Filling the Buffer void glBufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); usage is a hint to OpenGL telling it how you intend to use this buffer. It can be GL_STREAM_DRAW, GL_STREAM_READ, GL_STREAM_COPY, GL_STATIC_DRAW, GL_STATIC_READ, GL_STATIC_COPY, GL_DYNAMIC_DRAW, GL_DYNAMIC_READ, or GL_DYNAMIC_COPY Calling glBufferData() on a buffer object that already contains data will cause the old data to be destroyed and replaced with the new data
  • 34. Rendering with Buffers and Vertex Arrays When rendering with VBOs you use gl*Pointer() functions as an offset.
  • 36. Modifying Point Size void glPointSize(GLfloat size) If point anti-aliasing is disabled then the point size is rounded to the nearest integer never zero.