CapsAdmin

Untitled

Mar 26th, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.51 KB | None | 0 0
  1. if not INIT then
  2.     glfw.OpenWindow(512, 512, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)
  3.     glfw.SetWindowTitle("me#2")
  4.     INIT = true
  5. end
  6.  
  7. local obj = luadata.ReadFile("teapot.obj", obj)
  8.  
  9. if #obj == 0 then
  10.  
  11.     http.Get("groups.csail.mit.edu/graphics/classes/6.837/F03/models/teapot.obj", function(data)
  12.         obj = {}
  13.         local uh = 0
  14.         local temp
  15.         for typ, x,y,z in data.content:gmatch("(.)%s(.-)%s(.-)%s(.-)\n") do
  16.             x = tonumber(x)
  17.             y = tonumber(y)
  18.             z = tonumber(z)
  19.             if typ == "v" then
  20.                 if uh == 3 then
  21.                     table.insert(obj, temp)
  22.                     temp = nil
  23.                     uh = 0
  24.                 else
  25.                     temp = temp or {}
  26.                     table.insert(temp, {x=x,y=y,z=z})
  27.                     uh = uh + 1
  28.                 end
  29.             end
  30.         end
  31.         luadata.WriteFile("teapot.obj", obj)
  32.         print("loaded obj")
  33.     end)
  34.  
  35. end
  36.  
  37. hook.Add("OnUpdate", "gl", function()
  38.     local width, height = glfw.GetWindowSize()
  39.     local frame = glfw.GetTime()*10
  40.  
  41.     gl.Viewport(0, 0, width, height)
  42.  
  43.     gl.ClearColor(0, 0, 0, 1)
  44.     gl.Clear(GL_COLOR_BUFFER_BIT)
  45.  
  46.     gl.MatrixMode(GL_PROJECTION)
  47.     gl.LoadIdentity()
  48.     glu.Perspective(90, width/height, 1, 100)
  49.  
  50.     gl.MatrixMode(GL_MODELVIEW)
  51.     gl.LoadIdentity()
  52.     glu.LookAt(
  53.         0, -7, 0,
  54.         0, 0, 0,
  55.         0, 0, 1
  56.     )
  57.  
  58.     gl.Rotate(frame, 0.25, 1, 0.75)
  59.  
  60.     gl.Begin(GL_TRIANGLES)
  61.         for key, tris in ipairs(obj) do
  62.             gl.Color3(1, 0, 0)
  63.             gl.Vertex3(tris[1].x, tris[1].y, tris[1].z)
  64.             gl.Color3(0, 1, 0)
  65.             gl.Vertex3(tris[2].x, tris[2].y, tris[2].z)
  66.             gl.Color3(0, 0, 1)
  67.             gl.Vertex3(tris[3].x, tris[3].y, tris[3].z)
  68.         end
  69.     gl.End()
  70.  
  71.     glfw.SwapBuffers()
  72. end)
Advertisement
Add Comment
Please, Sign In to add comment