add capability verification and fix shader param error in spheres

db4
Joe Groff 2008-09-30 18:42:32 -07:00
parent 52a12c2387
commit dacd2dfc1c
1 changed files with 19 additions and 16 deletions

View File

@ -1,6 +1,6 @@
USING: kernel opengl.demo-support opengl.gl opengl.shaders opengl.framebuffers USING: kernel opengl.demo-support opengl.gl opengl.shaders opengl.framebuffers
opengl multiline ui.gadgets accessors sequences ui.render ui math opengl multiline ui.gadgets accessors sequences ui.render ui math locals
arrays generalizations combinators ; arrays generalizations combinators opengl.capabilities ;
IN: spheres IN: spheres
STRING: plane-vertex-shader STRING: plane-vertex-shader
@ -162,6 +162,8 @@ M: spheres-gadget distance-step ( gadget -- dz )
3array <gl-program> check-gl-program ; 3array <gl-program> check-gl-program ;
M: spheres-gadget graft* ( gadget -- ) M: spheres-gadget graft* ( gadget -- )
"2.0" { "GL_ARB_shader_objects" } require-gl-version-or-extensions
{ "GL_EXT_framebuffer_object" } require-gl-extensions
(plane-program) >>plane-program (plane-program) >>plane-program
(solid-sphere-program) >>solid-sphere-program (solid-sphere-program) >>solid-sphere-program
(texture-sphere-program) >>texture-sphere-program (texture-sphere-program) >>texture-sphere-program
@ -183,26 +185,27 @@ M: spheres-gadget ungraft* ( gadget -- )
M: spheres-gadget pref-dim* ( gadget -- dim ) M: spheres-gadget pref-dim* ( gadget -- dim )
drop { 640 480 } ; drop { 640 480 } ;
: (draw-sphere) ( program center radius surfacecolor -- ) :: (draw-sphere) ( program center radius -- )
roll program "center" glGetAttribLocation center first3 glVertexAttrib3f
[ [ "center" glGetAttribLocation swap first3 glVertexAttrib3f ] curry ] program "radius" glGetAttribLocation radius glVertexAttrib1f
[ [ "radius" glGetAttribLocation swap glVertexAttrib1f ] curry ]
[ [ "surface_color" glGetAttribLocation swap first4 glVertexAttrib4f ] curry ]
tri tri*
{ -1.0 -1.0 } { 1.0 1.0 } rect-vertices ; { -1.0 -1.0 } { 1.0 1.0 } rect-vertices ;
:: (draw-colored-sphere) ( program center radius surfacecolor -- )
program "surface_color" glGetAttribLocation surfacecolor first4 glVertexAttrib4f
program center radius (draw-sphere) ;
: sphere-scene ( gadget -- ) : sphere-scene ( gadget -- )
GL_DEPTH_BUFFER_BIT GL_COLOR_BUFFER_BIT bitor glClear GL_DEPTH_BUFFER_BIT GL_COLOR_BUFFER_BIT bitor glClear
[ [
solid-sphere-program>> [ solid-sphere-program>> [
{ {
[ "light_position" glGetUniformLocation 0.0 0.0 100.0 glUniform3f ] [ "light_position" glGetUniformLocation 0.0 0.0 100.0 glUniform3f ]
[ { 7.0 0.0 0.0 } 1.0 { 1.0 0.0 0.0 1.0 } (draw-sphere) ] [ { 7.0 0.0 0.0 } 1.0 { 1.0 0.0 0.0 1.0 } (draw-colored-sphere) ]
[ { -7.0 0.0 0.0 } 1.0 { 0.0 1.0 0.0 1.0 } (draw-sphere) ] [ { -7.0 0.0 0.0 } 1.0 { 0.0 1.0 0.0 1.0 } (draw-colored-sphere) ]
[ { 0.0 0.0 7.0 } 1.0 { 0.0 0.0 1.0 1.0 } (draw-sphere) ] [ { 0.0 0.0 7.0 } 1.0 { 0.0 0.0 1.0 1.0 } (draw-colored-sphere) ]
[ { 0.0 0.0 -7.0 } 1.0 { 1.0 1.0 0.0 1.0 } (draw-sphere) ] [ { 0.0 0.0 -7.0 } 1.0 { 1.0 1.0 0.0 1.0 } (draw-colored-sphere) ]
[ { 0.0 7.0 0.0 } 1.0 { 1.0 0.0 1.0 1.0 } (draw-sphere) ] [ { 0.0 7.0 0.0 } 1.0 { 1.0 0.0 1.0 1.0 } (draw-colored-sphere) ]
[ { 0.0 -7.0 0.0 } 1.0 { 0.0 1.0 1.0 1.0 } (draw-sphere) ] [ { 0.0 -7.0 0.0 } 1.0 { 0.0 1.0 1.0 1.0 } (draw-colored-sphere) ]
} cleave } cleave
] with-gl-program ] with-gl-program
] [ ] [
@ -271,7 +274,7 @@ M: spheres-gadget draw-gadget* ( gadget -- )
[ [
texture-sphere-program>> [ texture-sphere-program>> [
[ "surface_texture" glGetUniformLocation 0 glUniform1i ] [ "surface_texture" glGetUniformLocation 0 glUniform1i ]
[ { 0.0 0.0 0.0 } 4.0 { 1.0 0.0 0.0 1.0 } (draw-sphere) ] [ { 0.0 0.0 0.0 } 4.0 (draw-sphere) ]
bi bi
] with-gl-program ] with-gl-program
] ]