Broken mouse input, texture mapping issue persists.

This commit is contained in:
2018-03-19 22:08:20 -05:00
parent a46f3deff9
commit 89c84dbe39
11 changed files with 1768 additions and 7853 deletions

View File

@@ -15,19 +15,21 @@ class IMICFPS
def set_texture(texture_path)
puts "#{name} texture #{texture_path}"
@texture = Gosu::Image.new(texture_path)
@texture = Gosu::Image.new(texture_path, retro: true)
array_of_pixels = @texture.to_blob
if @texture.gl_tex_info
@texture_id = @texture.gl_tex_info.tex_name
else
puts "Allocating..."
tex_names_buf = ' ' * 8
glGenTextures(1, tex_names_buf)
@texture_id = tex_names_buf.unpack('L2').first
end
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) unless @texture.gl_tex_info
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
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_MIN_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)
glGenerateMipmap(GL_TEXTURE_2D)
end
def texture_id

View File

@@ -25,7 +25,7 @@ class IMICFPS
@faces = []
@smoothing= 0
@bounding_box = BoundingBox.new(0.0,0.0,0.0, 0.0,0.0,0.0)
@bounding_box = BoundingBox.new(nil,nil,nil, nil,nil,nil)
@debug_color = Color.new(rand(0.0..1.0), rand(0.0..1.0), rand(0.0..1.0))
start_time = Time.now
parse
@@ -35,7 +35,7 @@ class IMICFPS
face_count = 0
@objects.each {|o| face_count+=o.faces.size}
@objects.each_with_index do |o, i|
puts "OBJECT FACES: Name: #{o.name} #{o.faces.size}, array size divided by 3: #{o.faces.size.to_f/3.0}"
puts "Model::Object Name: #{o.name} Faces: #{o.faces.size}, array size divided by 3: #{o.faces.size.to_f/3.0}"
end
$window.number_of_faces+=face_count
@model_has_texture = false
@@ -97,9 +97,9 @@ class IMICFPS
end
glDisable(GL_CULL_FACE) if back_face_culling
glDisable(GL_COLOR_MATERIAL)
render_bounding_box(o.bounding_box) if ARGV.join("--debug")
render_bounding_box(o.bounding_box, o.debug_color) if $debug
end
render_bounding_box(@bounding_box) if ARGV.join("--debug")
render_bounding_box(@bounding_box) if $debug
glPopMatrix

View File

@@ -1,7 +1,7 @@
class IMICFPS
class Wavefront
class Object
attr_reader :name, :vertices, :textures, :normals, :bounding_box
attr_reader :name, :vertices, :textures, :normals, :bounding_box, :debug_color
attr_accessor :faces
def initialize(name)
@@ -11,6 +11,7 @@ class IMICFPS
@normals = []
@faces = []
@bounding_box = BoundingBox.new(nil,nil,nil, nil,nil,nil)
@debug_color = Parser::Color.new(1.0,0.0,0.0)
# Faces array packs everything:
# vertex = index[0]
@@ -21,6 +22,8 @@ class IMICFPS
def flattened_vertices
unless @vertices_list
@debug_color = @faces.first[3].diffuse
list = []
@faces.each do |face|
[face[0]].each do |v|

View File

@@ -141,9 +141,9 @@ class IMICFPS
def add_texture_coordinate(array)
texture = nil
if array.size == 4
texture = Vertex.new(Float(array[1]), Float(array[2]), Float(array[3]))
texture = Vertex.new(Float(array[1]), 1-Float(array[2]), Float(array[3]))
elsif array.size == 3
texture = Vertex.new(Float(array[1]), Float(array[2]), 0.0)
texture = Vertex.new(Float(array[1]), 1-Float(array[2]), 0.0)
else
raise
end