Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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) enter image description here

This is screenshot with GL.UseProgram(theProgram) enter image description here

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
share|improve this question
1  
In your fragment shader you use 'outputColor'. Try changing it to 'gl_FragColor'. – Basaa Jul 25 at 14:10
I have replaced all 'outputColor' to 'gl_FragColor' with no luck. Thanks for reply. – invisal Jul 25 at 15:02
Have you checked for OpenGL errors? Check for errors after your entire shader initialization, if you get an error, make your way back to the beginning by moving your error check before the function above the current one. Link for more information on the subject: opentk.com/node/1040 – Basaa Jul 25 at 15:17
I have put the Msgbox(GL.GetError().ToString()) at the GameRender() function. It said "NoError". I guess there is something wrong with shader code, but I have no experience with shader language since I am just starting OpenGL. Do you know any other shade language sample that I can quickly plug and test. – invisal Jul 25 at 15:20
1  
Okay, change ftransform() to: 'gl_ModelViewProjectionMatrix * gl_Vertex' with a semicolumn at the end. – Basaa Jul 25 at 15:47
show 3 more commentsadd comment (requires an account with 50 reputation)

1 Answer

After

#version 330
layout(location = 0) in vec4 position;

you want to use OpenGL > 2.0, this means that you need to store all your vertices in Vertex Buffer Objects (VBO) which are bound to Vertex Array Objects (VAO).

For testing you should first comment the gl_ModelViewProjectionMatrix * part and put your rectangle into the view volume (i think it was from x = -1 to x = 1 and the same for y)

share|improve this answer
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.