mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 15:42:35 +00:00
Added Texture object for handling creating and caching textures, stubbed ParticleEmitter
This commit is contained in:
BIN
assets/base/shared/particles/smoke/smoke.png
Normal file
BIN
assets/base/shared/particles/smoke/smoke.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.0 KiB |
@@ -5,4 +5,7 @@ on.create do |event|
|
|||||||
map.insert_entity("base", "information_panel", event.entity.position + Vector.new(0.5, 0, 3), Vector.new(0, 90, 0))
|
map.insert_entity("base", "information_panel", event.entity.position + Vector.new(0.5, 0, 3), Vector.new(0, 90, 0))
|
||||||
map.insert_entity("base", "door", event.entity.position + Vector.new(3.3, 0, 6), Vector.new(0, 0, 0))
|
map.insert_entity("base", "door", event.entity.position + Vector.new(3.3, 0, 6), Vector.new(0, 0, 0))
|
||||||
map.insert_entity("base", "door", event.entity.position + Vector.new(3.3, 0, 6), Vector.new(0, 180, 0))
|
map.insert_entity("base", "door", event.entity.position + Vector.new(3.3, 0, 6), Vector.new(0, 180, 0))
|
||||||
|
|
||||||
|
map.insert_particle_emitter(Vector.new(3.0, 15.379, 0.029), Texture.new("base", "shared", "particles", "smoke", "smoke.png"))
|
||||||
|
map.insert_particle_emitter(Vector.new(5.0, 15.379, 0.029), Texture.new("base", "shared", "particles", "smoke", "smoke.png"))
|
||||||
end
|
end
|
||||||
@@ -79,12 +79,14 @@ require_relative "lib/components/building"
|
|||||||
|
|
||||||
require_relative "lib/game_objects/entity"
|
require_relative "lib/game_objects/entity"
|
||||||
require_relative "lib/game_objects/light"
|
require_relative "lib/game_objects/light"
|
||||||
|
require_relative "lib/game_objects/particle_emitter"
|
||||||
|
|
||||||
require_relative "lib/game_objects/camera"
|
require_relative "lib/game_objects/camera"
|
||||||
require_relative "lib/game_objects/entities/player"
|
require_relative "lib/game_objects/entities/player"
|
||||||
require_relative "lib/game_objects/entities/skydome"
|
require_relative "lib/game_objects/entities/skydome"
|
||||||
require_relative "lib/game_objects/entities/terrain"
|
require_relative "lib/game_objects/entities/terrain"
|
||||||
|
|
||||||
|
require_relative "lib/texture"
|
||||||
require_relative "lib/model"
|
require_relative "lib/model"
|
||||||
require_relative "lib/model_cache"
|
require_relative "lib/model_cache"
|
||||||
require_relative "lib/model/parser"
|
require_relative "lib/model/parser"
|
||||||
|
|||||||
@@ -19,21 +19,7 @@ class IMICFPS
|
|||||||
|
|
||||||
@devisor = 500.0
|
@devisor = 500.0
|
||||||
@name_image = Gosu::Image.from_text("#{Etc.getlogin}", 100, font: "Consolas", align: :center)
|
@name_image = Gosu::Image.from_text("#{Etc.getlogin}", 100, font: "Consolas", align: :center)
|
||||||
# @name_image.save("temp.png")
|
@name_texture_id = Texture.new(@name_image).id
|
||||||
# @name_tex = @name_image.gl_tex_info
|
|
||||||
array_of_pixels = @name_image.to_blob
|
|
||||||
|
|
||||||
tex_names_buf = ' ' * 8
|
|
||||||
glGenTextures(1, tex_names_buf)
|
|
||||||
@name_texture_id = tex_names_buf.unpack('L2').first
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, @name_texture_id)
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, @name_image.width, @name_image.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, array_of_pixels)
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)
|
|
||||||
glGenerateMipmap(GL_TEXTURE_2D)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw_nameplate
|
def draw_nameplate
|
||||||
|
|||||||
10
lib/game_objects/particle_emitter.rb
Normal file
10
lib/game_objects/particle_emitter.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class IMICFPS
|
||||||
|
def initialize(position:, image:, interval: 1_500, time_to_live: 3_000, max_particles: 500)
|
||||||
|
end
|
||||||
|
|
||||||
|
def draw
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -31,5 +31,8 @@ class IMICFPS
|
|||||||
def entities
|
def entities
|
||||||
@entities
|
@entities
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def insert_particle_emitter(position, texture)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -13,23 +13,7 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def set_texture(texture_path)
|
def set_texture(texture_path)
|
||||||
# puts "#{name} texture #{texture_path}"
|
@texture_id = Texture.new(texture_path).id
|
||||||
@texture = Gosu::Image.new(texture_path, retro: false)
|
|
||||||
array_of_pixels = @texture.to_blob
|
|
||||||
|
|
||||||
tex_names_buf = ' ' * 8
|
|
||||||
glGenTextures(1, tex_names_buf)
|
|
||||||
@texture_id = tex_names_buf.unpack('L2').first
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, @texture_id)
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, @texture.width, @texture.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, array_of_pixels)
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)
|
|
||||||
glGenerateMipmap(GL_TEXTURE_2D)
|
|
||||||
|
|
||||||
@texture = nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
62
lib/texture.rb
Normal file
62
lib/texture.rb
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
class IMICFPS
|
||||||
|
class Texture
|
||||||
|
include CommonMethods
|
||||||
|
|
||||||
|
CACHE = {}
|
||||||
|
|
||||||
|
def self.release_textures
|
||||||
|
CACHE.values.each do |id|
|
||||||
|
glDeleteTextures(id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
attr_reader :id
|
||||||
|
def initialize(*path)
|
||||||
|
if path.size > 1
|
||||||
|
path = "#{GAME_ROOT_PATH}/assets/#{path.join("/")}"
|
||||||
|
else
|
||||||
|
path = path.first
|
||||||
|
end
|
||||||
|
|
||||||
|
unless path.is_a?(String)
|
||||||
|
@id = create_from_image(path)
|
||||||
|
else
|
||||||
|
@id = from_cache(path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def from_cache(path)
|
||||||
|
CACHE[path] = create_from_image(path) unless CACHE[path]
|
||||||
|
|
||||||
|
return CACHE[path]
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_from_image(path_or_image)
|
||||||
|
puts "Allocating texture for: #{path_or_image}" if window.config.get(:debug_options, :stats)
|
||||||
|
|
||||||
|
texture = nil
|
||||||
|
if path_or_image.is_a?(Gosu::Image)
|
||||||
|
texture = path_or_image
|
||||||
|
else
|
||||||
|
texture = Gosu::Image.new(path_or_image, retro: false)
|
||||||
|
end
|
||||||
|
|
||||||
|
array_of_pixels = texture.to_blob
|
||||||
|
|
||||||
|
tex_names_buf = ' ' * 8
|
||||||
|
glGenTextures(1, tex_names_buf)
|
||||||
|
texture_id = tex_names_buf.unpack('L2').first
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, texture_id)
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture.width, texture.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, array_of_pixels)
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)
|
||||||
|
glGenerateMipmap(GL_TEXTURE_2D)
|
||||||
|
gl_error?
|
||||||
|
|
||||||
|
return texture_id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user