Permalink
Browse files

Adds textures to the master

  • Loading branch information...
dorsath committed Feb 11, 2012
2 parents 05836d6 + 8ea9d49 commit 5fce11b957cea711303cb15dcaeb393afcf728cd
View
@@ -8,6 +8,7 @@ GEM
ruby-progressbar (~> 0.0.10) ruby-progressbar (~> 0.0.10)
mkrf (0.2.3) mkrf (0.2.3)
rake (0.8.7) rake (0.8.7)
rmagick (2.13.1)
rspec (2.8.0) rspec (2.8.0)
rspec-core (~> 2.8.0) rspec-core (~> 2.8.0)
rspec-expectations (~> 2.8.0) rspec-expectations (~> 2.8.0)
@@ -27,5 +28,6 @@ DEPENDENCIES
fuubar fuubar
mkrf mkrf
rake rake
rmagick
rspec rspec
ruby-opengl2 ruby-opengl2
View
@@ -3,13 +3,14 @@
require 'glut' require 'glut'
require 'mathn' require 'mathn'
require 'singleton' require 'singleton'
require 'mechanics/rotation' require 'mechanics/rotation'
require 'controllers/controller' require 'controllers/controller'
require 'models/camera' require 'models/camera'
require 'textures'
require 'views/view' require 'views/view'
require 'views/window' require 'views/window'
require 'views/camera_view' require 'views/camera_view'
require 'rmagick'
View
@@ -4,8 +4,6 @@ class Spaceship
def animate def animate
rotation.yaw!(0.01) rotation.yaw!(0.01)
rotation.pitch!(-0.01)
rotation.roll!(0.02)
end end
def roll_left def roll_left
View
@@ -0,0 +1,52 @@
class Textures
include Gl, Glu, Glut
def initialize
@textures = []
@hash = {}
end
def loaded_textures
@hash.keys
end
def find key
if @hash[key].nil?
raise "No texture loaded with this name"
else
@textures[@hash[key]]
end
end
def load_all
file_names = Dir["textures/*"].map { |file| file if file.split('.').last == 'bmp' }.compact
file_names.each_with_index do |f, index|
@hash[f.split('/')[1][(0..-5)].gsub('.','_').to_sym] = index
end
@textures = glGenTextures(file_names.size)
file_names.size.times do |i|
image = Magick::Image::read(file_names[i]).first
load(@textures[i],image.to_blob,image.rows, image.columns)
end
end
def load texture, image_binary, width, height
glBindTexture(GL_TEXTURE_2D, texture) # Bind The Texture
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE )
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
#glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height, GL_BGR, GL_UNSIGNED_BYTE, image_binary )
texture
end
end
View
@@ -3,8 +3,18 @@ class Fuselage < View
def draw def draw
glMultMatrix(@model.matrix) glMultMatrix(@model.matrix)
glColor(1, 0, 0) texture = $window.textures.find(:neptunemap)
glutSolidCube 0.5
quadro = gluNewQuadric();
gluQuadricNormals(quadro, GLU_SMOOTH);
gluQuadricTexture(quadro, GL_TRUE);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture(GL_TEXTURE_2D, texture);
gluSphere(quadro, 10, 72, 72);
glDisable(GL_TEXTURE_2D);
gluDeleteQuadric(quadro);
end end
end end
View
@@ -1,11 +1,12 @@
class Window class Window
include Gl, Glu, Glut include Gl, Glu, Glut
attr_reader :controller attr_reader :controller, :textures
attr_accessor :width, :height, :title, :framerate attr_accessor :width, :height, :title, :framerate
def initialize(controller) def initialize(controller)
@controller = controller @controller = controller
@textures = Textures.new
controller.window = self controller.window = self
default_values! default_values!
end end
@@ -71,9 +72,23 @@ def start
glDepthFunc(GL_LESS) glDepthFunc(GL_LESS)
glEnable(GL_DEPTH_TEST) glEnable(GL_DEPTH_TEST)
glShadeModel(GL_SMOOTH) glShadeModel(GL_SMOOTH)
#glEnable( GL_CULL_FACE )
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
glEnable(GL_COLOR_MATERIAL)
#lighting and lighting position _Abstraction would be nice...
glEnable(GL_LIGHTING) glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0) glEnable(GL_LIGHT0)
glEnable(GL_COLOR_MATERIAL) glEnable(GL_LIGHT1)
glLightfv(GL_LIGHT0, GL_DIFFUSE, [1, 1, 1])
glLightfv(GL_LIGHT1, GL_AMBIENT, [1, 1, 1])
glLightfv(GL_LIGHT0, GL_POSITION, [0, 2, 0, 0])
textures.load_all
start_timer start_timer
View
@@ -93,9 +93,13 @@ space_wars = SpaceWars.new
window = Window.new(space_wars) window = Window.new(space_wars)
$camera = Camera.new(-2) $camera = Camera.new( -40)
$camera.pitch(Math::PI/2)
window.views << CameraView.new($camera) window.views << CameraView.new($camera)
window.views << Fuselage.new(space_wars.spaceship) window.views << Fuselage.new(space_wars.spaceship)
# window.views << SunView.new(Sun.new)
$window = window
window.start window.start
View
BIN +12.1 KB textures/Particle.bmp
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
BIN +189 KB textures/crate.tga
Binary file not shown.
View
BIN +1.43 MB textures/earthmap.bmp
Binary file not shown.
View
Binary file not shown.
View
BIN +1.5 MB textures/marsmap.bmp
Binary file not shown.
View
Binary file not shown.
View
BIN +1.5 MB textures/moonmap.bmp
Binary file not shown.
View
BIN +768 KB textures/nasalogo.bmp
Binary file not shown.
View
Binary file not shown.
View
BIN +1.43 MB textures/plutomap.bmp
Binary file not shown.
View
BIN +4.63 MB textures/saturnmap.bmp
Binary file not shown.
View
Binary file not shown.
View
BIN +1.5 MB textures/sunmap.bmp
Binary file not shown.
View
Binary file not shown.
View
BIN +1.5 MB textures/venusmap.bmp
Binary file not shown.

0 comments on commit 5fce11b

Please sign in to comment.