Handbook
Glossary
terrain-world
Vocabulary
terrain
Definition
USING:
game.worlds
;
IN:
terrain
TUPLE:
terrain-world
<
game-world
{
player
player
initial:
T{
player
}
}
sky-image sky-texture
sky-program terrain terrain-segment terrain-texture
terrain-program terrain-mesh history
;
Methods
USING:
accessors
game.worlds
grid-meshes
kernel
math.matrices.simd
math.vectors.simd
noise
opengl.capabilities
opengl.gl
opengl.shaders
opengl.textures
terrain
terrain.generation
terrain.shaders
;
M:
terrain-world
begin-game-world
"2.0"
{
"GL_ARB_vertex_buffer_object"
"GL_ARB_shader_objects"
}
require-gl-version-or-extensions
GL_DEPTH_TEST
glEnable
GL_TEXTURE_2D
glEnable
GL_VERTEX_ARRAY
glEnableClientState
<player>
>>player
V{
}
clone
>>history
<perlin-noise-table>
0.01
float-4-with
scale-matrix4
{
512 512
}
perlin-noise-image
[
>>sky-image
]
keep
make-texture
[
set-texture-parameters
]
keep
>>sky-texture
<terrain>
[
>>terrain
]
keep
float-4{
0.0 0.0 0.0 1.0
}
terrain-segment
[
>>terrain-segment
]
keep
make-texture
[
set-texture-parameters
]
keep
>>terrain-texture
sky-vertex-shader
sky-pixel-shader
<simple-gl-program>
>>sky-program
terrain-vertex-shader
terrain-pixel-shader
<simple-gl-program>
>>terrain-program
terrain-vertex-size
<grid-mesh>
>>terrain-mesh
drop
;
USING:
accessors
combinators
grid-meshes
kernel
opengl
opengl.gl
opengl.shaders
sequences
terrain
ui.gadgets.worlds
;
M:
terrain-world
draw-world*
{
[
set-modelview-matrix
]
[
terrain-texture>>
GL_TEXTURE_2D
GL_TEXTURE0
bind-texture-unit
]
[
sky-texture>>
GL_TEXTURE_2D
GL_TEXTURE1
bind-texture-unit
]
[
GL_DEPTH_TEST
glDisable
dup
sky-program>>
[
[
nip
"sky"
glGetUniformLocation
1
glUniform1i
]
[
"sky_gradient"
glGetUniformLocation
swap
sky-gradient
glUniform1f
]
[
"sky_theta"
glGetUniformLocation
swap
sky-theta
glUniform1f
]
2tri
{
-1.0 -1.0
}
{
2.0 2.0
}
gl-fill-rect
]
with-gl-program
]
[
GL_DEPTH_TEST
glEnable
dup
terrain-program>>
[
[
"heightmap"
glGetUniformLocation
0
glUniform1i
]
[
"component_scale"
glGetUniformLocation
COMPONENT-SCALE
first4
glUniform4f
]
bi
terrain-mesh>>
draw-grid-mesh
]
with-gl-program
]
}
cleave
gl-error
;
USING:
accessors
combinators
destructors
game.worlds
opengl.shaders
opengl.textures
terrain
;
M:
terrain-world
end-game-world
{
[
terrain-mesh>>
dispose
]
[
terrain-program>>
delete-gl-program
]
[
terrain-texture>>
delete-texture
]
[
sky-program>>
delete-gl-program
]
[
sky-texture>>
delete-texture
]
}
cleave
;
USING:
accessors
kernel
opengl
opengl.gl
terrain
ui.gadgets.worlds
;
M:
terrain-world
resize-world
GL_PROJECTION
glMatrixMode
glLoadIdentity
dim>>
[
[
{
0 0
}
]
dip
gl-viewport
]
[
frustum
glFrustum
]
bi
;
USING:
accessors
game.worlds
kernel
terrain
;
M:
terrain-world
tick-game-world
[
dup
focused?>>
[
handle-input
]
[
drop
]
if
]
[
dup
player>>
tick-player
]
bi
;