mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 15:42:35 +00:00
Wireframes! Player now has a name tag.
This commit is contained in:
@@ -8,6 +8,74 @@ class IMICFPS
|
||||
|
||||
@speed = 0.05
|
||||
@old_speed = @speed
|
||||
@first_person_view = true
|
||||
|
||||
@devisor = 500.0
|
||||
@name_image = Gosu::Image.from_text("Player", 100, font: "Consolas", align: :center)
|
||||
# @name_image.save("temp.png")
|
||||
p @name_image.width/@devisor
|
||||
p @name_image.height/@devisor
|
||||
@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
|
||||
|
||||
def draw_nameplate
|
||||
_height = (@name_image.height/@devisor)
|
||||
_width = (@name_image.width/@devisor)/2
|
||||
_x = @x
|
||||
_y = normalize_bounding_box(model.bounding_box).max_y+0.05
|
||||
glDisable(GL_LIGHTING)
|
||||
glEnable(GL_COLOR_MATERIAL)
|
||||
glEnable(GL_TEXTURE_2D)
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_BLEND)
|
||||
glBindTexture(GL_TEXTURE_2D, @name_texture_id)
|
||||
glBegin(GL_TRIANGLES)
|
||||
# glColor3f(0.0,0.0,0.0)
|
||||
# TOP LEFT
|
||||
glTexCoord2f(0, 0)
|
||||
glVertex3f(_x-_width,_y+_height,@z)
|
||||
|
||||
# TOP RIGHT
|
||||
glTexCoord2f(1, 0)
|
||||
glVertex3f(_x+_width, _y+_height,@z)
|
||||
|
||||
# BOTTOM LEFT
|
||||
glTexCoord2f(0, 1)
|
||||
glVertex3f(_x-_width,_y,@z)
|
||||
|
||||
# BOTTOM LEFT
|
||||
glTexCoord2f(0, 1)
|
||||
glVertex3f(_x-_width,_y,@z)
|
||||
|
||||
# BOTTOM RIGHT
|
||||
glTexCoord2f(1, 1)
|
||||
glVertex3f(_x+_width, _y,@z)
|
||||
|
||||
# TOP RIGHT
|
||||
glTexCoord2f(1, 0)
|
||||
glVertex3f(_x+_width,_y+_height,@z)
|
||||
glEnd
|
||||
# glDisable(GL_BLEND)
|
||||
glDisable(GL_TEXTURE_2D)
|
||||
glEnable(GL_LIGHTING)
|
||||
end
|
||||
|
||||
def draw
|
||||
draw_nameplate
|
||||
super
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -54,5 +122,16 @@ class IMICFPS
|
||||
# x_offset = distance * Math.cos(@bound_model.y_rotation)
|
||||
# z_offset = distance * Math.sin(@bound_model.y_rotation)
|
||||
end
|
||||
|
||||
def button_up(id)
|
||||
case id
|
||||
when Gosu::KbX
|
||||
@y_rotation = @y_rotation+180
|
||||
@y_rotation %= 360
|
||||
when Gosu::KbF
|
||||
@first_person_view = !@first_person_view
|
||||
puts "First Person? #{@first_person_view}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,7 +15,7 @@ class IMICFPS
|
||||
|
||||
def set_texture(texture_path)
|
||||
puts "#{name} texture #{texture_path}"
|
||||
@texture = Gosu::Image.new(texture_path, retro: true)
|
||||
@texture = Gosu::Image.new(texture_path, retro: false)
|
||||
array_of_pixels = @texture.to_blob
|
||||
|
||||
tex_names_buf = ' ' * 8
|
||||
|
||||
@@ -72,7 +72,13 @@ class IMICFPS
|
||||
glColorPointer(3, GL_FLOAT, 0, o.flattened_materials)
|
||||
glNormalPointer(GL_FLOAT, 0, o.flattened_normals)
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, o.flattened_vertices_size/4)
|
||||
if $debug
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
|
||||
glDrawArrays(GL_TRIANGLES, 0, o.flattened_vertices_size/4)
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
|
||||
else
|
||||
glDrawArrays(GL_TRIANGLES, 0, o.flattened_vertices_size/4)
|
||||
end
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY)
|
||||
glDisableClientState(GL_COLOR_ARRAY)
|
||||
|
||||
Reference in New Issue
Block a user