SlideShare a Scribd company logo
1 of 36
Download to read offline
Computer Graphics
CHAPTER 3 INTRODUCTION TO THE RENDERING PROCESS WITH OPENGL
By Asamenek.
Overview
➢Graphics Pipeline
➢OpenGL
➢Coordinate Systems
➢Shaders Fundamentals
➢Summery
➢Lab 2 – Basic of OpenGL and Shader Language
Graphics Pipeline(Rendering)
➢ Vectors are the basis for computer generated images specifying the vertexes in the image
➢ Changing these vertexes to beautiful image is not an easy task and it goes through many stages
➢ The Process of changing these vertexes to images is called Graphics Pipeline or Rendering
Pipeline
.
.
.
Graphics Pipeline
Graphics Pipeline
➢ The graphics pipeline has up to 7 stages.
➢ Some of these stages need to be implemented by us, some are optional to implement and
some are already implemented for us
➢ The stages are executed by Shader Program
➢ Vertex Shader
➢ Tessellation Shader
➢ Geometry Shader
➢ Rasterization
➢ Clipping
➢ Primitive Setup
➢ Fragment Shader
Graphics Pipeline – Vertex Shader
➢ Vertex shading is the stage in the rendering pipeline that handles the processing of individual
vertices
➢ Vertex shaders are fed Vertex data, as specified from a vertex array object by a drawing
command
➢ receives a single vertex from the vertex stream and generates a single vertex to the output
vertex stream
[4, 4]
[8, 0]
[4, -4]
[-4, -4]
[-8, 0]
[-4, 4]
V
Vertex Shader
[1, 0]
[1, 0]
[1, 0]
[1, 0]
[1, 0]
[1, 0]
V +
Graphics Pipeline – Tessellation Shader
➢ Tessellation Shader tessellates (subdivide) the object given by the Vertex Shader
➢ This shader allows to add more detail to the already existing object
Tessellation Shader
Graphics Pipeline – Tessellation Shader
➢ Tessellation Shader tessellates (subdivide) the object given by the Vertex Shader
➢ This shader allows to more detail to the already existing object
Graphics Pipeline – Geometry Shader
➢ Geometry Shader allows additional processing on individual primitive level like creating new
primitive, removing old primitives or manipulating the existing
➢ This allows parts of the graphics to be generated only when they are needed, which saves
storage of the newly generated parts
➢ Grass, Fur and similar graphics can be generated using geometry shader
Graphics Pipeline – Primitive Assembly
➢ The previous shaders operate on vertexes and generate new vertexes and primitives
➢ The primitive assembly organize these vertexes to base primitives so that further processing is
easier like rasterizing and clipping
Graphics Pipeline – Clipping
➢ The vertexes created until now might out of the view port (the region of the window where we
are permitted to draw)
➢ We use clipping stage to modify the drawing vertex is outside the view port
View Port
Clipping
Graphics Pipeline – Clipping and Rasterizing
➢ The vectors that we specify have only mathematical description and doesn’t contain any
information about the screen
➢Rasterization – is the process of defining candidate fragments of the primitives that can be
displayed on the screen
Graphics Pipeline – Fragment Shader
➢ Until now, we only manipulate the position of the vertexes and primitives (basic shapes)
➢ We need to manipulate the color and texture of the image
➢ In this stage, we calculate the fragments’ final color
Coordinate systems
➢ The use of coordinate systems is fundamental to computer graphics
➢ Coordinate systems are used to describe the locations of points in space
Summary
➢ Coordinate Systems are defined by an origin point O and set of basis vectors
➢ Basis vectors are vectors that are linearly independent and span a set of vectors V
➢ Different Coordinate systems can be used based on the problem given
➢ Changing between coordinate systems can be calculated using Transformation
➢ Transformation can be used for Rotation, Reflection, Scaling ….
➢ Homogenous coordinate system is a cartesian coordinate system with extra W component
➢ Used for applying uniform matrix operation across different transformation
Output Primitives
 Output Primitives: Basic geometric structures
