diff --git a/Gemfile.lock b/Gemfile.lock index ea56105..b034655 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -25,4 +25,4 @@ DEPENDENCIES opengl-bindings BUNDLED WITH - 1.17.3 + 2.1.4 diff --git a/lib/common_methods.rb b/lib/common_methods.rb index 2ab0945..13ac966 100644 --- a/lib/common_methods.rb +++ b/lib/common_methods.rb @@ -43,12 +43,12 @@ class IMICFPS draw_rect(0, 0, window.width, window.height, color) end - def handleGlError + def gl_error? e = glGetError() if e != GL_NO_ERROR $stderr.puts "OpenGL error detected by handler at: #{caller[0]}" $stderr.puts " #{gluErrorString(e)} (#{e})\n" - exit + exit if $debug && $debug.get(:opengl_error_panic) end end end diff --git a/lib/manifest.rb b/lib/manifest.rb index 224f279..8749a49 100644 --- a/lib/manifest.rb +++ b/lib/manifest.rb @@ -2,6 +2,7 @@ class IMICFPS class Manifest attr_reader :name, :model, :collision, :collision_mesh, :collision_resolution, :physics, :scripts, :uses def initialize(manifest_file: nil, package: nil, name: nil) + unless manifest_file raise "Entity package not specified!" unless package raise "Entity name not specified!" unless name @@ -10,6 +11,7 @@ class IMICFPS raise "No manifest found at: #{manifest_file}" unless File.exist?(manifest_file) + @file = manifest_file parse(manifest_file) end @@ -55,4 +57,4 @@ class IMICFPS Script = Struct.new(:name, :source) Dependency = Struct.new(:package, :name) end -end \ No newline at end of file +end diff --git a/lib/map.rb b/lib/map.rb index 8057ff0..7e09cb9 100644 --- a/lib/map.rb +++ b/lib/map.rb @@ -2,6 +2,7 @@ class IMICFPS class Map include EntityManager include LightManager + include CommonMethods attr_reader :collision_manager attr_reader :gravity @@ -37,23 +38,15 @@ class IMICFPS @map_loader end - def glError? - e = glGetError() - if e != GL_NO_ERROR - $stderr.puts "OpenGL error in: #{gluErrorString(e)} (#{e})\n" - exit - end - end - def render(camera) - glError? + gl_error? Gosu.gl do - glError? + gl_error? glClearColor(0,0.2,0.5,1) # skyish blue - glError? + gl_error? glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # clear the screen and the depth buffer - glError? + gl_error? @renderer.draw(camera, @lights, @entities) end @@ -66,4 +59,4 @@ class IMICFPS # @lights.each(&:update) end end -end \ No newline at end of file +end diff --git a/lib/model.rb b/lib/model.rb index 67813ae..a7422ec 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -167,25 +167,25 @@ class IMICFPS # vertices (positions) glBindBuffer(GL_ARRAY_BUFFER, @positions_buffer_id) glVertexAttribPointer(glGetAttribLocation(program, "inPosition"), 3, GL_FLOAT, GL_FALSE, 0, nil) - handleGlError + gl_error? # colors glBindBuffer(GL_ARRAY_BUFFER, @colors_buffer_id) glVertexAttribPointer(glGetAttribLocation(program, "inColor"), 3, GL_FLOAT, GL_FALSE, 0, nil) - handleGlError + gl_error? # normals glBindBuffer(GL_ARRAY_BUFFER, @normals_buffer_id) glVertexAttribPointer(glGetAttribLocation(program, "inNormal"), 4, GL_FLOAT, GL_FALSE, 0, nil) - handleGlError + gl_error? if has_texture? # uvs glBindBuffer(GL_ARRAY_BUFFER, @uvs_buffer_id) glVertexAttribPointer(glGetAttribLocation(program, "inUV"), 3, GL_FLOAT, GL_FALSE, 0, nil) - handleGlError + gl_error? # texture ids glBindBuffer(GL_ARRAY_BUFFER, @textures_buffer_id) glVertexAttribPointer(glGetAttribLocation(program, "inTextureID"), 1, GL_FLOAT, GL_FALSE, 0, nil) - handleGlError + gl_error? end glBindBuffer(GL_ARRAY_BUFFER, 0) diff --git a/lib/renderer/opengl_renderer.rb b/lib/renderer/opengl_renderer.rb index e987d66..b12f0e3 100644 --- a/lib/renderer/opengl_renderer.rb +++ b/lib/renderer/opengl_renderer.rb @@ -27,7 +27,7 @@ class IMICFPS shader.uniform_float("totalLights", lights.size) - handleGlError + gl_error? draw_model(object.model) object.draw end @@ -35,7 +35,7 @@ class IMICFPS puts "Shader 'default' failed to compile, using immediate mode for rendering..." unless @immediate_mode_warning @immediate_mode_warning = true - handleGlError + gl_error? lights.each(&:draw) camera.draw @@ -48,13 +48,13 @@ class IMICFPS glRotatef(object.orientation.y, 0, 1.0, 0) glRotatef(object.orientation.z, 0, 0, 1.0) - handleGlError + gl_error? draw_mesh(object.model) object.draw glPopMatrix end - handleGlError + gl_error? end def draw_model(model) @@ -137,4 +137,4 @@ class IMICFPS end end end -end \ No newline at end of file +end diff --git a/lib/states/game_states/loading_state.rb b/lib/states/game_states/loading_state.rb index 915fb93..c1db7b0 100644 --- a/lib/states/game_states/loading_state.rb +++ b/lib/states/game_states/loading_state.rb @@ -43,10 +43,10 @@ class IMICFPS end def update - @percentage.text = "#{((@asset_index.to_f/@assets.count)*100.0).round}%" + @percentage.text = "#{((@asset_index.to_f / @assets.count) * 100.0).round}%" @act = true if @cycled - if @act && (@asset_index+1 <= @assets.count) + if @act && (@asset_index + 1 <= @assets.count) @act = false @cycled = false @@ -55,13 +55,17 @@ class IMICFPS when :model ModelLoader.new(manifest: hash[:manifest], entity: @dummy_entity) when :shader + if $debug.get(:use_shaders) shader = Shader.new(name: hash[:name], vertex: "shaders/vertex/#{hash[:name]}.glsl", fragment: "shaders/fragment/#{hash[:name]}.glsl") Shader.add(hash[:name], shader) if shader.compiled? + else + warn "Skipping shader: #{hash[:name]}..." + end else warn "Unknown asset: #{hash}" end - @asset_index+=1 + @asset_index += 1 end unless @asset_index < @assets.count diff --git a/lib/ui/commands/debug_command.rb b/lib/ui/commands/debug_command.rb index 54788aa..1b8a3a4 100644 --- a/lib/ui/commands/debug_command.rb +++ b/lib/ui/commands/debug_command.rb @@ -17,11 +17,15 @@ class IMICFPS set(:stats, false) set(:fps, false) set(:skydome, true) + set(:use_shaders, true) + set(:opengl_error_panic, false) subcommand(:boundingboxes, :boolean) subcommand(:wireframe, :boolean) subcommand(:stats, :boolean) subcommand(:skydome, :boolean) + subcommand(:use_shaders, :boolean) + subcommand(:opengl_error_panic, :boolean) end def handle(arguments, console) @@ -33,4 +37,4 @@ class IMICFPS end end end -end \ No newline at end of file +end