- opengl -> 3d space
- screen -> 2d surface pixels
- 3d coordinates ->2d pixels transformation MANAGED BY graphics pipeline
- graphics pipeline : does transformation of
- 3d space to 2d
- 2d coords to actual pixels
- 3 points in 3d space
- lets create vertices array having these 3 point's coordinates in
main.cpp
but how?
- we need to create a buffer in gpu memory
glGenBuffers(1 , &VBO);
- load vertex data to gpu buffer
//bind vbo to curr context
glBindBuffer(GL_ARRAY_BUFFER,VBO);
//adding data to context == adding data to VBO
glBufferData(
GL_ARRAY_BUFFER ,
sizeof(vertices) ,
vertices ,
GL_STATIC_DRAW
);
- need to tell gpu's program how to use this buffer. how?
- create vertex attribute pointer
glVertexAttribPointer(0,3,GL_FLOAT , GL_FALSE , 3 * sizeof(GLfloat) , 0);
glEnableVertexAttribArray(0);
- From the buffer ,this takes every "3" "float" values with "no rescaling" and 3*size(float) bytes offset b/w consecutive attributes and gives to graphics pipeline at index "0" i.e layout (location = 0)
- make vertex shader
- in our case , vertex attributes at index = 0 is simply forwarded further
- input : vec3
- output : gl_Position which is vec4
- gl_Position if sent down the pipeline
#version 330 core
layout (location = 0) in vec3 aPos;
void main(){
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
}
- make fragment shader
- output : FragColor which renders to screen!
#version 330 core
out vec4 FragColor;
void main(){
FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
}
- compile these shaders
- create shader program (i.e link shaders and make pipeline)
- hooray! our graphics pipeline is ready!
[!error] creating triangle only with VBO without VAO seems like not possible on mac with core profile link