SlideShare a Scribd company logo
1 of 32
Fixed Function to Shaders
Porting a fixed-function application to “modern”
Opengl.
Watch the video here: http://bit.ly/1TA24fU
Outline
There are many tutorials that introduce you to
“modern” OpenGL: (OpenGL 3.3/OpenGL ES
2.0 or greater which is where the fixed-function
APIs were removed from the spec.)
Here we will compare and contrast old fixed-
functionality and it’s new modern replacement.
We will cover some basic things you need to get
going: Vertex/Attribute data, rendering, and 3-
D math.
Geometry
Let’s use the famous OpenGL triangle as a
platform to talk about geometry/attributes.
It’s the probably the very first OpenGL program
you saw when learning OpenGL.
Rendering
What is the minimum need to “light up” a pixel?
First you need a window on your platform with
an OpenGL context bound to it.
You used to use GLUT and GLU “helper”
libraries
Here we use Qt to replace both.
For window/platform integration we’re using
QOpenGLWindow
initializeGL(), resizeGL(),
paintGL(), keyPressEvent()
GLUT OpenGL Triangle (clip-space)
Show code in Qt Creator.
OpenGL 1.1 Vertex Arrays GLUT Triangle
Show code in Qt Creator.
Modern Open Vertex Arrays Qt Triangle
Show code in Qt Creator.
Doesn’t Work ??
Previous slide will not render a triangle.
Why not?
Fixed-function example uses “fixed functionality”
to render.
With modern OpenGL, you have to program that
functionality yourself in the form of “shaders”.
Shaders
Many kinds of shaders in Modern OpenGL:
Vertex Shader
Tessellation Control Shader
Tessellation Evaluation Shader
Geometry Shader
Fragment Shader
Compute Shader
Only two are required.
Vertex Shader
Program that runs on the GPU.
Invoked once for each vertex in primitive shapes
drawn.
Input: Attribute data from vertex arrays
Output:
Clip space position of vertex: gl_Position
Data to pixel shader: varying variables.
Fragment Shader
Program run on the GPU once for each
fragment (pixel-candidate) displayed on
screen.
Inputs: varying variables from Vertex Shader
Outputs: pixel color: gl_FragColor
Pixels are produced by “Rasterization”
Rasterization
http://www.raywenderlich.com
Program
All the shaders are compiled and linked together
similar to C++ program.
QOpenGLShaderProgram makes it easy
Once compiled and linked bind() must be called
to make it active.
Hold On ...
You may notice the fragment shader is
assigning the output color directly from it’s
input varying v_color variable set by the
Vertex Shader.
How is it that the colors are “mixed” inside the
triangle?
Outputs of the vertex shader (and
corresponding inputs to the pixel shader) are
interpolated between the vertices.
Equivalent to glShadeModel(GL_SMOOTH);
What about GL_FLAT ?
Okay so attribute data output from the vertex
shader is interpolated to the pixel shader
inputs.
What about glShadeModel(GL_FLAT)?
Use flat attribute on variable declaration in
shader code.
flat varying vec3 v_color;
Default is smooth. These are equivalent:
smooth varying vec3 v_color;
varying vec3 v_color;
Review: QGLBufferObject
Memory buffer on graphics card that holds
vertex attribute data.
Equivalent to glBegin/glEnd inside a display
list
Attributes inside glBegin/glEnd copied to
video card instead of being rendered.
Equivalent to alloc() on QGLBufferObject.
Vertex Buffer Objects (VBO) don’t save primitive
type.
Instead pass as parameter to glDraw()
Just like OpenGL 1.1 Vertex Arrays
Review: QGLVertexArrayObject
OpenGL 1.1 Vertex Arrays require setting up
attribute array specifications each time before
calling glDraw().
Modern OpenGL captures attribute array
specifications once when data is uploaded to
card using Vertex Array Objects (VAO).
VAO “remembers” vertex array state and
applies this state when .bind() is called.
Modern code only needs a vao.bind() before
glDraw()
Another thing to note …
Fixed-function primitive types: GL_QUAD,
GL_QUAD_STRIP, GL_POLYGON have been
removed.
You must change your geometry to
GL_TRIANGLE_STRIP,
GL_TRIANGLE_FAN, or GL_TRIANGLE.
Math
Fixed-function OpenGL had Matrix Stacks built
into the API.
Used to create concept of a “camera”
(GL_MODELVIEW) rendering a world through a
window (GL_PROJECTION) that’s painted on
your computer screen.
Convenience Functions: glLoadIdentity,
glTranslate, glRotate, glScale
Matrix stack: glMatrixMode,
glPushMatrix, glPopmatrix
Sorry...
Sorry, that’s all gone now.
You, the programmer, have to perform all this math.
Recall the vertex shader is responsible for outputting
the vertices clip-space position by assigning to
gl_Position.
It is this math that you use in the vertex shader to
perform this conversion.
On the CPU the typical thing to do is recreate the
camera/window idiom with model transform
matrices, a view transform matrix, and a projection
matrix.
Pass the matrices to the shaders as “uniforms”
Agnostic
Modern OpenGL is agnostic about these idioms.
But it does help you by providing matrix math
operators in the shader language.
You, the programmer, get to decide how to
transform your vertex positions to clip space.
If you can code it, you can use it.
Math Library
If you want to use the Model-View-Projection
concept in your program you have to perform
the math yourself.
Qt has a powerful/concise library built-in which
supports vectors, matrices, and quaternions.
Matrix functions to replace GL & GLU
gluPerspective, gluOrtho2D, glFrustum,
gluLookAt, glTranslate, glRotate, glScale,
etc.
Checkout: QVector[2,3,4]D, QQuaterion,
QMatrix4x4
Move out of Clip space (fixed-function)
Show code in Qt Creator.
Uniforms
A uniform is a OpenGL Shading Language
(GLSL) constant parameter.
Set in CPU code between glDraw() calls.
Constant in the fashion that it has a constant
value for all shader invocations originating
from glDraw() calls until the value is
changed.
Use QOpenGLProgram.setUniform() to
pass Model, View, Projection matrices to
shader code before drawing.
Move out of Clip Space (modern GL)
Show code in Qt Creator.
User Clip Planes
Another thing to note is the glClipPlane()
has been removed.
Perform point/plane equation tests in your pixel
shader and use keyword discard (instead of
assigning to gl_FragColor) to inform
OpenGL that that particular pixel should not be
displayed.
Managing OpenGL State
Another thing to note is that
glPushAttrib(), glPopAttrib(),
glPushClientAttrib() and
glPopClientAttrib() have been
removed.
You have to manually manage your OpenGL
state by either keeping track of it in your C++
program (the preferred method) or by using
glGet() to read the current state and then
restoring it afterwards.
Wrapping Up
We were able to cover transitioning from fixed-
function Vertex/Attribute data and the built-in
Matrix stacks (and associated matrix
functionality) to Modern OpenGL.
We learned that Modern OpenGL replaced the
“fixed” stuff with programmable shaders. We
learned about the Vertex and Fragment
shaders, what they do and how data flows
through them.
We learned that using Qt makes is very easy to
create cross-platform Modern OpenGL code.
For More Information
For more information checkout the four-part
blog series I wrote covering this topic.
www.ics.com/blog/fixed-function-modern-opengl-part-1-4
Also, check out our training class coming up in
April out in Silicon Valley
www.ics.com/learning/training/state-art-opengl-and-qt-3
Outline
For the Blog: Journal Entry Style
- Introduction:
Spent a lot of time in past life on porting
complex, scenegraph based, fixed function
OpenGL code to Modern Pipeline Code
...
- Three Things that spring out to be addressed
- Geometry and Lighting and Texturing
- Picking, Text is another one for another day
- Explain Geometry and Lighting using a simple
scene example
Simple Scene from <insert link here>
Screenshot
Code: window/context, geometry, drawing,
resize, camera modelview, projection, viewport,
light
Modern Code: QOpenGLWindow....
Geometry: VertexBuffer, IndexBuffer,
VertexArrayObjects, ...
GLUT OpenGL Triangle (clip-space)
void init(void) {
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0); glVertex3f(-1.0, -1.0, 0.0);
glColor3f(0.0, 1.0, 0.0); glVertex3f( 0.0, 1.0, 0.0);
glColor3f(0.0, 0.0, 1.0); glVertex3f( 1.0, -1.0, 0.0);
glEnd();
glutSwapBuffers();
}
void reshape(int w, int h) {
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
}
void keyboard (unsigned char key, int , int )
{
if (key == 27) exit(0);
}

