From 85a66a9f7df063cdccd45a51fe79a573296a616a Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Sun, 4 Mar 2018 13:32:19 -0600 Subject: [PATCH] Fixed gl::error... --- i-mic-fps.rb | 1 + lib/wavefront/material.rb | 2 ++ lib/wavefront/model.rb | 30 +++++++++++++++++++----------- lib/window.rb | 19 ++++++++++++------- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/i-mic-fps.rb b/i-mic-fps.rb index c827886..51738eb 100644 --- a/i-mic-fps.rb +++ b/i-mic-fps.rb @@ -2,6 +2,7 @@ require "opengl" require "glu" require "glut" require "gosu" +require "fiddle" # require "wavefront" require_relative "lib/wavefront/model" diff --git a/lib/wavefront/material.rb b/lib/wavefront/material.rb index 00bf882..5f0416b 100644 --- a/lib/wavefront/material.rb +++ b/lib/wavefront/material.rb @@ -1,6 +1,8 @@ class IMICFPS class Wavefront class Material + def initialize(material_file) + end end end end diff --git a/lib/wavefront/model.rb b/lib/wavefront/model.rb index 42c8e50..0e611e5 100644 --- a/lib/wavefront/model.rb +++ b/lib/wavefront/model.rb @@ -29,17 +29,25 @@ class IMICFPS end end - def draw + def draw(scale = 1) + begin + render(scale) + rescue Gl::Error => e + p e + end + end + + def render(scale = 1) glEnable(GL_CULL_FACE) glEnable(GL_COLOR_MATERIAL) glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE) glBegin(GL_TRIANGLES) # begin drawing model - # @objects.each_with_index do |o, i| - @faces.each do |vert| + @objects.each_with_index do |o, i| + o.faces.each do |vert| vertex = vert[0] uv = vert[1] normal = vert[2] - color = vert[3] + color = vert[3] # p vert if i > 0 glColor3f(color.red, color.green, color.blue) @@ -47,13 +55,13 @@ class IMICFPS glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [@color.red, @color.green, @color.blue, 1.0]) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [1,1,1,1]) glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, [10.0]) - glNormal3f(normal.x, normal.y, normal.z) - glVertex3f(vertex.x, vertex.y, vertex.z) + glNormal3f(normal.x*scale, normal.y*scale, normal.z*scale) + glVertex3f(vertex.x*scale, vertex.y*scale, vertex.z*scale) end - glEnd - glDisable(GL_CULL_FACE) - glDisable(GL_COLOR_MATERIAL) - # end + end + glEnd + glDisable(GL_CULL_FACE) + glDisable(GL_COLOR_MATERIAL) end def parse @@ -68,7 +76,6 @@ class IMICFPS @material_file = array[1] parse_mtllib when 'usemtl' - # PI*(r*r) set_material(array[1]) when 'o' change_object(array[1]) @@ -132,6 +139,7 @@ class IMICFPS def set_material(name) # @current_object. end + def material Color.new(rand(0.1..1.0), rand(0.1..1.0), rand(0.1..1.0)) end diff --git a/lib/window.rb b/lib/window.rb index 3419970..0f68a82 100644 --- a/lib/window.rb +++ b/lib/window.rb @@ -29,13 +29,17 @@ class IMICFPS @diffuse_light = [1, 1, 1, 1] @specular_light = [1, 1, 1, 1] @light_postion = [1, 1, 1, 0] - - # gl do - # - # end end def draw + begin + render + rescue Gl::Error => e + p e + end + end + + def render gl do glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # clear the screen and the depth buffer glShadeModel(GL_SMOOTH) @@ -65,9 +69,10 @@ class IMICFPS gluLookAt(@camera.x,@camera.y,@camera.z, @angle_x,@angle_y,0, 0,1,0) color = [@c1, @c2, @c3] - @model.draw + @model.draw(1) end + @text.split("~").each_with_index do |bit, i| @font.draw(bit.strip, 10, @font.height*i, Float::INFINITY) end @@ -86,8 +91,8 @@ class IMICFPS @last_frame_time = Gosu.milliseconds # $window.caption = "Gosu OBJ object - FPS:#{Gosu.fps}" - @angle_x-=Integer(@mouse.x-self.mouse_x) - @angle_y-=Integer(@mouse.y-self.mouse_y) + @angle_x+=Integer(@mouse.x-self.mouse_x) + @angle_y+=Integer(@mouse.y-self.mouse_y) @angle_x = @angle_x.clamp(-360, 360) @angle_y = @angle_y.clamp(-360, 360) self.mouse_x, self.mouse_y = Gosu.screen_width/2, Gosu.screen_height/2