-USING: kernel opengl opengl.demo-support opengl.gl opengl.textures
-opengl.shaders opengl.framebuffers opengl.capabilities multiline
-ui.gadgets accessors sequences ui.render ui math locals arrays
-generalizations combinators ui.gadgets.worlds
-literals ui.pixel-formats ;
+USING: accessors arrays combinators kernel literals multiline
+opengl opengl.capabilities opengl.demo-support
+opengl.framebuffers opengl.gl opengl.shaders opengl.textures
+sequences ui ui.gadgets.worlds ui.pixel-formats ;
IN: spheres
STRING: plane-vertex-shader
{
float distance_factor = (gl_FragCoord.z * 0.5 + 0.5);
distance_factor = pow(distance_factor, 500.0)*0.5;
-
+
gl_FragColor = checker_color(object_position)
? mix(checker_color_1, checker_color_2, distance_factor)
: mix(checker_color_2, checker_color_1, distance_factor);
{
world_position = gl_ModelViewMatrix * vec4(center, 1);
sphere_position = gl_Vertex.xyz;
-
+
gl_Position = gl_ProjectionMatrix * (world_position + vec4(sphere_position * radius, 0));
-
+
vcolor = surface_color;
vradius = radius;
}
vec3 transformed_light_position = (gl_ModelViewMatrix * vec4(light_position, 1)).xyz;
vec3 direction = normalize(transformed_light_position - point);
float d = max(0.0, dot(normal, direction));
-
+
return ambient * vcolor + diffuse * vec4(d * vcolor.rgb, vcolor.a);
}
;
{ "GL_EXT_framebuffer_object" } require-gl-extensions
GL_DEPTH_TEST glEnable
GL_VERTEX_ARRAY glEnableClientState
- 0.15 0.15 1.0 1.0 glClearColor
+ 0.15 0.15 1.0 1.0 glClearColor
20.0 10.0 20.0 set-demo-orientation
(plane-program) >>plane-program
(solid-sphere-program) >>solid-sphere-program
[ plane-program>> [ delete-gl-program ] when* ]
} cleave ;
-M: spheres-world pref-dim*
- drop { 640 480 } ;
-
:: (draw-sphere) ( program center radius -- )
program "center" glGetAttribLocation center first3 glVertexAttrib3f
program "radius" glGetAttribLocation radius glVertexAttrib1f
{ -1.0 -1.0 } { 2.0 2.0 } gl-fill-rect ;
-
+
:: (draw-colored-sphere) ( program center radius surfacecolor -- )
program "surface_color" glGetAttribLocation surfacecolor first4 glVertexAttrib4f
program center radius (draw-sphere) ;
: sphere-scene ( gadget -- )
- GL_DEPTH_BUFFER_BIT GL_COLOR_BUFFER_BIT bitor glClear
+ flags{ GL_DEPTH_BUFFER_BIT GL_COLOR_BUFFER_BIT } glClear
[
solid-sphere-program>> [
{
: (draw-reflection-texture) ( gadget -- )
dup reflection-framebuffer>> [ {
- [ drop 0 0 (reflection-dim) glViewport ]
+ [ drop { 0 0 } (reflection-dim) 2array gl-viewport ]
[
GL_PROJECTION glMatrixMode
glPushMatrix glLoadIdentity
glPopMatrix 90.0 1.0 0.0 0.0 glRotatef ]
[ sphere-scene ]
[
- [ 0 0 ] dip dim>> first2 glViewport
+ [ { 0 0 } ] dip dim>> gl-viewport
GL_PROJECTION glMatrixMode
glPopMatrix
]
]
} cleave ;
-: spheres-window ( -- )
- [
- f T{ world-attributes
- { world-class spheres-world }
- { title "Spheres" }
- { pixel-format-attributes {
- windowed
- double-buffered
- T{ depth-bits { value 16 } }
- } }
- } open-window
- ] with-ui ;
-
-MAIN: spheres-window
+MAIN-WINDOW: spheres-window {
+ { world-class spheres-world }
+ { title "Spheres" }
+ { pixel-format-attributes {
+ windowed
+ double-buffered
+ T{ depth-bits { value 16 } }
+ } }
+ { pref-dim { 640 480 } }
+ } ;