More Related Content

What's hot

Qt for beginners part 2 widgets
Qt for beginners part 2   widgetsQt for beginners part 2   widgets
Qt for beginners part 2 widgetsICS
 
Qt and QML performance tips & tricks for Qt 4.7
Qt and QML performance tips & tricks for Qt 4.7Qt and QML performance tips & tricks for Qt 4.7
Qt and QML performance tips & tricks for Qt 4.7Pasi Kellokoski
 
Building the QML Run-time
Building the QML Run-timeBuilding the QML Run-time
Building the QML Run-timeJohan Thelin
 
Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3ICS
 
Meet the Widgets: Another Way to Implement UI
Meet the Widgets: Another Way to Implement UIMeet the Widgets: Another Way to Implement UI
Meet the Widgets: Another Way to Implement UIICS
 
Qt for beginners part 5 ask the experts
Qt for beginners part 5   ask the expertsQt for beginners part 5   ask the experts
Qt for beginners part 5 ask the expertsICS
 
QVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentQVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentICS
 
Optimizing Performance in Qt-Based Applications
Optimizing Performance in Qt-Based ApplicationsOptimizing Performance in Qt-Based Applications
Optimizing Performance in Qt-Based Applicationsaccount inactive
 
Best Practices in Qt Quick/QML - Part 1 of 4
Best Practices in Qt Quick/QML - Part 1 of 4Best Practices in Qt Quick/QML - Part 1 of 4
Best Practices in Qt Quick/QML - Part 1 of 4ICS
 
