Fixed gl::error...

This commit is contained in:
2018-03-04 13:32:19 -06:00
parent bf7a1b48db
commit 85a66a9f7d
4 changed files with 34 additions and 18 deletions

View File

@@ -2,6 +2,7 @@ require "opengl"
require "glu"
require "glut"
require "gosu"
require "fiddle"
# require "wavefront"
require_relative "lib/wavefront/model"

View File

@@ -1,6 +1,8 @@
class IMICFPS
class Wavefront
class Material
def initialize(material_file)
end
end
end
end

View File

@@ -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

View File

@@ -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