April 02, 2020, 11:31:40 AM

Author Topic: Any chance of a GLFW port?  (Read 856 times)

Offline DruggedBunny

  • Jr. Member
  • **
  • Posts: 27
Re: Any chance of a GLFW port?
« Reply #30 on: March 19, 2020, 01:20:58 AM »
Cool... all working for me here! Thank you.

Offline DruggedBunny

  • Jr. Member
  • **
  • Posts: 27
Re: Any chance of a GLFW port?
« Reply #31 on: March 20, 2020, 12:49:46 AM »
Last one before the GLFW samples get into separation of shader files, reworking everything into classes, etc.

We finally get the interpolated RGB triangle!

3.2 Shaders Interpolation

Code: [Select]

' https://learnopengl.com/

SuperStrict

Framework GLFW.GLFWWindow

Import GLFW.GLFW
Import GLFW.GLFWOpenGL
Import GLFW.GLFWSystem

Import BRL.StandardIO

Local app_name:String = "Shaders Interpolation"

Const SCR_WIDTH:UInt = 800
Const SCR_HEIGHT:UInt = 600

Type TGameWindow Extends TGLFWWindow

Method OnFrameBufferSize (width:Int, height:Int)
glViewport (0, 0, width, height)
EndMethod

EndType

Function ProcessInput (window:TGLFWWindow)

If window.IsKeyDown (GLFW_KEY_ESCAPE)
window.SetShouldClose (True)
EndIf

EndFunction

TGLFWWindow.Hint (GLFW_CONTEXT_VERSION_MAJOR, 3)
TGLFWWindow.Hint (GLFW_CONTEXT_VERSION_MINOR, 3)
TGLFWWindow.Hint (GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE)

?MacOS ' Ewww...
TGLFWWindow.Hint (GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE)
?

Local window:TGLFWWindow = New TGameWindow.Create (SCR_WIDTH, SCR_HEIGHT, app_name)

If Not window
Print "Failed to create GLFW window!"
End
EndIf

window.MakeContextCurrent ()

gladLoadGL (glfwGetProcAddress)

Local vertexShaderSource:String

vertexShaderSource :+ "#version 330 core~n"
vertexShaderSource :+ "layout (location = 0) in vec3 aPos;~n"
vertexShaderSource :+ "layout (location = 1) in vec3 aColor;~n"
vertexShaderSource :+ "out vec3 ourColor;~n"
vertexShaderSource :+ "void main()~n"
vertexShaderSource :+ "{~n"
vertexShaderSource :+ "   gl_Position = vec4(aPos, 1.0);~n"
vertexShaderSource :+ "   ourColor = aColor;~n"
vertexShaderSource :+ "}~n"

Local vertexShader:Int = glCreateShader (GL_VERTEX_SHADER)

glShaderSource (vertexShader, 1, vertexShaderSource)
glCompileShader (vertexShader)

Local success:Int
Local infoLog:Byte [512]

glGetShaderiv (vertexShader, GL_COMPILE_STATUS, Varptr success)

If Not success
glGetShaderInfoLog (vertexShader, 512, Null, infoLog)
Print "Vertex shader compilation failed: " + String.FromCString (infoLog)
EndIf

Local fragmentShaderSource:String

fragmentShaderSource :+ "#version 330 core~n"
fragmentShaderSource :+ "out vec4 FragColor;~n"
fragmentShaderSource :+ "in vec3 ourColor;~n"
fragmentShaderSource :+ "void main()~n"
fragmentShaderSource :+ "{~n"
fragmentShaderSource :+ "   FragColor = vec4(ourColor, 1.0f);~n"
fragmentShaderSource :+ "}~n"

Local fragmentShader:Int = glCreateShader (GL_FRAGMENT_SHADER)

glShaderSource (fragmentShader, 1, fragmentShaderSource)
glCompileShader (fragmentShader)

glGetShaderiv (fragmentShader, GL_COMPILE_STATUS, Varptr success)

If Not success
glGetShaderInfoLog (fragmentShader, 512, Null, infoLog)
Print "Fragment shader compilation failed: " + String.FromCString (infoLog)
EndIf

Local shaderProgram:Int = glCreateProgram ()

glAttachShader (shaderProgram, vertexShader)
glAttachShader (shaderProgram, fragmentShader)

glLinkProgram (shaderProgram)

glGetProgramiv (shaderProgram, GL_LINK_STATUS, Varptr success)

If Not success
glGetProgramInfoLog (shaderProgram, 512, Null, infoLog)
Print "Shader program linking failed: " + String.FromCString (infoLog)
EndIf

glDeleteShader (vertexShader)
glDeleteShader (fragmentShader)

Local vertices:Float [] = [..
0.5, -0.5, 0.0, 1.0, 0.0, 0.0, ..
-0.5, -0.5, 0.0, 0.0, 1.0, 0.0, ..
0.0, 0.5, 0.0, 0.0, 0.0, 1.0]

Local VBO:UInt
Local VAO:UInt

glGenVertexArrays (1, Varptr VAO)
glGenBuffers (1, Varptr VBO)

glBindVertexArray (VAO)

glBindBuffer (GL_ARRAY_BUFFER, VBO)
glBufferData (GL_ARRAY_BUFFER, vertices.length * SizeOf (0:Float), vertices, GL_STATIC_DRAW)

glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, 6 * Sizeof (0:Float), 0:Byte Ptr)
glEnableVertexAttribArray (0)

Local attribute_offset:Int = 3 * Sizeof (0:Float)

glVertexAttribPointer (1, 3, GL_FLOAT, GL_FALSE, 6 * Sizeof (0:Float), Byte Ptr (attribute_offset))
glEnableVertexAttribArray (1)

glUseProgram (shaderProgram)

While Not window.ShouldClose ()

ProcessInput (window)

glClearColor (0.2, 0.3, 0.3, 1.0)
glClear (GL_COLOR_BUFFER_BIT)

glBindVertexArray (VAO)
glDrawArrays (GL_TRIANGLES, 0, 3)

window.SwapBuffers ()
PollSystem ()

Wend

glDeleteVertexArrays (1, Varptr VAO)
glDeleteBuffers (1, Varptr VBO)

End


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal