Skip to content

Commit

Permalink
Added examples for using luagl to implement some of the famous
Browse files Browse the repository at this point in the history
Nehe OpenGL tutorials.
  • Loading branch information
akrinke committed Apr 6, 2013
1 parent 08bb395 commit e758f7a
Show file tree
Hide file tree
Showing 5 changed files with 319 additions and 0 deletions.
4 changes: 4 additions & 0 deletions examples/opengl/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
exampledir = $(pkgdatadir)/examples/opengl
example_DATA = \
nehe-02.slua \
nehe-03.slua \
nehe-04.slua \
nehe-05.slua \
triangle.slua

EXTRA_DIST = $(example_DATA)
61 changes: 61 additions & 0 deletions examples/opengl/nehe-02.slua
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
--[[
-- $Id$
-- NeHe OpenGL Lesson 02:
-- http://nehe.gamedev.net/tutorial/your_first_polygon/13002/
--]]

require "luagl"
require "luaglu"

local function init(w, h)
scrupp.init("NeHe Lesson 02", w, h, 32, false, true)

gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
glu.Perspective(45.0, w/h, 0.1, 100.0)

gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()

-- scrupp enables backface culling per default
-- so we need to disable it for this lesson
gl.Disable(gl.CULL_FACE)

gl.ShadeModel(gl.SMOOTH)
gl.ClearColor(0.0, 0.0, 0.0, 0.0)
gl.ClearDepth(1.0)
gl.Enable(gl.DEPTH_TEST)
gl.DepthFunc(gl.LEQUAL)
gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)
end

init(600, 400)

main = {
render = function(dt)
gl.Clear(gl.COLOR_BUFFER_BIT+gl.DEPTH_BUFFER_BIT)
gl.LoadIdentity()
gl.Translate(-1.5, 0.0, -6.0)
gl.Begin(gl.TRIANGLES)
gl.Vertex( 0.0, 1.0, 0.0)
gl.Vertex(-1.0, -1.0, 0.0)
gl.Vertex( 1.0, -1.0, 0.0)
gl.End()
gl.Translate(3.0, 0.0, 0.0)
gl.Begin(gl.QUADS)
gl.Vertex(-1.0, 1.0, 0.0)
gl.Vertex( 1.0, 1.0, 0.0)
gl.Vertex( 1.0, -1.0, 0.0)
gl.Vertex(-1.0, -1.0, 0.0)
gl.End()
end,

keypressed = function(key)
if key == "ESCAPE" then
scrupp.exit()
end
end,

-- on window resize, call the init function
resized = init
}
65 changes: 65 additions & 0 deletions examples/opengl/nehe-03.slua
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
--[[
-- $Id$
-- NeHe OpenGL Lesson 03:
-- http://nehe.gamedev.net/tutorial/adding_colour/13003/
--]]

require "luagl"
require "luaglu"

local function init(w, h)
scrupp.init("NeHe Lesson 03", w, h, 32, false, true)

gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
glu.Perspective(45.0, w/h, 0.1, 100.0)

gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()

-- scrupp enables backface culling per default
-- so we need to disable it for this lesson
gl.Disable(gl.CULL_FACE)

gl.ShadeModel(gl.SMOOTH)
gl.ClearColor(0.0, 0.0, 0.0, 0.0)
gl.ClearDepth(1.0)
gl.Enable(gl.DEPTH_TEST)
gl.DepthFunc(gl.LEQUAL)
gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)
end

init(600, 400)