Migrating from Photon to Qt
Migrating from Photon to QtMigrating from Photon to Qt
Migrating from Photon to QtJanel Heilbrunn
 
So I Downloaded Qt, Now What?
So I Downloaded Qt, Now What?So I Downloaded Qt, Now What?
So I Downloaded Qt, Now What?Janel Heilbrunn
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threadsYnon Perek
 
Intro to QML / Declarative UI
Intro to QML / Declarative UIIntro to QML / Declarative UI
Intro to QML / Declarative UIOpenBossa
 
Best Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIBest Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIICS
 
A Brief Introduction to the Qt Application Framework
A Brief Introduction to the Qt Application FrameworkA Brief Introduction to the Qt Application Framework
A Brief Introduction to the Qt Application FrameworkZachary Blair
 
Qt for Python
Qt for PythonQt for Python
Qt for PythonICS
 
Lockless Producer Consumer Threads: Asynchronous Communications Made Easy
Lockless Producer Consumer Threads: Asynchronous Communications Made EasyLockless Producer Consumer Threads: Asynchronous Communications Made Easy
Lockless Producer Consumer Threads: Asynchronous Communications Made EasyICS
 

What's hot (20)

Qt for beginners part 2 widgets
Qt for beginners part 2   widgetsQt for beginners part 2   widgets
Qt for beginners part 2 widgets
 
Cross Platform Qt
Cross Platform QtCross Platform Qt
Cross Platform Qt
 
Qt and QML performance tips & tricks for Qt 4.7
Qt and QML performance tips & tricks for Qt 4.7Qt and QML performance tips & tricks for Qt 4.7
Qt and QML performance tips & tricks for Qt 4.7
 
Building the QML Run-time
Building the QML Run-timeBuilding the QML Run-time
Building the QML Run-time
 
Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3
 
Meet the Widgets: Another Way to Implement UI
Meet the Widgets: Another Way to Implement UIMeet the Widgets: Another Way to Implement UI
Meet the Widgets: Another Way to Implement UI
 
Qt for beginners part 5 ask the experts
Qt for beginners part 5   ask the expertsQt for beginners part 5   ask the experts
Qt for beginners part 5 ask the experts
 
QVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentQVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI development
 
Optimizing Performance in Qt-Based Applications
Optimizing Performance in Qt-Based ApplicationsOptimizing Performance in Qt-Based Applications
Optimizing Performance in Qt-Based Applications
 
Best Practices in Qt Quick/QML - Part 1 of 4
Best Practices in Qt Quick/QML - Part 1 of 4Best Practices in Qt Quick/QML - Part 1 of 4
Best Practices in Qt Quick/QML - Part 1 of 4
 