used to describe scenes.
(points, straight line segment, circles and
other conic sections, quadric surfaces,
spline curve and surfaces, polygon color
areas, and character strings)
These picture components are often
defined in a continuous space.
Output Primitives
In order to draw the primitive objects, one
has to first scan convert the object.
Scan convert: Refers to the operation of
finding out the location of pixels to be
intensified and then setting the values of
corresponding bits, in the graphic
memory, to the desired intensity code.
Scan Converting A Point
A random-scan (vector) system
stores point-plotting instructions in the
display list, and coordinate values in
these instructions are converted to
deflection voltages that position the
electron beam at the screen locations
to be plotted during each refresh cycle.
OpenGL
➢ OpenGL (Open Graphics Library) is an API – Application Programming Interface – which is a
software library for accessing features in computer graphics hardware
➢ Contains more than 500 distinct commands to create computer graphics objects and apply
operation on these objects
➢ OpenGL is designed to be hardware independent and cross platform interface
OpenGL
➢ OpenGL 1.0, first version, was release in 1994
➢ Now the latest version is 4.3 but we will be using version 3.3 and above
➢ OpenGL uses the full graphics pipeline
➢ It is Client-Server system in which the application we write is the client which simply sends
commands that manipulate images to the server
➢ The server is OpenGL implementation provided by the manufacturer of the hardware and the
software of the machine
OpenGL – Graphics Terminologies
➢ Primitives – are basic shapes that allow to create more complex shapes – Point, Line, Triangles
and their derivatives
➢ Models or Objects – are complex structures that are constructed by combining the primitives
➢ Rendering – is the process by which computer creates images from models
➢ Pixel – is the smallest visible elements of the computer/mobile display
➢ Framebuffer – is the memory space on which the pixels are stored
OpenGL – Syntax
➢ All OpenGL function start with ‘gl’ prefix
➢ Some have glUniform*() structure describing the arguments
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(1.0, 0.0, 0.0)
glBegin(GL_POINTS)
glVertex2f(0.0, 0.0)
glEnd()
glFlush()
glUniform2f()
glUniform3fv()
glUniform2fv()
Drawing using OpenGL
➢ OpenGL by itself doesn’t provide windowing functionalities apart from graphics processing
commands
➢ We use PyGame to create and provide windowing functionalities
➢ We also need to initialize OpenGL with default values
OpenGL – before all
➢ Import important libraries
import pygame
from OpenGL.GL import *
from OpenGL.GLU import *
from pygame.locals import *
from OpenGL.GL.shaders import *
import numpy as np
OpenGL – Window Loop
➢ Graphical Applications need a main loop to stay open until the user closes it
def main():
init()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
draw()
pygame.display.flip()
pygame.time.wait(10)
Shader Language
➢ Most operations on the vertexes can be done in parallel processing
➢ Sadly, CPUs like sequential computation and not parallel computation
➢ GPUs offer parallel computation scheme, allowing us to compute thousands of operation in a
single unit time
Shader Language
➢ The graphics pipeline in computer graphics requires parallel computation
➢ Shader Language is specialized programming language for computer graphics pipeline that
allows us to use the parallel computation power of the GPU
➢ Shaders must be compiled by OpenGL before loading them to memory
Shader Language – Vertex Shader
vec4 vPosition;
void main()
{
gl_Position = vPosition;
}
Shader Language – Fragment Shader
void main()
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
Shader Language – Compiling and Loading Shader
# read Shader File content
vertexShaderContent = getFileContent("triangle.vertex.shader")
fragmentShaderContent = getFileContent("triangle.fragment.shader")
# compile Shader content
vertexShader = compileShader(vertexShaderContent, GL_VERTEX_SHADER)
fragmentShader = compileShader(fragmentShaderContent, GL_FRAGMENT_SHADER)
# Compile shader program
program = glCreateProgram()
glAttachShader(program, vertexShader)
glAttachShader(program, fragmentShader)
glLinkProgram(program)
OpenGL - Buffers
➢ OpenGL stores any kind of data on buffer memory
➢ This buffer memory need to be first allocated for specific kind of of data (position vector, color,
image)
➢ Once, a buffer memory space is created, the vertexes are stored on it
OpenGL – Creating vertexes
# Create vertexes
vertexes = np.array([
[0.5, 0.0, 0.0],
[-0.5, 0.0, 0.0],
[0, 0.5, 0.0]], dtype=np.float32)
OpenGL – Creating Buffer Memory
# Get memory space and load it with the vetrtexes
triangleVBO = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, triangleVBO)
glBufferData(GL_ARRAY_BUFFER, vertexes.nbytes, vertexes, GL_STATIC_DRAW)
OpenGL – Loading the vertexes
# Load the new memory space with our vertexes
triangleVAO = glGenVertexArrays(1)
glBindVertexArray(triangleVAO)
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * vertexes.itemsize, None)
Summary
➢ The Graphics Pipeline – The stages in which vertexes pass through
➢ Vertex Shader – Processing individual vertexes
➢ Tessellation Shader – subdividing the patches of the model to further process in detail
➢ Geometry Shader – Processing basic primitives
➢ Primitive Assembly – organizing primitive so that it is easier for further processing
➢ Clipping – Modifying primitives by clipping vertexes outside the view port
➢ Rasterizing – Converting mathematical description of shapes to candidate fragments on the screen
➢ Fragment Shader – processing the color of individual fragments
Summary
➢ OpenGL – API for processing computer graphics
➢ Cross Platform and Hardware Independent
➢ Client-Server Architecture
➢ Doesn’t contain windowing functionality, so we use PyGame’s windowing functionality
➢ Shaders
➢ Small programs of computer graphics that run on GPU for parallel computation of vertexes and
primitives
➢ Must be compiled by OpenGL and loaded to memory
CG – Lab 2 Hello World in OpenGL
➢ Create a “shader” program, compile and load it in OpenGL
➢ Create our triangle vertices and load it to GPU
➢ Draw the vertexes – A Triangle

