rendered paste bodybegin
#!/usr/bin/env ruby
module RUDL
class SFont
def print_centered(*args)
end
end
end
require 'RUDL'
include RUDL
require "opengl"
require "glut"
require "mathn"
require "rational"
include Constant
require "Maps/Map001.txt"
$SCREEN = DisplaySurface.new([640,480],OPENGL|DOUBLEBUF)
$SCREEN_W = 640
$SCREEN_H = 480
$SCREEN.set_caption($map_name, $map_name)
#Camra Cordinations
$camra_x = 0
$camra_y = 0
$camra_z = 0
# rotation angle for the triangle.
rtri = 0.0
# rotation angle for the quadrilateral.
rquad = 0.0
STDOUT.sync = TRUE # flush all output to screen immediately
rot = 0.0
$Texures = []
def loadGLTextures
$Textures = GL.GenTextures($map_textures.size);
for i in 0...$map_textures.size
if ($map_textures[i].nil?)
SDL_Quit
exit (1)
end
# convert bmp from BGR to RGB - no BGR mask on Windows
image= Surface.new($map_textures[i].size, SWSURFACE, 24, [0x000000FF, 0x0000FF00, 0x00FF0000, 0])
image.blit($map_textures[i], [0,0])
# texture 0 (linear scaling)
GL.BindTexture(GL::TEXTURE_2D, $Textures[i]);
GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MAG_FILTER, GL::LINEAR);
GL.TexParameteri(GL::TEXTURE_2D, GL::TEXTURE_MIN_FILTER, GL::LINEAR);
GL.TexImage2D(GL::TEXTURE_2D, 0, 3,$map_textures[i].w, $map_textures[i].h, 0, GL::RGB, GL::UNSIGNED_BYTE, $map_textures[i].pixels)
end
end
def init(w,h)
loadGLTextures
GL.ClearColor(0.0, 0.0, 0.0, 0.0)
GL.ClearDepth(1.0)
GL.DepthFunc(GL::LESS)
GL.Enable(GL::DEPTH_TEST)
GL.MatrixMode(GL::PROJECTION)
GL.LoadIdentity()
GL.MatrixMode(GL::MODELVIEW)
end
def layer_1
for y in 1...$map.size
for x in 1...$map[y].size
GL.Begin(GL::QUADS);
GL.TexCoord(0.0, 0.0);GL.Vertex3f(0.0, 0.13 * y, 0.0)
GL.TexCoord(1.0 * x, 0.0);GL.Vertex3f(0.10 * x, 0.13 * y, 0.0)
GL.TexCoord(1.0* x,1.0 * y);GL.Vertex3f(0.10* x, 0.0, 0.0)
GL.TexCoord(0.0, 1.0 * y); GL.Vertex3f(0.0, 0.0, 0.0)
GL.End();
GL.BindTexture(GL::TEXTURE_2D, $Textures[$map[y][x]]);
end
end
end
display = Proc.new {
GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT)
GL.Enable(GL::TEXTURE_2D);
GL.Color(1.0, 1.0, 1.0)
GL.LoadIdentity()
GL.Translate($camra_x, $camra_y, 0)
layer_1
GL.Disable(GL::TEXTURE_2D);
}
reshape = Proc.new { |w, h|
GL.Viewport(0, 0, $SCREEN_W, $SCREEN_H)
GL.MatrixMode(GL::PROJECTION)
GL.LoadIdentity()
GLU.Perspective(0.0, 0.0, 10.0, 1.0)
GL.MatrixMode(GL::MODELVIEW)
}
init($SCREEN_W, $SCREEN_H)
done=false
while !done
event=EventQueue.poll
case event
when QuitEvent
done=true
when KeyDownEvent
case event.key
when K_ESCAPE
done=true
end
end
$camra_z -= 0.1 if Key.pressed?[K_PAGEUP]
$camra_z += 0.1 if Key.pressed?[K_PAGEDOWN]
$camra_y -= 0.13 if Key.pressed?[K_UP]
$camra_y += 0.13 if Key.pressed?[K_DOWN]
$camra_x += 0.10 if Key.pressed?[K_LEFT]
$camra_x -= 0.10 if Key.pressed?[K_RIGHT]
reshape.call($SCREEN_W, $SCREEN_H)
display.call
$SCREEN.flip
end
rescue
print "File error:\n"
print "------------------\n"
print "#{$!}\n"
print "#{$!.backtrace}\n"
print "------------------\n"
end