class BgUtils::Skybox
Public Class Methods
new(filename)
click to toggle source
# File lib/bg_utils.rb, line 3 def initialize(filename) # filename is supposed to lead to a composed texture like below : # X # XXXX # X texture = Gosu::Image.new(filename, :retro=>true) @tile_size = texture.width / 4 texture = nil # we don't need it anymore @textures = { :y_pos => Gosu::Image.new(filename, :rect => [@tile_size, 0, @tile_size, @tile_size]), :x_neg => Gosu::Image.new(filename, :rect => [0, @tile_size, @tile_size, @tile_size]), :z_neg => Gosu::Image.new(filename, :rect => [@tile_size, @tile_size, @tile_size, @tile_size]), :x_pos => Gosu::Image.new(filename, :rect => [2 * @tile_size, @tile_size, @tile_size, @tile_size]), :z_pos => Gosu::Image.new(filename, :rect => [3 * @tile_size, @tile_size, @tile_size, @tile_size]), :y_neg => Gosu::Image.new(filename, :rect => [@tile_size, 2 * @tile_size, @tile_size, @tile_size]) } self.gen_list end
Public Instance Methods
draw(x = 0, y = 0, z = 0, rot_pitch = 0, rot_yaw = 0)
click to toggle source
# File lib/bg_utils.rb, line 88 def draw(x = 0, y = 0, z = 0, rot_pitch = 0, rot_yaw = 0) glPushMatrix glTranslatef(x, y, z) glRotatef(rot_pitch, 1, 0, 0) glRotatef(rot_yaw, 0, 1, 0) glCallList(@display_list) glPopMatrix end
gen_list()
click to toggle source
# File lib/bg_utils.rb, line 33 def gen_list @display_list = glGenLists(1) glNewList(@display_list, GL_COMPILE) glDepthMask(GL_FALSE) tex = switch_texture(:z_neg) glBegin(GL_QUADS) glTexCoord2d(tex.left, tex.top); glVertex3f(-1, 1, -1) glTexCoord2d(tex.left, tex.bottom); glVertex3f(-1, -1, -1) glTexCoord2d(tex.right, tex.bottom); glVertex3f(1, -1, -1) glTexCoord2d(tex.right, tex.top); glVertex3f(1, 1, -1) glEnd tex = switch_texture(:z_pos) glBindTexture(GL_TEXTURE_2D, tex.tex_name) glBegin(GL_QUADS) glTexCoord2d(tex.left, tex.top); glVertex3f(1, 1, 1) glTexCoord2d(tex.left, tex.bottom); glVertex3f(1, -1, 1) glTexCoord2d(tex.right, tex.bottom); glVertex3f(-1, -1, 1) glTexCoord2d(tex.right, tex.top); glVertex3f(-1, 1, 1) glEnd tex = switch_texture(:x_neg) glBindTexture(GL_TEXTURE_2D, tex.tex_name) glBegin(GL_QUADS) glTexCoord2d(tex.left, tex.top); glVertex3f(-1, 1, 1) glTexCoord2d(tex.left, tex.bottom); glVertex3f(-1, -1, 1) glTexCoord2d(tex.right, tex.bottom); glVertex3f(-1, -1, -1) glTexCoord2d(tex.right, tex.top); glVertex3f(-1, 1, -1) glEnd tex = switch_texture(:x_pos) glBindTexture(GL_TEXTURE_2D, tex.tex_name) glBegin(GL_QUADS) glTexCoord2d(tex.left, tex.top); glVertex3f(1, 1, -1) glTexCoord2d(tex.left, tex.bottom); glVertex3f(1, -1, -1) glTexCoord2d(tex.right, tex.bottom); glVertex3f(1, -1, 1) glTexCoord2d(tex.right, tex.top); glVertex3f(1, 1, 1) glEnd tex = switch_texture(:y_pos) glBindTexture(GL_TEXTURE_2D, tex.tex_name) glBegin(GL_QUADS) glTexCoord2d(tex.left, tex.top); glVertex3f(-1, 1, 1) glTexCoord2d(tex.left, tex.bottom); glVertex3f(-1, 1, -1) glTexCoord2d(tex.right, tex.bottom); glVertex3f(1, 1, -1) glTexCoord2d(tex.right, tex.top); glVertex3f(1, 1, 1) glEnd tex = switch_texture(:y_neg) glBindTexture(GL_TEXTURE_2D, tex.tex_name) glBegin(GL_QUADS) glTexCoord2d(tex.left, tex.top); glVertex3f(-1, -1, -1) glTexCoord2d(tex.left, tex.bottom); glVertex3f(-1, -1, 1) glTexCoord2d(tex.right, tex.bottom); glVertex3f(1, -1, 1) glTexCoord2d(tex.right, tex.top); glVertex3f(1, -1, -1) glEnd glDepthMask(GL_TRUE) glEndList end
switch_texture(face)
click to toggle source
# File lib/bg_utils.rb, line 23 def switch_texture(face) tex = @textures[face].gl_tex_info glBindTexture(GL_TEXTURE_2D, tex.tex_name) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) return tex end