More Related Content

Similar to Chapter-3.pdf

Introduction to Computer graphics
Introduction to Computer graphicsIntroduction to Computer graphics
Introduction to Computer graphicsLOKESH KUMAR
 
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
 
Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011Prabindh Sundareson
 
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
 
Hpg2011 papers kazakov
Hpg2011 papers kazakovHpg2011 papers kazakov
Hpg2011 papers kazakovmistercteam
 
Graphics pipelining
Graphics pipeliningGraphics pipelining
Graphics pipeliningAreena Javed
 
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
 
OpenGL ES and Mobile GPU
OpenGL ES and Mobile GPUOpenGL ES and Mobile GPU
OpenGL ES and Mobile GPUJiansong Chen
 
Introduction of openGL
Introduction  of openGLIntroduction  of openGL
Introduction of openGLGary Yeh
 
Computer graphics - Nitish Nagar
Computer graphics - Nitish NagarComputer graphics - Nitish Nagar
Computer graphics - Nitish NagarNitish Nagar
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer GraphicsAdri Jovin
 

Similar to Chapter-3.pdf (20)

Introduction to Computer graphics
Introduction to Computer graphicsIntroduction to Computer graphics
Introduction to Computer graphics
 
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...
 
What is OpenGL ?
What is OpenGL ?What is OpenGL ?
What is OpenGL ?
 
Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011
 
Unit 11. Graphics
Unit 11. GraphicsUnit 11. Graphics
Unit 11. Graphics
 
Shaders in Unity
Shaders in UnityShaders in Unity
Shaders in Unity
 
OpenGL basics
OpenGL basicsOpenGL basics
OpenGL basics
 
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
 
Hpg2011 papers kazakov
Hpg2011 papers kazakovHpg2011 papers kazakov
Hpg2011 papers kazakov
 
Opengl basics
Opengl basicsOpengl basics
Opengl basics
 
Graphics pipelining
Graphics pipeliningGraphics pipelining
Graphics pipelining
 
OpenGL for 2015
OpenGL for 2015OpenGL for 2015
OpenGL for 2015
 
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 ES and Mobile GPU
OpenGL ES and Mobile GPUOpenGL ES and Mobile GPU
OpenGL ES and Mobile GPU
 
Introduction of openGL
Introduction  of openGLIntroduction  of openGL
Introduction of openGL
 
2D graphics
2D graphics2D graphics
2D graphics
 
Computer graphics - Nitish Nagar
Computer graphics - Nitish NagarComputer graphics - Nitish Nagar
Computer graphics - Nitish Nagar
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
NVIDIA CUDA
NVIDIA CUDANVIDIA CUDA
NVIDIA CUDA
 

More from mekelle university(EiT-M)

የምርምር_አተገባበር_እና_አስተዳደር_መመሪያ_18_Dec_ver_1_1.docx
የምርምር_አተገባበር_እና_አስተዳደር_መመሪያ_18_Dec_ver_1_1.docxየምርምር_አተገባበር_እና_አስተዳደር_መመሪያ_18_Dec_ver_1_1.docx
የምርምር_አተገባበር_እና_አስተዳደር_መመሪያ_18_Dec_ver_1_1.docxmekelle university(EiT-M)
 
Chapter 4 Health Management Information Systems.pdf
Chapter 4 Health Management Information Systems.pdfChapter 4 Health Management Information Systems.pdf
Chapter 4 Health Management Information Systems.pdfmekelle university(EiT-M)
 
Chapter 3 Health informatics terminology.pdf
Chapter 3 Health informatics terminology.pdfChapter 3 Health informatics terminology.pdf
Chapter 3 Health informatics terminology.pdfmekelle university(EiT-M)
 
Seminar on computer simulation and modeling The Activity Approach By:Asamene.K
Seminar on computer simulation and modeling The Activity Approach By:Asamene.KSeminar on computer simulation and modeling The Activity Approach By:Asamene.K
Seminar on computer simulation and modeling The Activity Approach By:Asamene.Kmekelle university(EiT-M)
 
Basic C# programming Part -1 For Computer Science & IT Prepared by: Asamene ....
Basic C# programming Part -1 For Computer Science & IT Prepared by: Asamene ....Basic C# programming Part -1 For Computer Science & IT Prepared by: Asamene ....
Basic C# programming Part -1 For Computer Science & IT Prepared by: Asamene ....mekelle university(EiT-M)
 

