From e26796f42c3d623ac8a30edac0a3c6b0abbff390 Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Tue, 20 Mar 2018 11:18:16 -0500 Subject: [PATCH] Textures work! that 3 was only getting 2... Added --native to lunch game at native resolution and fullscreen. Added basic plane. --- Gemfile | 2 -- Gemfile.lock | 10 ++++++---- lib/wavefront/material.rb | 19 ++++++++++--------- lib/wavefront/object.rb | 3 ++- lib/wavefront/parser.rb | 3 +-- lib/window.rb | 11 ++++++++--- 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/Gemfile b/Gemfile index 2d8ffb0..89576b9 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,5 @@ source "https://rubygems.org" -# gem "opengl" gem "opengl-bindings" gem "glu" # gem "glut" gem "gosu" -gem "wavefront" # Gem for opening blender or blender exported object with texturing diff --git a/Gemfile.lock b/Gemfile.lock index eaca3fc..7d269d2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,12 +1,14 @@ GEM remote: https://rubygems.org/ specs: - glu (8.3.0) - glu (8.3.0-x86-mingw32) + chunky_png (1.3.10) + glu (8.2.2) + glu (8.2.2-x86-mingw32) gosu (0.13.3) gosu (0.13.3-x86-mingw32) + oily_png (1.2.1) + chunky_png (~> 1.3.7) opengl-bindings (1.6.6) - wavefront (0.1.2) PLATFORMS ruby @@ -15,8 +17,8 @@ PLATFORMS DEPENDENCIES glu gosu + oily_png opengl-bindings - wavefront BUNDLED WITH 1.16.1 diff --git a/lib/wavefront/material.rb b/lib/wavefront/material.rb index 549eb52..54125ce 100644 --- a/lib/wavefront/material.rb +++ b/lib/wavefront/material.rb @@ -17,19 +17,20 @@ class IMICFPS puts "#{name} texture #{texture_path}" @texture = Gosu::Image.new(texture_path, retro: true) array_of_pixels = @texture.to_blob - if @texture.gl_tex_info - @texture_id = @texture.gl_tex_info.tex_name - else - puts "Allocating..." - tex_names_buf = ' ' * 8 - glGenTextures(1, tex_names_buf) - @texture_id = tex_names_buf.unpack('L2').first - end + + tex_names_buf = ' ' * 8 + glGenTextures(1, tex_names_buf) + @texture_id = tex_names_buf.unpack('L2').first + glBindTexture(GL_TEXTURE_2D, @texture_id) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, @texture.width, @texture.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, array_of_pixels) - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) glGenerateMipmap(GL_TEXTURE_2D) + + @texture = nil end def texture_id diff --git a/lib/wavefront/object.rb b/lib/wavefront/object.rb index cc1bb2a..58ccf1a 100644 --- a/lib/wavefront/object.rb +++ b/lib/wavefront/object.rb @@ -49,11 +49,12 @@ class IMICFPS def flattened_textures unless @textures_list list = [] - @faces.each do |face| + @faces.each_with_index do |face, i| [face[1]].each do |v| next unless v list << v.x list << v.y + list << v.z end end diff --git a/lib/wavefront/parser.rb b/lib/wavefront/parser.rb index 1a92869..b53623a 100644 --- a/lib/wavefront/parser.rb +++ b/lib/wavefront/parser.rb @@ -59,7 +59,6 @@ class IMICFPS file = File.open(@object_path.sub(File.basename(@object_path), '')+@material_file, 'r') file.readlines.each do |line| array = line.strip.split(' ') - # puts array.join case array.first when 'newmtl' material = Material.new(array.last) @@ -143,7 +142,7 @@ class IMICFPS if array.size == 4 texture = Vertex.new(Float(array[1]), 1-Float(array[2]), Float(array[3])) elsif array.size == 3 - texture = Vertex.new(Float(array[1]), 1-Float(array[2]), 0.0) + texture = Vertex.new(Float(array[1]), 1-Float(array[2]), 1.0) else raise end diff --git a/lib/window.rb b/lib/window.rb index a0deeb2..8bdca77 100644 --- a/lib/window.rb +++ b/lib/window.rb @@ -8,8 +8,11 @@ class IMICFPS attr_accessor :number_of_faces, :needs_cursor def initialize(window_width = 1280, window_height = 800, fullscreen = false) - super(window_width, window_height, fullscreen) - # super(Gosu.screen_width, Gosu.screen_height, true) + if ARGV.join.include?("--native") + super(Gosu.screen_width, Gosu.screen_height, true) + else + super(window_width, window_height, fullscreen) + end $window = self @needs_cursor = false @@ -17,6 +20,7 @@ class IMICFPS @number_of_faces = 0 @draw_skydome = true @skydome = Wavefront::Model.new("objects/skydome.obj") + @plane = Wavefront::Model.new("objects/plane.obj") @cube = Wavefront::Model.new("objects/cube.obj") @model = Wavefront::Model.new("objects/biped.obj") @tree = Wavefront::Model.new("objects/tree.obj") @@ -87,11 +91,12 @@ class IMICFPS @skydome.draw(0,0,0, 1, false) if @draw_skydome @cube.draw(0,1,-2, 0.0005) + @plane.draw(0,-1,-4, 0.0005, false) @model.draw(1, 0, 0) @tree.draw(5, 0, 0) @tree.draw(5, 0, 3) @tree.draw(3, 0, 10) - @mega_model.draw(0,0,0, 1) + # @mega_model.draw(0,0,0, 1) end # Draw crosshair