Paste: opengl error

Author: pggb
Mode: factor
Date: Fri, 12 Oct 2012 19:12:43
Plain Text |
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 <simple-gl-program> ; 

: initialize-vertex-buffer ( -- vertex-buffer )
    GL_ARRAY_BUFFER vertex-positions 
    GL_STATIC_DRAW <gl-buffer> ;


: display ( program buffer -- )
    0 0 0 0 <rgba> 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 ;

: <tut-gadgets> ( -- 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
        } }
    } <tut-gadgets> >>gadgets ;

New Annotation

Summary:
Author:
Mode:
Body: