mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-16 08:02:36 +00:00
Broken support for textures, trying to switch to opengl-bindings gem
This commit is contained in:
@@ -2,7 +2,7 @@ class IMICFPS
|
||||
class Wavefront
|
||||
class Model
|
||||
include OpenGL
|
||||
# include GLU
|
||||
include GLU
|
||||
TextureCoordinate = Struct.new(:u, :v, :weight)
|
||||
Vertex = Struct.new(:x, :y, :z, :weight)
|
||||
Color = Struct.new(:red, :green, :blue, :alpha)
|
||||
@@ -32,14 +32,22 @@ class IMICFPS
|
||||
puts "OBJECT FACES: Name: #{o.name} #{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
|
||||
@materials.each do |key, material|
|
||||
if material.texture_id
|
||||
@model_has_texture = true
|
||||
@textured_material = key
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def draw(x, y, z, scale = MODEL_METER_SCALE, back_face_culling = true)
|
||||
# begin
|
||||
render(x,y,z, scale, back_face_culling)
|
||||
# rescue Gl::Error => e
|
||||
# p e
|
||||
# end
|
||||
e = glGetError()
|
||||
if e != GL_NO_ERROR
|
||||
$stderr.puts "OpenGL error in \"#{desc}\": #{gluErrorString(e)} (#{e})\n"
|
||||
exit
|
||||
end
|
||||
render(x,y,z, scale, back_face_culling)
|
||||
end
|
||||
|
||||
def render(x,y,z, scale, back_face_culling)
|
||||
@@ -56,10 +64,16 @@ class IMICFPS
|
||||
glEnableClientState(GL_VERTEX_ARRAY)
|
||||
glEnableClientState(GL_COLOR_ARRAY)
|
||||
glEnableClientState(GL_NORMAL_ARRAY)
|
||||
glVertexPointer(3, GL_FLOAT, 0, o.flattened_vertices)
|
||||
glColorPointer(3, GL_FLOAT, 0, o.flattened_materials)
|
||||
glNormalPointer(GL_FLOAT, 0, o.flattened_normals)
|
||||
glDrawArrays(GL_TRIANGLES, 0, o.flattened_vertices.count/3)
|
||||
if false#@model_has_texture
|
||||
glEnable(GL_TEXTURE_2D)
|
||||
glBindTexture(GL_TEXTURE_2D, @materials[@textured_material].texture_id)
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY)
|
||||
glTexCoordPointer(3, GL_FLOAT, 0, o.flattened_textures.pack("i*"))
|
||||
end
|
||||
glVertexPointer(4, GL_FLOAT, 0, o.flattened_vertices.pack("i*"))
|
||||
glColorPointer(3, GL_FLOAT, 0, o.flattened_materials.pack("i*"))
|
||||
glNormalPointer(GL_FLOAT, 0, o.flattened_normals.pack("i*"))
|
||||
glDrawArrays(GL_TRIANGLES, 0, o.flattened_vertices.count/4)
|
||||
# glBegin(GL_TRIANGLES) # begin drawing model
|
||||
# o.faces.each do |vert|
|
||||
# vertex = vert[0]
|
||||
@@ -79,10 +93,16 @@ class IMICFPS
|
||||
glDisableClientState(GL_VERTEX_ARRAY)
|
||||
glDisableClientState(GL_COLOR_ARRAY)
|
||||
glDisableClientState(GL_NORMAL_ARRAY)
|
||||
if false#@model_has_texture
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY)
|
||||
glBindTexture(GL_TEXTURE_2D, 0)
|
||||
glDisable(GL_TEXTURE_2D)
|
||||
end
|
||||
glDisable(GL_CULL_FACE) if back_face_culling
|
||||
glDisable(GL_COLOR_MATERIAL)
|
||||
end
|
||||
glPopMatrix
|
||||
$window.number_of_faces+=self.faces.size
|
||||
end
|
||||
|
||||
def parse
|
||||
@@ -156,6 +176,8 @@ class IMICFPS
|
||||
when 'Ni' # Unknown (Blender Specific?)
|
||||
when 'd' # Dissolved (Transparency)
|
||||
when 'illum' # Illumination model
|
||||
when 'map_Kd'
|
||||
# @materials[@current_material].set_texture(array[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user