More from mekelle university(EiT-M) (10)

Transformations.pptx
Transformations.pptxTransformations.pptx
Transformations.pptx
 
Advanced DB chapter 2.pdf
Advanced DB chapter 2.pdfAdvanced DB chapter 2.pdf
Advanced DB chapter 2.pdf
 
የምርምር_አተገባበር_እና_አስተዳደር_መመሪያ_18_Dec_ver_1_1.docx
የምርምር_አተገባበር_እና_አስተዳደር_መመሪያ_18_Dec_ver_1_1.docxየምርምር_አተገባበር_እና_አስተዳደር_መመሪያ_18_Dec_ver_1_1.docx
የምርምር_አተገባበር_እና_አስተዳደር_መመሪያ_18_Dec_ver_1_1.docx
 
Computer Organization and Architecture.pdf
Computer Organization and Architecture.pdfComputer Organization and Architecture.pdf
Computer Organization and Architecture.pdf
 
6952234.ppt
6952234.ppt6952234.ppt
6952234.ppt
 
Chapter 4 Health Management Information Systems.pdf
Chapter 4 Health Management Information Systems.pdfChapter 4 Health Management Information Systems.pdf
Chapter 4 Health Management Information Systems.pdf
 
Chapter 3 Health informatics terminology.pdf
Chapter 3 Health informatics terminology.pdfChapter 3 Health informatics terminology.pdf
Chapter 3 Health informatics terminology.pdf
 
Chapter 2 Networking &.pdf
Chapter 2  Networking &.pdfChapter 2  Networking &.pdf
Chapter 2 Networking &.pdf
 
Seminar on computer simulation and modeling The Activity Approach By:Asamene.K
Seminar on computer simulation and modeling The Activity Approach By:Asamene.KSeminar on computer simulation and modeling The Activity Approach By:Asamene.K
Seminar on computer simulation and modeling The Activity Approach By:Asamene.K
 
Basic C# programming Part -1 For Computer Science & IT Prepared by: Asamene ....
Basic C# programming Part -1 For Computer Science & IT Prepared by: Asamene ....Basic C# programming Part -1 For Computer Science & IT Prepared by: Asamene ....
Basic C# programming Part -1 For Computer Science & IT Prepared by: Asamene ....
 

Recently uploaded

怎样办理伍伦贡大学毕业证(UOW毕业证书)成绩单留信认证
怎样办理伍伦贡大学毕业证(UOW毕业证书)成绩单留信认证怎样办理伍伦贡大学毕业证(UOW毕业证书)成绩单留信认证
怎样办理伍伦贡大学毕业证(UOW毕业证书)成绩单留信认证ehyxf
 
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制uodye
 
Abortion pills in Jeddah +966572737505 <> buy cytotec <> unwanted kit Saudi A...
Abortion pills in Jeddah +966572737505 <> buy cytotec <> unwanted kit Saudi A...Abortion pills in Jeddah +966572737505 <> buy cytotec <> unwanted kit Saudi A...
Abortion pills in Jeddah +966572737505 <> buy cytotec <> unwanted kit Saudi A...samsungultra782445
 
怎样办理昆士兰大学毕业证(UQ毕业证书)成绩单留信认证
怎样办理昆士兰大学毕业证(UQ毕业证书)成绩单留信认证怎样办理昆士兰大学毕业证(UQ毕业证书)成绩单留信认证
怎样办理昆士兰大学毕业证(UQ毕业证书)成绩单留信认证ehyxf
 
一比一维多利亚大学毕业证(victoria毕业证)成绩单学位证如何办理
一比一维多利亚大学毕业证(victoria毕业证)成绩单学位证如何办理一比一维多利亚大学毕业证(victoria毕业证)成绩单学位证如何办理
一比一维多利亚大学毕业证(victoria毕业证)成绩单学位证如何办理uodye
 
Hilti's Latest Battery - Hire Depot.pptx
Hilti's Latest Battery - Hire Depot.pptxHilti's Latest Battery - Hire Depot.pptx
Hilti's Latest Battery - Hire Depot.pptxhiredepot6
 
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证tufbav
 
在线办理(scu毕业证)南十字星大学毕业证电子版学位证书注册证明信
在线办理(scu毕业证)南十字星大学毕业证电子版学位证书注册证明信在线办理(scu毕业证)南十字星大学毕业证电子版学位证书注册证明信
在线办理(scu毕业证)南十字星大学毕业证电子版学位证书注册证明信oopacde
 
