rendered paste bodyrequire "sdl"require "opengl"require "glut"module SDL class Surface def pixels p = '' for i in 0..self.w for j in 0..self.h p += self[i,j].to_s end end p end def texture t = GL.GenTextures(1).pop GL.BindTexture(GL::TEXTURE_2D, t) 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, w, h, 0, GL::RGB, GL::UNSIGNED_BYTE, pixels) @texture_cached = t end def texture_cached if !@texture_cached texture end @texture_cached end endendGLUT.InitGLUT.InitDisplayMode(GLUT::SINGLE | GLUT::RGB)GLUT.InitWindowSize(640, 480)GLUT.InitWindowPosition(150, 150)GLUT.CreateWindow($0)GL.ClearColor(0.0, 0.0, 0.0, 0.0)@grass = SDL::Surface.load("grass.png")x, y = 0, 0loop do GL.Enable(GL::TEXTURE_2D) GLU.Ortho2D(0, 640, 480, 0) GL.Clear(GL::COLOR_BUFFER_BIT | GL::DEPTH_BUFFER_BIT) GL.Begin(GL::QUADS) GL.TexCoord(0, 0) GL.Vertex(x, y) GL.TexCoord(1, 0) GL.Vertex(x + @grass.w, y) GL.TexCoord(1, 1) GL.Vertex(x + @grass.w, y + @grass.h) GL.TexCoord(0, 1) GL.Vertex(x, y + @grass.h) GL.End GL.BindTexture(GL::TEXTURE_2D, @grass.texture_cached) x += 1 y += 1 GL.MatrixMode(GL::PROJECTION) GL.LoadIdentity GL.MatrixMode(GL::MODELVIEW) GL.LoadIdentity GL.Flush sleep(0.01)end