The steps in working with a shader object:
-
Create shader object:
glCreateShader(int type)
type: The type of shader to create, either GL_VERTEX_SHADER or GL_FRAGMENT_SHADER.
-
Provide shader source code:
glShaderSource(int shader, String shaderSrc)
shader: The shader created with
glCreateShader()
.shaderSrc: Shader source code.
-
Compile the shader:
glCompileShader(int shader)
shader: The shader object which already has a source code.
-
Get information about compiling after compile:
glGetShaderiv(int shader, int pname, int[] params)
shader: The shader object to get information about.
pname: Information parameter;
- GL_COMPILE_STATUS
- GL_DELETE_STATUS
- GL_INFO_LOG_LENGTH
- GL_SHADER_SOURCE_LENGTH
- GL_SHADER_TYPE
params: Integer storage location for the result of the query.
-
Get shader info log to see if error occurs and find out why:
glGetShaderInfoLog(int shader)
shader: The shader object which you want to get log info about.
-
Create program object:
glCreateProgram()
-
Attach shader object to our program object created before:
glAttachShader(int program, int shader)
program: The program object which shader will be attached to it.
shader: The shader object which will be attached to the program object created before with
glCreateProgram()
method. -
After shaders have been attached, it is ready to link shader objects together.
glLinkProgram(int program)
program: The program object which shader objects attached to it with
glAttachShader()
. -
Check the link succeeded or not:
glGetProgramiv (int program, int pname, int[] params, int offset)
program: The program object to get information about.
pname: Information parameter;
- GL_ACTIVE_ATTRIBUTES
- GL_ACTIVE_ATTRIBUTE_MAX_LENGTH
- GL_ACTIVE_UNIFORM_BLOCK
- GL_ACTIVE_UNIFORM_BLOCK_MAX_LENGTH
- GL_ACTIVE_UNIFORMS
- GL_ACTIVE_UNIFORM_MAX_LENGTH
- GL_ATTACHED_SHADERS
- GL_DELETE_STATUS
- GL_INFO_LOG_LENGTH
- GL_LINK_STATUS
- GL_PROGRAM_BINARY_RETRIEVABLE_HINT
- GL_TRANSFORM_FEEDBACK_BUFFER_MODE
- GL_TRANSFORM_FEEDBACK_VARYINGS
- GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH
- GL_VALIDATE_STATUS
params: Integer storage location for the result of the query.
-
Get program info log to see if error occurs and find out why:
glGetProgramInfoLog(int program)
program: The program object which you want to get log info about.
-
Activate the program object:
glUseProgram(int program)
program: The program object which will be activated for render process.