Call Girls Service Lucknow {0000000000 } ❤️VVIP BHAWNA Call Girl in Lucknow U.P
Call Girls Service Lucknow {0000000000 } ❤️VVIP BHAWNA Call Girl in Lucknow U.PCall Girls Service Lucknow {0000000000 } ❤️VVIP BHAWNA Call Girl in Lucknow U.P
Call Girls Service Lucknow {0000000000 } ❤️VVIP BHAWNA Call Girl in Lucknow U.Pjabtakhaidam7
 
Abortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in Dammam
Abortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in DammamAbortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in Dammam
Abortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in Dammamahmedjiabur940
 
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证tufbav
 
Top profile Call Girls In Ratlam [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Ratlam [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Ratlam [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Ratlam [ 7014168258 ] Call Me For Genuine Models We...nirzagarg
 
Dubai Call Girls O525547819 Call Girls In Dubai<.> Full Dirty Services
Dubai Call Girls O525547819 Call Girls In Dubai<.> Full Dirty ServicesDubai Call Girls O525547819 Call Girls In Dubai<.> Full Dirty Services
Dubai Call Girls O525547819 Call Girls In Dubai<.> Full Dirty Serviceskajalvid75
 
Jual Obat Aborsi Samarinda ( No.1 ) 088980685493 Obat Penggugur Kandungan Cy...
Jual Obat Aborsi Samarinda (  No.1 ) 088980685493 Obat Penggugur Kandungan Cy...Jual Obat Aborsi Samarinda (  No.1 ) 088980685493 Obat Penggugur Kandungan Cy...
Jual Obat Aborsi Samarinda ( No.1 ) 088980685493 Obat Penggugur Kandungan Cy...Obat Aborsi 088980685493 Jual Obat Aborsi
 
Kadi - HiFi Call Girl Service Ahmedabad Phone No 8005736733 Elite Escort Serv...
Kadi - HiFi Call Girl Service Ahmedabad Phone No 8005736733 Elite Escort Serv...Kadi - HiFi Call Girl Service Ahmedabad Phone No 8005736733 Elite Escort Serv...
Kadi - HiFi Call Girl Service Ahmedabad Phone No 8005736733 Elite Escort Serv...gragchanchal546
 
Call Girls Amethi 9332606886 HOT & SEXY Models beautiful and charming call g...
Call Girls Amethi  9332606886 HOT & SEXY Models beautiful and charming call g...Call Girls Amethi  9332606886 HOT & SEXY Models beautiful and charming call g...
Call Girls Amethi 9332606886 HOT & SEXY Models beautiful and charming call g...Sareena Khatun
 
Call Girls in Bhubaneswar (Odisha) call me [🔝 9777949614 🔝] escort service 24X7
Call Girls in Bhubaneswar (Odisha) call me [🔝 9777949614 🔝] escort service 24X7Call Girls in Bhubaneswar (Odisha) call me [🔝 9777949614 🔝] escort service 24X7
Call Girls in Bhubaneswar (Odisha) call me [🔝 9777949614 🔝] escort service 24X7jabtakhaidam7
 
Low Cost Patna Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Gi...
Low Cost Patna Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Gi...Low Cost Patna Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Gi...
Low Cost Patna Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Gi...vershagrag
 
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证wpkuukw
 
Top profile Call Girls In Udgir [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Udgir [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Udgir [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Udgir [ 7014168258 ] Call Me For Genuine Models We ...gajnagarg
 

Recently uploaded (20)

怎样办理伍伦贡大学毕业证(UOW毕业证书)成绩单留信认证
怎样办理伍伦贡大学毕业证(UOW毕业证书)成绩单留信认证怎样办理伍伦贡大学毕业证(UOW毕业证书)成绩单留信认证
怎样办理伍伦贡大学毕业证(UOW毕业证书)成绩单留信认证
 
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
 
Abortion pills in Jeddah +966572737505 <> buy cytotec <> unwanted kit Saudi A...
Abortion pills in Jeddah +966572737505 <> buy cytotec <> unwanted kit Saudi A...Abortion pills in Jeddah +966572737505 <> buy cytotec <> unwanted kit Saudi A...
Abortion pills in Jeddah +966572737505 <> buy cytotec <> unwanted kit Saudi A...
 
怎样办理昆士兰大学毕业证(UQ毕业证书)成绩单留信认证
怎样办理昆士兰大学毕业证(UQ毕业证书)成绩单留信认证怎样办理昆士兰大学毕业证(UQ毕业证书)成绩单留信认证
怎样办理昆士兰大学毕业证(UQ毕业证书)成绩单留信认证
 
一比一维多利亚大学毕业证(victoria毕业证)成绩单学位证如何办理
一比一维多利亚大学毕业证(victoria毕业证)成绩单学位证如何办理一比一维多利亚大学毕业证(victoria毕业证)成绩单学位证如何办理
一比一维多利亚大学毕业证(victoria毕业证)成绩单学位证如何办理
 
Hilti's Latest Battery - Hire Depot.pptx
Hilti's Latest Battery - Hire Depot.pptxHilti's Latest Battery - Hire Depot.pptx
Hilti's Latest Battery - Hire Depot.pptx
 
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
 
在线办理(scu毕业证)南十字星大学毕业证电子版学位证书注册证明信
在线办理(scu毕业证)南十字星大学毕业证电子版学位证书注册证明信在线办理(scu毕业证)南十字星大学毕业证电子版学位证书注册证明信
在线办理(scu毕业证)南十字星大学毕业证电子版学位证书注册证明信
 
Call Girls Service Lucknow {0000000000 } ❤️VVIP BHAWNA Call Girl in Lucknow U.P
Call Girls Service Lucknow {0000000000 } ❤️VVIP BHAWNA Call Girl in Lucknow U.PCall Girls Service Lucknow {0000000000 } ❤️VVIP BHAWNA Call Girl in Lucknow U.P
Call Girls Service Lucknow {0000000000 } ❤️VVIP BHAWNA Call Girl in Lucknow U.P
 
Abortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in Dammam
Abortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in DammamAbortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in Dammam
Abortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in Dammam
 
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
怎样办理斯威本科技大学毕业证(SUT毕业证书)成绩单留信认证
 
Top profile Call Girls In Ratlam [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Ratlam [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Ratlam [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Ratlam [ 7014168258 ] Call Me For Genuine Models We...
 
Dubai Call Girls O525547819 Call Girls In Dubai<.> Full Dirty Services
Dubai Call Girls O525547819 Call Girls In Dubai<.> Full Dirty ServicesDubai Call Girls O525547819 Call Girls In Dubai<.> Full Dirty Services
Dubai Call Girls O525547819 Call Girls In Dubai<.> Full Dirty Services
 
Jual Obat Aborsi Samarinda ( No.1 ) 088980685493 Obat Penggugur Kandungan Cy...
Jual Obat Aborsi Samarinda (  No.1 ) 088980685493 Obat Penggugur Kandungan Cy...Jual Obat Aborsi Samarinda (  No.1 ) 088980685493 Obat Penggugur Kandungan Cy...
Jual Obat Aborsi Samarinda ( No.1 ) 088980685493 Obat Penggugur Kandungan Cy...
 
Kadi - HiFi Call Girl Service Ahmedabad Phone No 8005736733 Elite Escort Serv...
Kadi - HiFi Call Girl Service Ahmedabad Phone No 8005736733 Elite Escort Serv...Kadi - HiFi Call Girl Service Ahmedabad Phone No 8005736733 Elite Escort Serv...
Kadi - HiFi Call Girl Service Ahmedabad Phone No 8005736733 Elite Escort Serv...
 
Call Girls Amethi 9332606886 HOT & SEXY Models beautiful and charming call g...
Call Girls Amethi  9332606886 HOT & SEXY Models beautiful and charming call g...Call Girls Amethi  9332606886 HOT & SEXY Models beautiful and charming call g...
Call Girls Amethi 9332606886 HOT & SEXY Models beautiful and charming call g...
 
Call Girls in Bhubaneswar (Odisha) call me [🔝 9777949614 🔝] escort service 24X7
Call Girls in Bhubaneswar (Odisha) call me [🔝 9777949614 🔝] escort service 24X7Call Girls in Bhubaneswar (Odisha) call me [🔝 9777949614 🔝] escort service 24X7
Call Girls in Bhubaneswar (Odisha) call me [🔝 9777949614 🔝] escort service 24X7
 
Low Cost Patna Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Gi...
Low Cost Patna Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Gi...Low Cost Patna Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Gi...
Low Cost Patna Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Gi...
 
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证
一比一定(购)新西兰林肯大学毕业证(Lincoln毕业证)成绩单学位证
 
Top profile Call Girls In Udgir [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Udgir [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Udgir [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Udgir [ 7014168258 ] Call Me For Genuine Models We ...
 

Chapter-3.pdf

  • 1. Computer Graphics CHAPTER 3 INTRODUCTION TO THE RENDERING PROCESS WITH OPENGL By Asamenek.
  • 2. Overview ➢Graphics Pipeline ➢OpenGL ➢Coordinate Systems ➢Shaders Fundamentals ➢Summery ➢Lab 2 – Basic of OpenGL and Shader Language
  • 3. Graphics Pipeline(Rendering) ➢ Vectors are the basis for computer generated images specifying the vertexes in the image ➢ Changing these vertexes to beautiful image is not an easy task and it goes through many stages ➢ The Process of changing these vertexes to images is called Graphics Pipeline or Rendering Pipeline . . . Graphics Pipeline
  • 4. Graphics Pipeline ➢ The graphics pipeline has up to 7 stages. ➢ Some of these stages need to be implemented by us, some are optional to implement and some are already implemented for us ➢ The stages are executed by Shader Program ➢ Vertex Shader ➢ Tessellation Shader ➢ Geometry Shader ➢ Rasterization ➢ Clipping ➢ Primitive Setup ➢ Fragment Shader
  • 5. Graphics Pipeline – Vertex Shader ➢ Vertex shading is the stage in the rendering pipeline that handles the processing of individual vertices ➢ Vertex shaders are fed Vertex data, as specified from a vertex array object by a drawing command ➢ receives a single vertex from the vertex stream and generates a single vertex to the output vertex stream [4, 4] [8, 0] [4, -4] [-4, -4] [-8, 0] [-4, 4] V Vertex Shader [1, 0] [1, 0] [1, 0] [1, 0] [1, 0] [1, 0] V +
  • 6. Graphics Pipeline – Tessellation Shader ➢ Tessellation Shader tessellates (subdivide) the object given by the Vertex Shader ➢ This shader allows to add more detail to the already existing object Tessellation Shader
  • 7. Graphics Pipeline – Tessellation Shader ➢ Tessellation Shader tessellates (subdivide) the object given by the Vertex Shader ➢ This shader allows to more detail to the already existing object
  • 8. Graphics Pipeline – Geometry Shader ➢ Geometry Shader allows additional processing on individual primitive level like creating new primitive, removing old primitives or manipulating the existing ➢ This allows parts of the graphics to be generated only when they are needed, which saves storage of the newly generated parts ➢ Grass, Fur and similar graphics can be generated using geometry shader
  • 9. Graphics Pipeline – Primitive Assembly ➢ The previous shaders operate on vertexes and generate new vertexes and primitives ➢ The primitive assembly organize these vertexes to base primitives so that further processing is easier like rasterizing and clipping
  • 10. Graphics Pipeline – Clipping ➢ The vertexes created until now might out of the view port (the region of the window where we are permitted to draw) ➢ We use clipping stage to modify the drawing vertex is outside the view port View Port Clipping
  • 11. Graphics Pipeline – Clipping and Rasterizing ➢ The vectors that we specify have only mathematical description and doesn’t contain any information about the screen ➢Rasterization – is the process of defining candidate fragments of the primitives that can be displayed on the screen
  • 12. Graphics Pipeline – Fragment Shader ➢ Until now, we only manipulate the position of the vertexes and primitives (basic shapes) ➢ We need to manipulate the color and texture of the image ➢ In this stage, we calculate the fragments’ final color
  • 13. Coordinate systems ➢ The use of coordinate systems is fundamental to computer graphics ➢ Coordinate systems are used to describe the locations of points in space
  • 14. Summary ➢ Coordinate Systems are defined by an origin point O and set of basis vectors ➢ Basis vectors are vectors that are linearly independent and span a set of vectors V ➢ Different Coordinate systems can be used based on the problem given ➢ Changing between coordinate systems can be calculated using Transformation ➢ Transformation can be used for Rotation, Reflection, Scaling …. ➢ Homogenous coordinate system is a cartesian coordinate system with extra W component ➢ Used for applying uniform matrix operation across different transformation
  • 15. Output Primitives  Output Primitives: Basic geometric structures used to describe scenes. (points, straight line segment, circles and other conic sections, quadric surfaces, spline curve and surfaces, polygon color areas, and character strings) These picture components are often defined in a continuous space.
  • 16. Output Primitives In order to draw the primitive objects, one has to first scan convert the object. Scan convert: Refers to the operation of finding out the location of pixels to be intensified and then setting the values of corresponding bits, in the graphic memory, to the desired intensity code.
  • 17. Scan Converting A Point A random-scan (vector) system stores point-plotting instructions in the display list, and coordinate values in these instructions are converted to deflection voltages that position the electron beam at the screen locations to be plotted during each refresh cycle.
  • 18. OpenGL ➢ OpenGL (Open Graphics Library) is an API – Application Programming Interface – which is a software library for accessing features in computer graphics hardware ➢ Contains more than 500 distinct commands to create computer graphics objects and apply operation on these objects ➢ OpenGL is designed to be hardware independent and cross platform interface
  • 19. OpenGL ➢ OpenGL 1.0, first version, was release in 1994 ➢ Now the latest version is 4.3 but we will be using version 3.3 and above ➢ OpenGL uses the full graphics pipeline ➢ It is Client-Server system in which the application we write is the client which simply sends commands that manipulate images to the server ➢ The server is OpenGL implementation provided by the manufacturer of the hardware and the software of the machine
  • 20. OpenGL – Graphics Terminologies ➢ Primitives – are basic shapes that allow to create more complex shapes – Point, Line, Triangles and their derivatives ➢ Models or Objects – are complex structures that are constructed by combining the primitives ➢ Rendering – is the process by which computer creates images from models ➢ Pixel – is the smallest visible elements of the computer/mobile display ➢ Framebuffer – is the memory space on which the pixels are stored
  • 21. OpenGL – Syntax ➢ All OpenGL function start with ‘gl’ prefix ➢ Some have glUniform*() structure describing the arguments glClear(GL_COLOR_BUFFER_BIT) glColor3f(1.0, 0.0, 0.0) glBegin(GL_POINTS) glVertex2f(0.0, 0.0) glEnd() glFlush() glUniform2f() glUniform3fv() glUniform2fv()
  • 22. Drawing using OpenGL ➢ OpenGL by itself doesn’t provide windowing functionalities apart from graphics processing commands ➢ We use PyGame to create and provide windowing functionalities ➢ We also need to initialize OpenGL with default values
  • 23. OpenGL – before all ➢ Import important libraries import pygame from OpenGL.GL import * from OpenGL.GLU import * from pygame.locals import * from OpenGL.GL.shaders import * import numpy as np
  • 24. OpenGL – Window Loop ➢ Graphical Applications need a main loop to stay open until the user closes it def main(): init() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() draw() pygame.display.flip() pygame.time.wait(10)
  • 25. Shader Language ➢ Most operations on the vertexes can be done in parallel processing ➢ Sadly, CPUs like sequential computation and not parallel computation ➢ GPUs offer parallel computation scheme, allowing us to compute thousands of operation in a single unit time
  • 26. Shader Language ➢ The graphics pipeline in computer graphics requires parallel computation ➢ Shader Language is specialized programming language for computer graphics pipeline that allows us to use the parallel computation power of the GPU ➢ Shaders must be compiled by OpenGL before loading them to memory
  • 27. Shader Language – Vertex Shader vec4 vPosition; void main() { gl_Position = vPosition; }
  • 28. Shader Language – Fragment Shader void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }
  • 29. Shader Language – Compiling and Loading Shader # read Shader File content vertexShaderContent = getFileContent("triangle.vertex.shader") fragmentShaderContent = getFileContent("triangle.fragment.shader") # compile Shader content vertexShader = compileShader(vertexShaderContent, GL_VERTEX_SHADER) fragmentShader = compileShader(fragmentShaderContent, GL_FRAGMENT_SHADER) # Compile shader program program = glCreateProgram() glAttachShader(program, vertexShader) glAttachShader(program, fragmentShader) glLinkProgram(program)
  • 30. OpenGL - Buffers ➢ OpenGL stores any kind of data on buffer memory ➢ This buffer memory need to be first allocated for specific kind of of data (position vector, color, image) ➢ Once, a buffer memory space is created, the vertexes are stored on it
  • 31. OpenGL – Creating vertexes # Create vertexes vertexes = np.array([ [0.5, 0.0, 0.0], [-0.5, 0.0, 0.0], [0, 0.5, 0.0]], dtype=np.float32)
  • 32. OpenGL – Creating Buffer Memory # Get memory space and load it with the vetrtexes triangleVBO = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, triangleVBO) glBufferData(GL_ARRAY_BUFFER, vertexes.nbytes, vertexes, GL_STATIC_DRAW)
  • 33. OpenGL – Loading the vertexes # Load the new memory space with our vertexes triangleVAO = glGenVertexArrays(1) glBindVertexArray(triangleVAO) glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * vertexes.itemsize, None)
  • 34. Summary ➢ The Graphics Pipeline – The stages in which vertexes pass through ➢ Vertex Shader – Processing individual vertexes ➢ Tessellation Shader – subdividing the patches of the model to further process in detail ➢ Geometry Shader – Processing basic primitives ➢ Primitive Assembly – organizing primitive so that it is easier for further processing ➢ Clipping – Modifying primitives by clipping vertexes outside the view port ➢ Rasterizing – Converting mathematical description of shapes to candidate fragments on the screen ➢ Fragment Shader – processing the color of individual fragments
  • 35. Summary ➢ OpenGL – API for processing computer graphics ➢ Cross Platform and Hardware Independent ➢ Client-Server Architecture ➢ Doesn’t contain windowing functionality, so we use PyGame’s windowing functionality ➢ Shaders ➢ Small programs of computer graphics that run on GPU for parallel computation of vertexes and primitives ➢ Must be compiled by OpenGL and loaded to memory
  • 36. CG – Lab 2 Hello World in OpenGL ➢ Create a “shader” program, compile and load it in OpenGL ➢ Create our triangle vertices and load it to GPU ➢ Draw the vertexes – A Triangle