Migrating from Photon to Qt
Migrating from Photon to QtMigrating from Photon to Qt
Migrating from Photon to Qt
 
So I Downloaded Qt, Now What?
So I Downloaded Qt, Now What?So I Downloaded Qt, Now What?
So I Downloaded Qt, Now What?
 
Qt 5 - C++ and Widgets
Qt 5 - C++ and WidgetsQt 5 - C++ and Widgets
Qt 5 - C++ and Widgets
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threads
 
Intro to QML / Declarative UI
Intro to QML / Declarative UIIntro to QML / Declarative UI
Intro to QML / Declarative UI
 
Best Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIBest Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part III
 
A Brief Introduction to the Qt Application Framework
A Brief Introduction to the Qt Application FrameworkA Brief Introduction to the Qt Application Framework
A Brief Introduction to the Qt Application Framework
 
Qt for Python
Qt for PythonQt for Python
Qt for Python
 
Lockless Producer Consumer Threads: Asynchronous Communications Made Easy
Lockless Producer Consumer Threads: Asynchronous Communications Made EasyLockless Producer Consumer Threads: Asynchronous Communications Made Easy
Lockless Producer Consumer Threads: Asynchronous Communications Made Easy
 
Qt Widget In-Depth
Qt Widget In-DepthQt Widget In-Depth
Qt Widget In-Depth
 

Similar to OpenGL Fixed Function to Shaders - Porting a fixed function application to “modern” OpenGL - Webinar Mar 2016

openGL basics for sample program (1).ppt
openGL basics for sample program (1).pptopenGL basics for sample program (1).ppt
openGL basics for sample program (1).pptHIMANKMISHRA2
 
openGL basics for sample program.ppt
openGL basics for sample program.pptopenGL basics for sample program.ppt
openGL basics for sample program.pptHIMANKMISHRA2
 
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
 
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
 
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 PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORTCOMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORTvineet raj
 
Opengl lec 3
Opengl lec 3Opengl lec 3
Opengl lec 3elnaqah
 
Shader Programming With Unity
Shader Programming With UnityShader Programming With Unity
Shader Programming With UnityMindstorm Studios
 
Mixing Path Rendering and 3D
Mixing Path Rendering and 3DMixing Path Rendering and 3D
Mixing Path Rendering and 3DMark Kilgard
 
GL Shading Language Document by OpenGL.pdf
GL Shading Language Document by OpenGL.pdfGL Shading Language Document by OpenGL.pdf
GL Shading Language Document by OpenGL.pdfshaikhshehzad024
 

Similar to OpenGL Fixed Function to Shaders - Porting a fixed function application to “modern” OpenGL - Webinar Mar 2016 (20)

openGL basics for sample program (1).ppt
openGL basics for sample program (1).pptopenGL basics for sample program (1).ppt
openGL basics for sample program (1).ppt
 
openGL basics for sample program.ppt
openGL basics for sample program.pptopenGL basics for sample program.ppt
openGL basics for sample program.ppt
 
Opengl basics
Opengl basicsOpengl basics
Opengl basics
 
Arkanoid Game
Arkanoid GameArkanoid Game
Arkanoid Game
 
18csl67 vtu lab manual
18csl67 vtu lab manual18csl67 vtu lab manual
18csl67 vtu lab manual
 
Android native gl
Android native glAndroid native gl
Android native gl
 
Bai 1
Bai 1Bai 1
Bai 1
 
Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011
 
Introduction to 2D/3D Graphics
Introduction to 2D/3D GraphicsIntroduction to 2D/3D Graphics
Introduction to 2D/3D Graphics
 
CS 354 Viewing Stuff
CS 354 Viewing StuffCS 354 Viewing Stuff
CS 354 Viewing Stuff
 
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
 
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 PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORTCOMPUTER GRAPHICS PROJECT REPORT
COMPUTER GRAPHICS PROJECT REPORT
 
Open gl tips
Open gl tipsOpen gl tips
Open gl tips
 
Open gles
Open glesOpen gles
Open gles
 
Open gl
Open glOpen gl
Open gl
 