main = {
render = function(dt)
gl.Clear(gl.COLOR_BUFFER_BIT+gl.DEPTH_BUFFER_BIT)
gl.LoadIdentity()
gl.Translate(-1.5, 0.0, -6.0)
gl.Begin(gl.TRIANGLES)
gl.Color(1.0, 0.0, 0.0)
gl.Vertex(0.0, 1.0, 0.0)
gl.Color(0.0, 1.0, 0.0)
gl.Vertex(-1.0, -1.0, 0.0)
gl.Color(0.0, 0.0, 1.0)
gl.Vertex( 1.0, -1.0, 0.0)
gl.End()
gl.Translate(3.0, 0.0, 0.0)
gl.Color(0.5, 0.5, 1.0)
gl.Begin(gl.QUADS)
gl.Vertex(-1.0, 1.0, 0.0)
gl.Vertex( 1.0, 1.0, 0.0)
gl.Vertex( 1.0, -1.0, 0.0)
gl.Vertex(-1.0, -1.0, 0.0)
gl.End()
end,

keypressed = function(key)
if key == "ESCAPE" then
scrupp.exit()
end
end,

-- on window resize, call the init function
resized = init
}
73 changes: 73 additions & 0 deletions examples/opengl/nehe-04.slua
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
--[[
-- $Id$
-- NeHe OpenGL Lesson 04:
-- http://nehe.gamedev.net/tutorial/rotation/14001/
--]]

require "luagl"
require "luaglu"

local rtri = 0.0
local rquad = 0.0

local function init(w, h)
scrupp.init("NeHe Lesson 04", w, h, 32, false, true)

gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
glu.Perspective(45.0, w/h, 0.1, 100.0)

gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()

-- scrupp enables backface culling per default
-- so we need to disable it for this lesson
gl.Disable(gl.CULL_FACE)

gl.ShadeModel(gl.SMOOTH)
gl.ClearColor(0.0, 0.0, 0.0, 0.0)
gl.ClearDepth(1.0)
gl.Enable(gl.DEPTH_TEST)
gl.DepthFunc(gl.LEQUAL)
gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)
end

init(600, 400)

main = {
render = function(dt)
gl.Clear(gl.COLOR_BUFFER_BIT+gl.DEPTH_BUFFER_BIT)
gl.LoadIdentity()
gl.Translate(-1.5, 0.0, -6.0)
gl.Rotate(rtri, 0.0, 1.0, 0.0)
gl.Begin(gl.TRIANGLES)
gl.Color(1.0, 0.0, 0.0)
gl.Vertex(0.0, 1.0, 0.0)
gl.Color(0.0, 1.0, 0.0)
gl.Vertex(-1.0, -1.0, 0.0)
gl.Color(0.0, 0.0, 1.0)
gl.Vertex( 1.0, -1.0, 0.0)
gl.End()
gl.LoadIdentity()
gl.Translate(1.5, 0.0, -6.0)
gl.Rotate(rquad, 1.0, 0.0, 0.0)
gl.Color(0.5, 0.5, 1.0)
gl.Begin(gl.QUADS)
gl.Vertex(-1.0, 1.0, 0.0)
gl.Vertex( 1.0, 1.0, 0.0)
gl.Vertex( 1.0, -1.0, 0.0)
gl.Vertex(-1.0, -1.0, 0.0)
gl.End()
rtri = rtri + dt * 0.2
rquad = rquad - dt * 0.15
end,

keypressed = function(key)
if key == "ESCAPE" then
scrupp.exit()
end
end,

-- on window resize, call the init function
resized = init
}
116 changes: 116 additions & 0 deletions examples/opengl/nehe-05.slua
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
--[[
-- $Id$
-- NeHe OpenGL Lesson 05:
-- http://nehe.gamedev.net/tutorial/3d_shapes/10035/
--]]

require "luagl"
require "luaglu"

local rtri = 0.0
local rquad = 0.0

local function init(w, h)
scrupp.init("NeHe Lesson 05", w, h, 32, false, true)

gl.MatrixMode(gl.PROJECTION)
gl.LoadIdentity()
glu.Perspective(45.0, w/h, 0.1, 100.0)

gl.MatrixMode(gl.MODELVIEW)
gl.LoadIdentity()

-- scrupp enables backface culling per default
-- so we need to disable it for this lesson
gl.Disable(gl.CULL_FACE)

gl.ShadeModel(gl.SMOOTH)
gl.ClearColor(0.0, 0.0, 0.0, 0.0)
gl.ClearDepth(1.0)
gl.Enable(gl.DEPTH_TEST)
gl.DepthFunc(gl.LEQUAL)
gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)
end

