-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added examples for using luagl to implement some of the famous
Nehe OpenGL tutorials.
- Loading branch information
Showing
5 changed files
with
319 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |