mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 23:52:35 +00:00
Fixed gl::error...
This commit is contained in:
@@ -2,6 +2,7 @@ require "opengl"
|
|||||||
require "glu"
|
require "glu"
|
||||||
require "glut"
|
require "glut"
|
||||||
require "gosu"
|
require "gosu"
|
||||||
|
require "fiddle"
|
||||||
# require "wavefront"
|
# require "wavefront"
|
||||||
|
|
||||||
require_relative "lib/wavefront/model"
|
require_relative "lib/wavefront/model"
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
class IMICFPS
|
class IMICFPS
|
||||||
class Wavefront
|
class Wavefront
|
||||||
class Material
|
class Material
|
||||||
|
def initialize(material_file)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -29,17 +29,25 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
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_CULL_FACE)
|
||||||
glEnable(GL_COLOR_MATERIAL)
|
glEnable(GL_COLOR_MATERIAL)
|
||||||
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
|
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
|
||||||
glBegin(GL_TRIANGLES) # begin drawing model
|
glBegin(GL_TRIANGLES) # begin drawing model
|
||||||
# @objects.each_with_index do |o, i|
|
@objects.each_with_index do |o, i|
|
||||||
@faces.each do |vert|
|
o.faces.each do |vert|
|
||||||
vertex = vert[0]
|
vertex = vert[0]
|
||||||
uv = vert[1]
|
uv = vert[1]
|
||||||
normal = vert[2]
|
normal = vert[2]
|
||||||
color = vert[3]
|
color = vert[3]
|
||||||
# p vert if i > 0
|
# p vert if i > 0
|
||||||
|
|
||||||
glColor3f(color.red, color.green, color.blue)
|
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_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_SPECULAR, [1,1,1,1])
|
||||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, [10.0])
|
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, [10.0])
|
||||||
glNormal3f(normal.x, normal.y, normal.z)
|
glNormal3f(normal.x*scale, normal.y*scale, normal.z*scale)
|
||||||
glVertex3f(vertex.x, vertex.y, vertex.z)
|
glVertex3f(vertex.x*scale, vertex.y*scale, vertex.z*scale)
|
||||||
end
|
end
|
||||||
glEnd
|
end
|
||||||
glDisable(GL_CULL_FACE)
|
glEnd
|
||||||
glDisable(GL_COLOR_MATERIAL)
|
glDisable(GL_CULL_FACE)
|
||||||
# end
|
glDisable(GL_COLOR_MATERIAL)
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse
|
def parse
|
||||||
@@ -68,7 +76,6 @@ class IMICFPS
|
|||||||
@material_file = array[1]
|
@material_file = array[1]
|
||||||
parse_mtllib
|
parse_mtllib
|
||||||
when 'usemtl'
|
when 'usemtl'
|
||||||
# PI*(r*r)
|
|
||||||
set_material(array[1])
|
set_material(array[1])
|
||||||
when 'o'
|
when 'o'
|
||||||
change_object(array[1])
|
change_object(array[1])
|
||||||
@@ -132,6 +139,7 @@ class IMICFPS
|
|||||||
def set_material(name)
|
def set_material(name)
|
||||||
# @current_object.
|
# @current_object.
|
||||||
end
|
end
|
||||||
|
|
||||||
def material
|
def material
|
||||||
Color.new(rand(0.1..1.0), rand(0.1..1.0), rand(0.1..1.0))
|
Color.new(rand(0.1..1.0), rand(0.1..1.0), rand(0.1..1.0))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -29,13 +29,17 @@ class IMICFPS
|
|||||||
@diffuse_light = [1, 1, 1, 1]
|
@diffuse_light = [1, 1, 1, 1]
|
||||||
@specular_light = [1, 1, 1, 1]
|
@specular_light = [1, 1, 1, 1]
|
||||||
@light_postion = [1, 1, 1, 0]
|
@light_postion = [1, 1, 1, 0]
|
||||||
|
|
||||||
# gl do
|
|
||||||
#
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
|
begin
|
||||||
|
render
|
||||||
|
rescue Gl::Error => e
|
||||||
|
p e
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def render
|
||||||
gl do
|
gl do
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # clear the screen and the depth buffer
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # clear the screen and the depth buffer
|
||||||
glShadeModel(GL_SMOOTH)
|
glShadeModel(GL_SMOOTH)
|
||||||
@@ -65,9 +69,10 @@ class IMICFPS
|
|||||||
gluLookAt(@camera.x,@camera.y,@camera.z, @angle_x,@angle_y,0, 0,1,0)
|
gluLookAt(@camera.x,@camera.y,@camera.z, @angle_x,@angle_y,0, 0,1,0)
|
||||||
|
|
||||||
color = [@c1, @c2, @c3]
|
color = [@c1, @c2, @c3]
|
||||||
@model.draw
|
@model.draw(1)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@text.split("~").each_with_index do |bit, i|
|
@text.split("~").each_with_index do |bit, i|
|
||||||
@font.draw(bit.strip, 10, @font.height*i, Float::INFINITY)
|
@font.draw(bit.strip, 10, @font.height*i, Float::INFINITY)
|
||||||
end
|
end
|
||||||
@@ -86,8 +91,8 @@ class IMICFPS
|
|||||||
@last_frame_time = Gosu.milliseconds
|
@last_frame_time = Gosu.milliseconds
|
||||||
|
|
||||||
# $window.caption = "Gosu OBJ object - FPS:#{Gosu.fps}"
|
# $window.caption = "Gosu OBJ object - FPS:#{Gosu.fps}"
|
||||||
@angle_x-=Integer(@mouse.x-self.mouse_x)
|
@angle_x+=Integer(@mouse.x-self.mouse_x)
|
||||||
@angle_y-=Integer(@mouse.y-self.mouse_y)
|
@angle_y+=Integer(@mouse.y-self.mouse_y)
|
||||||
@angle_x = @angle_x.clamp(-360, 360)
|
@angle_x = @angle_x.clamp(-360, 360)
|
||||||
@angle_y = @angle_y.clamp(-360, 360)
|
@angle_y = @angle_y.clamp(-360, 360)
|
||||||
self.mouse_x, self.mouse_y = Gosu.screen_width/2, Gosu.screen_height/2
|
self.mouse_x, self.mouse_y = Gosu.screen_width/2, Gosu.screen_height/2
|
||||||
|
|||||||
Reference in New Issue
Block a user