init(600, 400)

main = {
render = function(dt)
gl.Clear(gl.COLOR_BUFFER_BIT+gl.DEPTH_BUFFER_BIT)
gl.LoadIdentity()
gl.Translate(-1.5, 0.0, -6.0)
gl.Rotate(rtri, 0.0, 1.0, 0.0)
gl.Begin(gl.TRIANGLES)
gl.Color(1.0, 0.0, 0.0)
gl.Vertex(0.0, 1.0, 0.0)
gl.Color(0.0, 1.0, 0.0)
gl.Vertex(-1.0, -1.0, 1.0)
gl.Color(0.0, 0.0, 1.0)
gl.Vertex(1.0, -1.0, 1.0)
gl.Color(1.0, 0.0, 0.0)
gl.Vertex(0.0, 1.0, 0.0)
gl.Color(0.0, 0.0, 1.0)
gl.Vertex(1.0, -1.0, 1.0)
gl.Color(0.0, 1.0, 0.0)
gl.Vertex(1.0, -1.0, -1.0)
gl.Color(1.0, 0.0, 0.0)
gl.Vertex(0.0, 1.0, 0.0)
gl.Color(0.0, 1.0, 0.0)
gl.Vertex(1.0, -1.0, -1.0)
gl.Color(0.0, 0.0, 1.0)
gl.Vertex(-1.0, -1.0, -1.0)
gl.Color(1.0, 0.0, 0.0)
gl.Vertex(0.0, 1.0, 0.0)
gl.Color(0.0, 0.0, 1.0)
gl.Vertex(-1.0, -1.0, -1.0)
gl.Color(0.0, 1.0, 0.0)
gl.Vertex(-1.0, -1.0, 1.0)
gl.End()
gl.LoadIdentity()
gl.Translate(1.5, 0.0, -7.0)
gl.Rotate(rquad, 1.0, 1.0, 1.0)
gl.Begin(gl.QUADS)
gl.Color(0.0, 1.0, 0.0)
gl.Vertex( 1.0, 1.0, -1.0)
gl.Vertex(-1.0, 1.0, -1.0)
gl.Vertex(-1.0, 1.0, 1.0)
gl.Vertex( 1.0, 1.0, 1.0)
gl.Color(1.0, 0.5, 0.0)
gl.Vertex(1.0, -1.0, 1.0)
gl.Vertex(-1.0, -1.0, 1.0)
gl.Vertex(-1.0, -1.0, -1.0)
gl.Vertex(1.0, -1.0, -1.0)
gl.Color(1.0, 0.0, 0.0)
gl.Vertex(1.0, 1.0, 1.0)
gl.Vertex(-1.0, 1.0, 1.0)
gl.Vertex(-1.0, -1.0, 1.0)
gl.Vertex(1.0, -1.0, 1.0)
gl.Color(1.0, 1.0, 0.0)
gl.Vertex(1.0, -1.0, -1.0)
gl.Vertex(-1.0, -1.0, -1.0)
gl.Vertex(-1.0, 1.0, -1.0)
gl.Vertex(1.0, 1.0, -1.0)
gl.Color(0.0, 0.0, 1.0)
gl.Vertex(-1.0, 1.0, 1.0)
gl.Vertex(-1.0, 1.0, -1.0)
gl.Vertex(-1.0, -1.0, -1.0)
gl.Vertex(-1.0, -1.0, 1.0)
gl.Color(1.0, 0.0, 1.0)
gl.Vertex(1.0, 1.0, -1.0)
gl.Vertex(1.0, 1.0, 1.0)
gl.Vertex(1.0, -1.0, 1.0)
gl.Vertex(1.0, -1.0, -1.0)
gl.End()
rtri = rtri + dt * 0.2
rquad = rquad - dt * 0.15
end,

keypressed = function(key)
if key == "ESCAPE" then
scrupp.exit()
end
end,

-- on window resize, call the init function
resized = init
}

0 comments on commit e758f7a

Please sign in to comment.