Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not INIT then
- glfw.OpenWindow(512, 512, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)
- glfw.SetWindowTitle("me#2")
- INIT = true
- end
- local obj = luadata.ReadFile("teapot.obj", obj)
- if #obj == 0 then
- http.Get("groups.csail.mit.edu/graphics/classes/6.837/F03/models/teapot.obj", function(data)
- obj = {}
- local uh = 0
- local temp
- for typ, x,y,z in data.content:gmatch("(.)%s(.-)%s(.-)%s(.-)\n") do
- x = tonumber(x)
- y = tonumber(y)
- z = tonumber(z)
- if typ == "v" then
- if uh == 3 then
- table.insert(obj, temp)
- temp = nil
- uh = 0
- else
- temp = temp or {}
- table.insert(temp, {x=x,y=y,z=z})
- uh = uh + 1
- end
- end
- end
- luadata.WriteFile("teapot.obj", obj)
- print("loaded obj")
- end)
- end
- hook.Add("OnUpdate", "gl", function()
- local width, height = glfw.GetWindowSize()
- local frame = glfw.GetTime()*10
- gl.Viewport(0, 0, width, height)
- gl.ClearColor(0, 0, 0, 1)
- gl.Clear(GL_COLOR_BUFFER_BIT)
- gl.MatrixMode(GL_PROJECTION)
- gl.LoadIdentity()
- glu.Perspective(90, width/height, 1, 100)
- gl.MatrixMode(GL_MODELVIEW)
- gl.LoadIdentity()
- glu.LookAt(
- 0, -7, 0,
- 0, 0, 0,
- 0, 0, 1
- )
- gl.Rotate(frame, 0.25, 1, 0.75)
- gl.Begin(GL_TRIANGLES)
- for key, tris in ipairs(obj) do
- gl.Color3(1, 0, 0)
- gl.Vertex3(tris[1].x, tris[1].y, tris[1].z)
- gl.Color3(0, 1, 0)
- gl.Vertex3(tris[2].x, tris[2].y, tris[2].z)
- gl.Color3(0, 0, 1)
- gl.Vertex3(tris[3].x, tris[3].y, tris[3].z)
- end
- gl.End()
- glfw.SwapBuffers()
- end)
Advertisement
Add Comment
Please, Sign In to add comment