var texture: Texture is writable(texture_direct=)
# Texture drawn to screen
- fun texture=(value: Texture)
+ fun texture=(texture: Texture)
do
- if isset _texture and value != texture then
+ if isset _texture and texture != self.texture then
needs_update
- if value.root != texture.root then needs_remap
+ if texture.root != self.texture.root then needs_remap
end
- texture_direct = value
+ texture_direct = texture
end
# Center position of this sprite in world coordinates
var center: Point3d[Float] is writable(center_direct=), noautoinit
# Center position of this sprite in world coordinates
- fun center=(value: Point3d[Float]) is autoinit do
- if isset _center and value != center then
+ fun center=(center: Point3d[Float]) is autoinit do
+ if isset _center and center != self.center then
needs_update
- center.sprites_remove self
+ self.center.sprites_remove self
end
- value.sprites_add self
- center_direct = value
+ center.sprites_add self
+ center_direct = center
end
# Last animation set with `animate`
var display = display
assert display != null
glClear gl_COLOR_BUFFER_BIT
+
+ ui_camera.reset_height 1080.0
+ glViewport(0, 0, display.width, display.height)
frame_core_ui_sprites display
display.flip
# Second performance clock for smaller operations
private var perf_clock_sprites = new Clock is lazy
- redef fun on_create
+ redef fun create_gamnit
do
super
+ create_flat
+ end
+ # Prepare the flat framework services
+ fun create_flat
+ do
var display = display
assert display != null
- var gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
# Prepare program
var program = simple_2d_program
glViewport(0, 0, display.width, display.height)
glClearColor(0.0, 0.0, 0.0, 1.0)
- gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
# Prepare to draw
for tex in all_root_textures do
glTexParameteri(gl_TEXTURE_2D, gl_TEXTURE_MIN_FILTER, gl_LINEAR)
glTexParameteri(gl_TEXTURE_2D, gl_TEXTURE_MAG_FILTER, gl_LINEAR)
end
+
+ sprites.reset
+ ui_sprites.reset
end
redef fun on_stop
do
- # Clean up
- simple_2d_program.delete
+ super
# Close gamnit
var display = display
for sprite in ui_sprites do sprite.needs_update
end
+ redef fun on_resume
+ do
+ clock.lapse
+ super
+ end
+
redef fun frame_core(display)
do
# Check errors
- var gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
# Update game logic and set sprites
perf_clock_main.lapse
display.flip
# Check errors
- gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
end
private var frame_dt = 0.0
# draw
sprite_set.draw
+
+ assert glGetError == gl_NO_ERROR
end
# Draw world sprites from `sprites`
for sprite in sprites_to_remap do
# Skip if it was removed from this set after being modified
- if sprite.context != self then continue
+ if sprite.sprite_set != self then continue
unmap_sprite sprite
map_sprite sprite
for c in contexts_items do c.destroy
contexts_map.clear
contexts_items.clear
+ sprites_to_remap.clear
+ end
+
+ private fun reset
+ do
+ for sprite in self do
+ sprite.context = null
+ end
+
+ for c in contexts_items do c.destroy
+ contexts_map.clear
+ contexts_items.clear
+ sprites_to_remap.clear
+
+ for sprite in self do
+ map_sprite sprite
+ end
end
end
buffer_array = bufs[0]
buffer_element = bufs[1]
- var gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
end
# Destroy `buffer_array` and `buffer_element`
fun destroy
do
glDeleteBuffers([buffer_array, buffer_element])
- var gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
buffer_array = -1
buffer_element = -1
glBindBuffer(gl_ARRAY_BUFFER, buffer_array)
assert glIsBuffer(buffer_array)
glBufferData(gl_ARRAY_BUFFER, array_bytes, new Pointer.nul, usage)
- var gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
# GL_TRIANGLES 6 vertices * sprite
var n_indices = capacity * indices_per_sprite
glBindBuffer(gl_ELEMENT_ARRAY_BUFFER, buffer_element)
assert glIsBuffer(buffer_element)
glBufferData(gl_ELEMENT_ARRAY_BUFFER, element_bytes, new Pointer.nul, usage)
- gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
buffer_capacity = capacity
glBindBuffer(gl_ELEMENT_ARRAY_BUFFER, buffer_element)
glBufferSubData(gl_ELEMENT_ARRAY_BUFFER, sprite_index*6*2, 6*2, indices.native_array)
- gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
end
# Draw all `sprites`
glBindTexture(gl_TEXTURE_2D, texture.gl_texture)
app.simple_2d_program.texture.uniform 0
end
- var gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
var animation = animation_texture
if animation != null then
glBindTexture(gl_TEXTURE_2D, animation.gl_texture)
app.simple_2d_program.animation_texture.uniform 1
end
- gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
# Configure attributes, in order:
# vec4 translation, vec4 color, float scale, vec4 coord, vec2 tex_coord, vec4 rotation_row*,
glEnableVertexAttribArray p.translation.location
glVertexAttribPointeri(p.translation.location, size, gl_FLOAT, false, bytes_per_vertex, offset)
offset += size * sizeof_gl_float
- gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
size = 4
glEnableVertexAttribArray p.color.location
glVertexAttribPointeri(p.color.location, size, gl_FLOAT, false, bytes_per_vertex, offset)
offset += size * sizeof_gl_float
- gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
size = 1
glEnableVertexAttribArray p.scale.location
glVertexAttribPointeri(p.scale.location, size, gl_FLOAT, false, bytes_per_vertex, offset)
offset += size * sizeof_gl_float
- gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
size = 4
glEnableVertexAttribArray p.coord.location
glVertexAttribPointeri(p.coord.location, size, gl_FLOAT, false, bytes_per_vertex, offset)
offset += size * sizeof_gl_float
- gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
size = 2
glEnableVertexAttribArray p.tex_coord.location
glVertexAttribPointeri(p.tex_coord.location, size, gl_FLOAT, false, bytes_per_vertex, offset)
offset += size * sizeof_gl_float
- gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
size = 4
for r in [p.rotation_row0, p.rotation_row1, p.rotation_row2, p.rotation_row3] do
glVertexAttribPointeri(r.location, size, gl_FLOAT, false, bytes_per_vertex, offset)
end
offset += size * sizeof_gl_float
- gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
end
size = 1
glEnableVertexAttribArray p.animation_fps.location
glVertexAttribPointeri(p.animation_fps.location, size, gl_FLOAT, false, bytes_per_vertex, offset)
offset += size * sizeof_gl_float
- gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
size = 1
glEnableVertexAttribArray p.animation_n_frames.location
glVertexAttribPointeri(p.animation_n_frames.location, size, gl_FLOAT, false, bytes_per_vertex, offset)
offset += size * sizeof_gl_float
- gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
size = 2
glEnableVertexAttribArray p.animation_coord.location
glVertexAttribPointeri(p.animation_coord.location, size, gl_FLOAT, false, bytes_per_vertex, offset)
offset += size * sizeof_gl_float
- gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
size = 2
glEnableVertexAttribArray p.animation_tex_coord.location
glVertexAttribPointeri(p.animation_tex_coord.location, size, gl_FLOAT, false, bytes_per_vertex, offset)
offset += size * sizeof_gl_float
- gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
size = 2
glEnableVertexAttribArray p.animation_tex_diff.location
glVertexAttribPointeri(p.animation_tex_diff.location, size, gl_FLOAT, false, bytes_per_vertex, offset)
offset += size * sizeof_gl_float
- gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
size = 1
glEnableVertexAttribArray p.animation_start.location
glVertexAttribPointeri(p.animation_start.location, size, gl_FLOAT, false, bytes_per_vertex, offset)
offset += size * sizeof_gl_float
- gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
size = 1
glEnableVertexAttribArray p.animation_loops.location
glVertexAttribPointeri(p.animation_loops.location, size, gl_FLOAT, false, bytes_per_vertex, offset)
offset += size * sizeof_gl_float
- gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
# Actual draw
for s in sprites.starts, e in sprites.ends do
var l = e-s
glDrawElementsi(gl_TRIANGLES, l*indices_per_sprite, gl_UNSIGNED_SHORT, 2*s*indices_per_sprite)
- gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
end
# Take down
p.rotation_row0, p.rotation_row1, p.rotation_row2, p.rotation_row3: Attribute] do
if not attr.is_active then continue
glDisableVertexAttribArray(attr.location)
- gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
end
glBindBuffer(gl_ARRAY_BUFFER, 0)
glBindBuffer(gl_ELEMENT_ARRAY_BUFFER, 0)
- gl_error = glGetError
- assert gl_error == gl_NO_ERROR else print_error gl_error
+ assert glGetError == gl_NO_ERROR
end
end