OpenGL is itself a big statemachine.All significant operations are done to change this machine's state.
Bold items are what programmer can do to refine.
pipe line (or shaders) of graphics workflow.
3D data -> rendered pixels.
- Vertex shader
- Shape assembley
- Geometry shader
- Tests and blending
- Fragment shader
- Rasterization
list of 3D coordinates which can be formed to triangiles.
- so the number of 3D coordinate is times of 3?
Vertex data is a list of vertices
-
vertex
a collection of data corresponds to a 3D coordinates.
-
vertex attributes
contaning many useful information such as color in addition to a 3D coordinate.
-
primitives
a hint of render type to tell OpenGL how to make up of those vertices, such as a line, a triangle or raw points
so, those vertices may not form a triangle?
- first step of the pipeline.
- takes a sigle vertex.
- transform one
3D coordinate
to another - basic processing, such as
attributes
.
- take
vertices
(orvertex
if GL_POINTS is specified) - form a
primitive shape
- takes a
primitive shape
and has the ability to generate new shape.
- mapping the primitive to pixels called
fragments
. - clipping fragments that is outd side of your view.
- a fragment is all the data needed for OpenGL to render a pixel.
- calculate the final color of one pixel.
- most advanced
effects
occured - fragment shader contains data about the
3D scene
alpha test
blending
- checks the depth value to decide if one fragment is behind another object.
- check
alpha
value and blends the objects. - pixel value may entirely different with
Fragment shader
stage when render multiple objects.
In most cases, we only have to do with Vertex shader
and Fragment shader
,Geometry shader
offen set to default.
In modern OpenGL, wo are required to define at least vertex
and fragment
shader.
- Normalized Device Coordinates
- view port transform(glViewport)
- Screen space cooordinates
create buffer
glgenBuffers(num, store address) **bind buffer
glBindBuffer(type or target, source address)copy data to buffer
glBufferData(type, size, source, data_change_type)
create vertex shader source code
using glslcreate vertex shader
glCreateShader(GL_VERTEX_SHADER)set source code of shader
glShaderSource()compile shader source
glCompileShader()check compile status
glgetShaderiv(), glGetShaderInfoLog
create vertex shader source code
using glslcreate vertex shader
glCreateShader(GL_FRAGMENT_SHADER)set source code of shader
glShaderSource()compile shader source
glCompileShader()check compile status
glgetShaderiv(), glGetShaderInfoLog
A shader program is the final linked version of multiple shaders, like excutables linked with mutiple libraries.
create shader program
glCreateProgramattach
glAttachShader(program, shader), order is importantlink
glLinkProgramcheck link errors
glGetProgramiv(), glGetProgramInfoLog()activate
glUseProgram
You can delete shaders after link
how OpenGL should interpret data
glVertexAttribPointer- glEnableVertexAttribArray
create a vao
glGenVertexArraysbind vao
glBindVertexArraycreate and configure vbo
as we said- 'unbind vao' glBindVertexArray(0)
- when use,re-bind vao
create ebo
glGenBuffers()bind buffer
glBindBuffercopy indices
glBufferDatadraw
use glDrawElements instead of glDrawArray