USING: accessors alien.data colors kernel literals multiline opengl opengl.gl opengl.shaders specialized-arrays specialized-arrays.instances.alien.c-types.float ui ui.gadgets ui.pixel-formats ui.render ; QUALIFIED-WITH: alien.c-types c IN: gl-tut CONSTANT: width 640 CONSTANT: height 480 STRING: vertex-shader attribute vec4 position; void main() { gl_Position = position; } ; STRING: fragment-shader void main() { gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); } ; SPECIALIZED-ARRAY: c:float TUPLE: tut-gadgets < gadget ; CONSTANT: vertex-positions float-array{ 0.75 0.75 0.0 1.0 0.75 -0.75 0.0 1.0 -0.75 -0.75 0.0 1.0 } : initialize-program ( -- program ) vertex-shader fragment-shader ; : initialize-vertex-buffer ( -- vertex-buffer ) GL_ARRAY_BUFFER vertex-positions GL_STATIC_DRAW ; : display ( program buffer -- ) 0 0 0 0 gl-clear-color swap [ drop GL_ARRAY_BUFFER swap [ 0 glEnableVertexAttribArray 0 4 GL_FLOAT GL_FALSE 0 0 glVertexAttribPointer GL_TRIANGLES 0 3 glDrawArrays 0 glDisableVertexAttribArray ] with-gl-buffer ] with-gl-program ; : ( -- gadget ) tut-gadgets new ; M: tut-gadgets draw-gadget* ( gadget -- ) drop initialize-program initialize-vertex-buffer gen-vertex-array [ display ] with-vertex-array ; MAIN-WINDOW: gl-tut { { pref-dim { $ width $ height } } { pixel-format-attributes { double-buffered accelerated } } } >>gadgets ;