Opengl lec 3
Opengl lec 3Opengl lec 3
Opengl lec 3
 
Shader Programming With Unity
Shader Programming With UnityShader Programming With Unity
Shader Programming With Unity
 
Mixing Path Rendering and 3D
Mixing Path Rendering and 3DMixing Path Rendering and 3D
Mixing Path Rendering and 3D
 
GL Shading Language Document by OpenGL.pdf
GL Shading Language Document by OpenGL.pdfGL Shading Language Document by OpenGL.pdf
GL Shading Language Document by OpenGL.pdf
 

More from ICS

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Practical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfPractical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfICS
 
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...ICS
 
Overcoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues WebinarOvercoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues WebinarICS
 
Enhancing Quality and Test in Medical Device Design - Part 2.pdf
Enhancing Quality and Test in Medical Device Design - Part 2.pdfEnhancing Quality and Test in Medical Device Design - Part 2.pdf
Enhancing Quality and Test in Medical Device Design - Part 2.pdfICS
 
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdf
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdfDesigning and Managing IoT Devices for Rapid Deployment - Webinar.pdf
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdfICS
 
Quality and Test in Medical Device Design - Part 1.pdf
Quality and Test in Medical Device Design - Part 1.pdfQuality and Test in Medical Device Design - Part 1.pdf
Quality and Test in Medical Device Design - Part 1.pdfICS
 
Creating Digital Twins Using Rapid Development Techniques.pdf
Creating Digital Twins Using Rapid Development Techniques.pdfCreating Digital Twins Using Rapid Development Techniques.pdf
Creating Digital Twins Using Rapid Development Techniques.pdfICS
 
Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up ICS
 
Cybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdfCybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdfICS
 
MDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical DevicesMDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical DevicesICS
 
How to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management SolutionHow to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management SolutionICS
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsICS
 
IoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with AzureIoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with AzureICS
 
Basic Cmake for Qt Users
Basic Cmake for Qt UsersBasic Cmake for Qt Users
Basic Cmake for Qt UsersICS
 
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...ICS
 
Qt Installer Framework
Qt Installer FrameworkQt Installer Framework
Qt Installer FrameworkICS
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsICS
 
Overcome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case StudyOvercome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case StudyICS
 
User Experience Design for IoT
User Experience Design for IoTUser Experience Design for IoT
User Experience Design for IoTICS
 

