Created
July 6, 2016 17:44
-
-
Save DCubix/db0a8aa87955ed7172b02bf03ae919b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GLGraphics 640, 480 | |
glewInit() | |
Local verts : Float[] = [-1.0, -1.0, 0.0, 1.0, -1.0, 0.0, 0.0, 1.0, 0.0] | |
Local vao : Int | |
Local vbo : Int | |
glGenVertexArrays(1, Varptr(vao)) | |
glBindVertexArray(vao) | |
glGenBuffersARB(1, Varptr(vbo)) | |
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo) | |
glBufferDataARB(GL_ARRAY_BUFFER_ARB, 3 * 3 * 4, verts, GL_STATIC_DRAW) | |
glEnableVertexAttribArrayARB(0) | |
glVertexAttribPointerARB(0, 3, GL_FLOAT, GL_FALSE, 0, Null) | |
Local VshaderCode : String | |
Local FshaderCode : String | |
ReadData str$ | |
If str$.ToInt() = 1 | |
While str$.ToInt() <> 2 | |
ReadData str$ | |
VshaderCode = VshaderCode + str | |
EndWhile | |
While str$.ToInt() <> 99 | |
ReadData str$ | |
FshaderCode = FshaderCode + str | |
EndWhile | |
VshaderCode = Left(VshaderCode, VshaderCode.length-1) | |
FshaderCode = Left(FshaderCode, FshaderCode.length-2) | |
Print "Vertex Shader: " + VshaderCode | |
Print "Fragment Shader: " + FshaderCode | |
EndIf | |
Local fs : Int = glCreateShader(GL_FRAGMENT_SHADER) | |
Local vs : Int = glCreateShader(GL_VERTEX_SHADER) | |
Local prog : Int = glCreateProgram() | |
Local vsPtr : Byte Ptr[1] | |
Local fsPtr : Byte Ptr[1] | |
vsPtr[0] = VshaderCode.ToCString() | |
fsPtr[0] = FshaderCode.ToCString() | |
glShaderSourceARB(vs, 1, vsPtr, Null) | |
glCompileShaderARB(vs) | |
glShaderSourceARB(fs, 1, fsPtr, Null) | |
glCompileShaderARB(fs) | |
glAttachShader(prog, vs) | |
glAttachShader(prog, fs) | |
glLinkProgram(prog) | |
Repeat | |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) | |
glUseProgram(prog) | |
glDrawArrays(GL_TRIANGLES, 0, 3) | |
Flip | |
Until AppTerminate() Or KeyHit(KEY_ESCAPE) | |
' Vertex Shader | |
DefData 1, "attribute vec3 position;varying vec3 P;", "void main() {", "gl_Position = vec4(position, 1.0);P=position;" , "}" | |
' Fragment Shader | |
DefData 2, "varying vec3 P;", "void main() {", "gl_FragColor = vec4(normalize(P), 1.0); }", 99 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment