mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 15:42:35 +00:00
Pack everything as f*? It renders!
This commit is contained in:
16
i-mic-fps.rb
16
i-mic-fps.rb
@@ -1,17 +1,17 @@
|
||||
require 'opengl'
|
||||
require 'glu'
|
||||
require "opengl"
|
||||
require "glu"
|
||||
require "gosu"
|
||||
|
||||
case OpenGL.get_platform
|
||||
when :OPENGL_PLATFORM_WINDOWS
|
||||
OpenGL.load_lib('opengl32.dll', 'C:/Windows/System32')
|
||||
GLU.load_lib('GLU32.dll', 'C:/Windows/System32')
|
||||
OpenGL.load_lib("opengl32.dll", "C:/Windows/System32")
|
||||
GLU.load_lib("GLU32.dll", "C:/Windows/System32")
|
||||
when :OPENGL_PLATFORM_MACOSX
|
||||
OpenGL.load_lib('libGL.dylib', '/System/Library/Frameworks/OpenGL.framework/Libraries')
|
||||
GLU.load_lib('libGLU.dylib', '/System/Library/Frameworks/OpenGL.framework/Libraries')
|
||||
OpenGL.load_lib("libGL.dylib", "/System/Library/Frameworks/OpenGL.framework/Libraries")
|
||||
GLU.load_lib("libGLU.dylib", "/System/Library/Frameworks/OpenGL.framework/Libraries")
|
||||
when :OPENGL_PLATFORM_LINUX
|
||||
OpenGL.load_lib('libGL.so', '/usr/lib/x86_64-linux-gnu')
|
||||
GLU.load_lib('libGLU.so', '/usr/lib/x86_64-linux-gnu')
|
||||
OpenGL.load_lib("libGL.so", "/usr/lib/x86_64-linux-gnu")
|
||||
GLU.load_lib("libGLU.so", "/usr/lib/x86_64-linux-gnu")
|
||||
else
|
||||
raise RuntimeError, "Unsupported platform."
|
||||
end
|
||||
|
||||
@@ -41,13 +41,18 @@ class IMICFPS
|
||||
end
|
||||
end
|
||||
|
||||
def draw(x, y, z, scale = MODEL_METER_SCALE, back_face_culling = true)
|
||||
def handleGlError
|
||||
e = glGetError()
|
||||
if e != GL_NO_ERROR
|
||||
$stderr.puts "OpenGL error in: #{gluErrorString(e)} (#{e})\n"
|
||||
exit
|
||||
end
|
||||
end
|
||||
|
||||
def draw(x, y, z, scale = MODEL_METER_SCALE, back_face_culling = true)
|
||||
handleGlError
|
||||
render(x,y,z, scale, back_face_culling)
|
||||
handleGlError
|
||||
end
|
||||
|
||||
def render(x,y,z, scale, back_face_culling)
|
||||
@@ -82,10 +87,10 @@ class IMICFPS
|
||||
# material = vert[3]
|
||||
#
|
||||
# glColor3f(material.diffuse.red, material.diffuse.green, material.diffuse.blue)
|
||||
# glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [material.ambient.red, material.ambient.green, material.ambient.blue, 1.0].pack("f*"))
|
||||
# glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [material.diffuse.red, material.diffuse.green, material.diffuse.blue, 1.0].pack("f*"))
|
||||
# glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [material.specular.red, material.specular.green, material.specular.blue, 1.0].pack("f*"))
|
||||
# glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, [10.0].pack("f*"))
|
||||
# # glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [material.ambient.red, material.ambient.green, material.ambient.blue, 1.0].pack("f*"))
|
||||
# # glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [material.diffuse.red, material.diffuse.green, material.diffuse.blue, 1.0].pack("f*"))
|
||||
# # glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [material.specular.red, material.specular.green, material.specular.blue, 1.0].pack("f*"))
|
||||
# # glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, [10.0].pack("f*"))
|
||||
# glNormal3f(normal.x, normal.y, normal.z) # Don't scale normals
|
||||
# glVertex3f(vertex.x, vertex.y, vertex.z)
|
||||
# end
|
||||
|
||||
@@ -32,7 +32,7 @@ class IMICFPS
|
||||
end
|
||||
|
||||
@vertices_list_size = list.size
|
||||
@vertices_list = list.pack("i*")
|
||||
@vertices_list = list.pack("f*")
|
||||
end
|
||||
|
||||
return @vertices_list
|
||||
@@ -42,6 +42,44 @@ class IMICFPS
|
||||
@vertices_list_size
|
||||
end
|
||||
|
||||
def flattened_textures
|
||||
unless @textures_list
|
||||
list = []
|
||||
@faces.each do |face|
|
||||
[face[1]].each do |v|
|
||||
next unless v
|
||||
list << v.x
|
||||
list << v.y
|
||||
end
|
||||
end
|
||||
|
||||
@textures_list_size = list.size
|
||||
@textures_list = list.pack("f*")
|
||||
end
|
||||
|
||||
return @textures_list
|
||||
end
|
||||
|
||||
def flattened_normals
|
||||
unless @normals_list
|
||||
list = []
|
||||
@faces.each do |face|
|
||||
[face[2]].each do |v|
|
||||
next unless v
|
||||
list << v.x
|
||||
list << v.y
|
||||
list << v.z
|
||||
# list << v.weight
|
||||
end
|
||||
end
|
||||
|
||||
@normals_list_size = list.size
|
||||
@normals_list = list.pack("f*")
|
||||
end
|
||||
|
||||
return @normals_list
|
||||
end
|
||||
|
||||
def flattened_materials
|
||||
unless @materials_list
|
||||
list = []
|
||||
@@ -59,49 +97,11 @@ class IMICFPS
|
||||
end
|
||||
|
||||
@materials_list_size = list.size
|
||||
@materials_list = list.pack("i*")
|
||||
@materials_list = list.pack("f*")
|
||||
end
|
||||
|
||||
return @materials_list
|
||||
end
|
||||
|
||||
def flattened_normals
|
||||
unless @normals_list
|
||||
list = []
|
||||
@faces.each do |face|
|
||||
[face[2]].each do |v|
|
||||
next unless v
|
||||
list << v.x
|
||||
list << v.y
|
||||
list << v.z
|
||||
# list << v.weight
|
||||
end
|
||||
end
|
||||
|
||||
@normals_list_size = list.size
|
||||
@normals_list = list.pack("i*")
|
||||
end
|
||||
|
||||
return @normals_list
|
||||
end
|
||||
|
||||
def flattened_textures
|
||||
unless @textures_list
|
||||
list = []
|
||||
@faces.each do |face|
|
||||
[face[1]].each do |v|
|
||||
next unless v
|
||||
list << v.x
|
||||
list << v.y
|
||||
end
|
||||
end
|
||||
|
||||
@textures_list_size = list.size
|
||||
@textures_list = list.pack("i*")
|
||||
end
|
||||
|
||||
return @textures_list
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -64,9 +64,9 @@ class IMICFPS
|
||||
#glMatrixMode(matrix) indicates that following [matrix] is going to get used
|
||||
glMatrixMode(GL_PROJECTION) # The projection matrix is responsible for adding perspective to our scene.
|
||||
glLoadIdentity # Resets current modelview matrix
|
||||
|
||||
# Calculates aspect ratio of the window. Gets perspective view. 45 is degree viewing angle, (0.1, 100) are ranges how deep can we draw into the screen
|
||||
gluPerspective(90.0, width / height, 0.1, 1000.0)
|
||||
|
||||
glMatrixMode(GL_MODELVIEW) # The modelview matrix is where object information is stored.
|
||||
glLoadIdentity
|
||||
|
||||
|
||||
Reference in New Issue
Block a user