More from ICS (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Practical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfPractical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdf
 
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
 
Overcoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues WebinarOvercoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues Webinar
 
Enhancing Quality and Test in Medical Device Design - Part 2.pdf
Enhancing Quality and Test in Medical Device Design - Part 2.pdfEnhancing Quality and Test in Medical Device Design - Part 2.pdf
Enhancing Quality and Test in Medical Device Design - Part 2.pdf
 
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdf
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdfDesigning and Managing IoT Devices for Rapid Deployment - Webinar.pdf
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdf
 
Quality and Test in Medical Device Design - Part 1.pdf
Quality and Test in Medical Device Design - Part 1.pdfQuality and Test in Medical Device Design - Part 1.pdf
Quality and Test in Medical Device Design - Part 1.pdf
 
Creating Digital Twins Using Rapid Development Techniques.pdf
Creating Digital Twins Using Rapid Development Techniques.pdfCreating Digital Twins Using Rapid Development Techniques.pdf
Creating Digital Twins Using Rapid Development Techniques.pdf
 
Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up
 
Cybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdfCybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdf
 
MDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical DevicesMDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical Devices
 
How to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management SolutionHow to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management Solution
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory Teams
 
IoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with AzureIoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with Azure
 
Basic Cmake for Qt Users
Basic Cmake for Qt UsersBasic Cmake for Qt Users
Basic Cmake for Qt Users
 
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
 
Qt Installer Framework
Qt Installer FrameworkQt Installer Framework
Qt Installer Framework
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory Teams
 
Overcome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case StudyOvercome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case Study
 
User Experience Design for IoT
User Experience Design for IoTUser Experience Design for IoT
User Experience Design for IoT
 

Recently uploaded

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 

Recently uploaded (20)

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 

OpenGL Fixed Function to Shaders - Porting a fixed function application to “modern” OpenGL - Webinar Mar 2016

  • 1. Fixed Function to Shaders Porting a fixed-function application to “modern” Opengl. Watch the video here: http://bit.ly/1TA24fU
  • 2. Outline There are many tutorials that introduce you to “modern” OpenGL: (OpenGL 3.3/OpenGL ES 2.0 or greater which is where the fixed-function APIs were removed from the spec.) Here we will compare and contrast old fixed- functionality and it’s new modern replacement. We will cover some basic things you need to get going: Vertex/Attribute data, rendering, and 3- D math.
  • 3. Geometry Let’s use the famous OpenGL triangle as a platform to talk about geometry/attributes. It’s the probably the very first OpenGL program you saw when learning OpenGL.
  • 4. Rendering What is the minimum need to “light up” a pixel? First you need a window on your platform with an OpenGL context bound to it. You used to use GLUT and GLU “helper” libraries Here we use Qt to replace both. For window/platform integration we’re using QOpenGLWindow initializeGL(), resizeGL(), paintGL(), keyPressEvent()
  • 5. GLUT OpenGL Triangle (clip-space) Show code in Qt Creator.
  • 6. OpenGL 1.1 Vertex Arrays GLUT Triangle Show code in Qt Creator.
  • 7. Modern Open Vertex Arrays Qt Triangle Show code in Qt Creator.
  • 8. Doesn’t Work ?? Previous slide will not render a triangle. Why not? Fixed-function example uses “fixed functionality” to render. With modern OpenGL, you have to program that functionality yourself in the form of “shaders”.
  • 9. Shaders Many kinds of shaders in Modern OpenGL: Vertex Shader Tessellation Control Shader Tessellation Evaluation Shader Geometry Shader Fragment Shader Compute Shader Only two are required.
  • 10. Vertex Shader Program that runs on the GPU. Invoked once for each vertex in primitive shapes drawn. Input: Attribute data from vertex arrays Output: Clip space position of vertex: gl_Position Data to pixel shader: varying variables.
  • 11. Fragment Shader Program run on the GPU once for each fragment (pixel-candidate) displayed on screen. Inputs: varying variables from Vertex Shader Outputs: pixel color: gl_FragColor Pixels are produced by “Rasterization”
  • 13. Program All the shaders are compiled and linked together similar to C++ program. QOpenGLShaderProgram makes it easy Once compiled and linked bind() must be called to make it active.
  • 14. Hold On ... You may notice the fragment shader is assigning the output color directly from it’s input varying v_color variable set by the Vertex Shader. How is it that the colors are “mixed” inside the triangle? Outputs of the vertex shader (and corresponding inputs to the pixel shader) are interpolated between the vertices. Equivalent to glShadeModel(GL_SMOOTH);
  • 15. What about GL_FLAT ? Okay so attribute data output from the vertex shader is interpolated to the pixel shader inputs. What about glShadeModel(GL_FLAT)? Use flat attribute on variable declaration in shader code. flat varying vec3 v_color; Default is smooth. These are equivalent: smooth varying vec3 v_color; varying vec3 v_color;
  • 16. Review: QGLBufferObject Memory buffer on graphics card that holds vertex attribute data. Equivalent to glBegin/glEnd inside a display list Attributes inside glBegin/glEnd copied to video card instead of being rendered. Equivalent to alloc() on QGLBufferObject. Vertex Buffer Objects (VBO) don’t save primitive type. Instead pass as parameter to glDraw() Just like OpenGL 1.1 Vertex Arrays
  • 17. Review: QGLVertexArrayObject OpenGL 1.1 Vertex Arrays require setting up attribute array specifications each time before calling glDraw(). Modern OpenGL captures attribute array specifications once when data is uploaded to card using Vertex Array Objects (VAO). VAO “remembers” vertex array state and applies this state when .bind() is called. Modern code only needs a vao.bind() before glDraw()
  • 18. Another thing to note … Fixed-function primitive types: GL_QUAD, GL_QUAD_STRIP, GL_POLYGON have been removed. You must change your geometry to GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, or GL_TRIANGLE.
  • 19. Math Fixed-function OpenGL had Matrix Stacks built into the API. Used to create concept of a “camera” (GL_MODELVIEW) rendering a world through a window (GL_PROJECTION) that’s painted on your computer screen. Convenience Functions: glLoadIdentity, glTranslate, glRotate, glScale Matrix stack: glMatrixMode, glPushMatrix, glPopmatrix
  • 20. Sorry... Sorry, that’s all gone now. You, the programmer, have to perform all this math. Recall the vertex shader is responsible for outputting the vertices clip-space position by assigning to gl_Position. It is this math that you use in the vertex shader to perform this conversion. On the CPU the typical thing to do is recreate the camera/window idiom with model transform matrices, a view transform matrix, and a projection matrix. Pass the matrices to the shaders as “uniforms”
  • 21. Agnostic Modern OpenGL is agnostic about these idioms. But it does help you by providing matrix math operators in the shader language. You, the programmer, get to decide how to transform your vertex positions to clip space. If you can code it, you can use it.
  • 22. Math Library If you want to use the Model-View-Projection concept in your program you have to perform the math yourself. Qt has a powerful/concise library built-in which supports vectors, matrices, and quaternions. Matrix functions to replace GL & GLU gluPerspective, gluOrtho2D, glFrustum, gluLookAt, glTranslate, glRotate, glScale, etc. Checkout: QVector[2,3,4]D, QQuaterion, QMatrix4x4
  • 23. Move out of Clip space (fixed-function) Show code in Qt Creator.
  • 24. Uniforms A uniform is a OpenGL Shading Language (GLSL) constant parameter. Set in CPU code between glDraw() calls. Constant in the fashion that it has a constant value for all shader invocations originating from glDraw() calls until the value is changed. Use QOpenGLProgram.setUniform() to pass Model, View, Projection matrices to shader code before drawing.
  • 25. Move out of Clip Space (modern GL) Show code in Qt Creator.
  • 26. User Clip Planes Another thing to note is the glClipPlane() has been removed. Perform point/plane equation tests in your pixel shader and use keyword discard (instead of assigning to gl_FragColor) to inform OpenGL that that particular pixel should not be displayed.
  • 27. Managing OpenGL State Another thing to note is that glPushAttrib(), glPopAttrib(), glPushClientAttrib() and glPopClientAttrib() have been removed. You have to manually manage your OpenGL state by either keeping track of it in your C++ program (the preferred method) or by using glGet() to read the current state and then restoring it afterwards.
  • 28. Wrapping Up We were able to cover transitioning from fixed- function Vertex/Attribute data and the built-in Matrix stacks (and associated matrix functionality) to Modern OpenGL. We learned that Modern OpenGL replaced the “fixed” stuff with programmable shaders. We learned about the Vertex and Fragment shaders, what they do and how data flows through them. We learned that using Qt makes is very easy to create cross-platform Modern OpenGL code.
  • 29. For More Information For more information checkout the four-part blog series I wrote covering this topic. www.ics.com/blog/fixed-function-modern-opengl-part-1-4 Also, check out our training class coming up in April out in Silicon Valley www.ics.com/learning/training/state-art-opengl-and-qt-3
  • 30. Outline For the Blog: Journal Entry Style - Introduction: Spent a lot of time in past life on porting complex, scenegraph based, fixed function OpenGL code to Modern Pipeline Code ... - Three Things that spring out to be addressed - Geometry and Lighting and Texturing - Picking, Text is another one for another day - Explain Geometry and Lighting using a simple scene example
  • 31. Simple Scene from <insert link here> Screenshot Code: window/context, geometry, drawing, resize, camera modelview, projection, viewport, light Modern Code: QOpenGLWindow.... Geometry: VertexBuffer, IndexBuffer, VertexArrayObjects, ...
  • 32. GLUT OpenGL Triangle (clip-space) void init(void) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void display(void) { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_TRIANGLES); glColor3f(1.0, 0.0, 0.0); glVertex3f(-1.0, -1.0, 0.0); glColor3f(0.0, 1.0, 0.0); glVertex3f( 0.0, 1.0, 0.0); glColor3f(0.0, 0.0, 1.0); glVertex3f( 1.0, -1.0, 0.0); glEnd(); glutSwapBuffers(); } void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); } void keyboard (unsigned char key, int , int ) { if (key == 27) exit(0); }

Editor's Notes

  1. in OpenGL 1.1, there was the concept of vertex arrays. Modern OpenGL keeps this concept,