Using Shader causes triangle to disappear
Posted
by
invisal
on Game Development
See other posts from Game Development
or by invisal
Published on 2013-07-25T13:50:37Z
Indexed on
2013/10/23
22:08 UTC
Read the original article
Hit count: 353
The following is my rendering code.
Private Sub GameRender()
GL.Clear(ClearBufferMask.ColorBufferBit + ClearBufferMask.DepthBufferBit)
GL.ClearColor(Color.SkyBlue)
GL.UseProgram(theProgram)
GL.EnableClientState(ArrayCap.VertexArray)
GL.EnableClientState(ArrayCap.ColorArray)
GL.BindBuffer(BufferTarget.ArrayBuffer, vertexPositionID)
GL.DrawArrays(BeginMode.Triangles, 0, 3)
GL.DisableClientState(ArrayCap.ColorArray)
GL.DisableClientState(ArrayCap.VertexArray)
GlControl1.SwapBuffers()
End Sub
This is screenshot without GL.UseProgram(theProgram)
This is screenshot with GL.UseProgram(theProgram)
Here are my shader code that I picked from online tutorial.
Vertex Shader
#version 330
layout(location = 0) in vec4 position;
void main()
{
gl_Position = position;
}
Fragment Shader
#version 330
out vec4 outputColor;
void main()
{
outputColor = vec4(1.0f, 1.0f, 1.0f, 1.0f);
}
These are my shader creation code.
'' Initialize Shader
Dim shaderList(1) As Integer
shaderList(0) = CreateShader(ShaderType.VertexShader, strVertexShader)
shaderList(1) = CreateShader(ShaderType.FragmentShader, strFragShader)
theProgram = CreateProgram(shaderList)
GL.DeleteShader(shaderList(0))
GL.DeleteShader(shaderList(1))
Here are my helper functions
Private Function CreateShader(ByVal shaderType As ShaderType, ByVal code As String)
Dim shader As Integer = GL.CreateShader(shaderType)
GL.ShaderSource(shader, code)
GL.CompileShader(shader)
Dim status As Integer
GL.GetShader(shader, ShaderParameter.CompileStatus, status)
If status = False Then
MsgBox(GL.GetShaderInfoLog(shader))
End If
Return shader
End Function
Private Function CreateProgram(ByVal shaderList() As Integer) As Integer
Dim program As Integer = GL.CreateProgram()
For i As Integer = 0 To shaderList.Length - 1
GL.AttachShader(program, shaderList(i))
Next
GL.LinkProgram(program)
Dim status As Integer
GL.GetProgram(program, ProgramParameter.LinkStatus, status)
If status = False Then
MsgBox(GL.GetProgramInfoLog(program))
End If
For i As Integer = 0 To shaderList.Length - 1
GL.DetachShader(program, shaderList(i))
Next
Return program
End Function
© Game Development or respective owner