Permalink
Browse files

Adds textures to the master

  • Loading branch information...
2 parents 05836d6 + 8ea9d49 commit 5fce11b957cea711303cb15dcaeb393afcf728cd @dorsath dorsath committed Feb 11, 2012
View
@@ -8,6 +8,7 @@ GEM
ruby-progressbar (~> 0.0.10)
mkrf (0.2.3)
rake (0.8.7)
+ rmagick (2.13.1)
rspec (2.8.0)
rspec-core (~> 2.8.0)
rspec-expectations (~> 2.8.0)
@@ -27,5 +28,6 @@ DEPENDENCIES
fuubar
mkrf
rake
+ rmagick
rspec
ruby-opengl2
View
@@ -3,13 +3,14 @@
require 'glut'
require 'mathn'
require 'singleton'
-
require 'mechanics/rotation'
require 'controllers/controller'
require 'models/camera'
+require 'textures'
require 'views/view'
require 'views/window'
require 'views/camera_view'
+require 'rmagick'
View
@@ -4,8 +4,6 @@ class Spaceship
def animate
rotation.yaw!(0.01)
- rotation.pitch!(-0.01)
- rotation.roll!(0.02)
end
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
glMultMatrix(@model.matrix)
- glColor(1, 0, 0)
- glutSolidCube 0.5
+ texture = $window.textures.find(:neptunemap)
+
+ 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
View
@@ -1,11 +1,12 @@
class Window
include Gl, Glu, Glut
- attr_reader :controller
+ attr_reader :controller, :textures
attr_accessor :width, :height, :title, :framerate
def initialize(controller)
@controller = controller
+ @textures = Textures.new
controller.window = self
default_values!
end
@@ -71,9 +72,23 @@ def start
glDepthFunc(GL_LESS)
glEnable(GL_DEPTH_TEST)
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_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
View
@@ -93,9 +93,13 @@ space_wars = SpaceWars.new
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 << Fuselage.new(space_wars.spaceship)
+# window.views << SunView.new(Sun.new)
+
+$window = window
window.start
View
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.

0 comments on commit 5fce11b

Please sign in to comment.