Skip to content

Commit

Permalink
hello world
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwu committed Oct 12, 2017
0 parents commit a33b574
Show file tree
Hide file tree
Showing 969 changed files with 6,842 additions and 0 deletions.
324 changes: 324 additions & 0 deletions 00-helloworld.lua

Large diffs are not rendered by default.

107 changes: 107 additions & 0 deletions 01-cubes.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
local ant = require "ant"
local util = require "ant.util"
local math3d = require "ant.math"
local bgfx = require "bgfx"

canvas = iup.canvas{
-- rastersize = "1024x768",
-- rastersize = "400x300",
}

dlg = iup.dialog {
canvas,
title = "01-cubes",
size = "HALFxHALF",
}

local ctx = {}
local time = 0
local function mainloop()
math3d.reset()
bgfx.touch(0)
local mat = math3d.matrix()
time = time + 0.001
for yy = 0, 10 do
for xx = 0, 10 do
mat:rotmat(time + xx*0.21, time + yy*0.37):trans(-15.0 + xx * 3, -15.0 + yy * 3, 0)
bgfx.set_transform(mat)
bgfx.set_vertex_buffer(0, ctx.vb)
bgfx.set_index_buffer(ctx.ib)
bgfx.set_state(ctx.state)
bgfx.submit(0, ctx.prog)
end
end

bgfx.frame()
end

local init

local function init(canvas)
ant.init {
nwh = iup.GetAttributeData(canvas,"HWND"),
-- renderer = "DIRECT3D12",
-- renderer = "OPENGL",
}
bgfx.set_view_clear(0, "CD", 0x303030ff, 1, 0)
-- bgfx.set_debug "ST"

ctx.prog = util.load_program("vs_cubes", "fs_cubes")

ctx.state = bgfx.make_state {
PT = "TRISTRIP"
}
ctx.vdecl = bgfx.vertex_decl {
{ "POSITION", 3, "FLOAT" },
{ "COLOR0", 4, "UINT8", true },
}
ctx.vb = bgfx.create_vertex_buffer({
"fffd",
-1.0, 1.0, 1.0, 0xff000000,
1.0, 1.0, 1.0, 0xff0000ff,
-1.0, -1.0, 1.0, 0xff00ff00,
1.0, -1.0, 1.0, 0xff00ffff,
-1.0, 1.0, -1.0, 0xffff0000,
1.0, 1.0, -1.0, 0xffff00ff,
-1.0, -1.0, -1.0, 0xffffff00,
1.0, -1.0, -1.0, 0xffffffff,
},
ctx.vdecl)
ctx.ib = bgfx.create_index_buffer{
0, 1, 2, 3, 7, 1, 5, 0, 4, 2, 6, 7, 4, 5,
}
ant.mainloop(mainloop)
end

function canvas:resize_cb(w,h)
if init then
init(self)
init = nil
end
ctx.width = w
ctx.height = h
bgfx.set_view_rect(0, 0, 0, ctx.width, ctx.height)
bgfx.reset(ctx.width,ctx.height, "vmx")
local viewmat = math3d.matrix "view"
local projmat = math3d.matrix "proj"
viewmat:lookatp(0,0,-35, 0,0,0)
projmat:projmat(60, ctx.width/ctx.height, 0.1, 100)
bgfx.set_view_transform(0, viewmat, projmat)
end

function canvas:action(x,y)
mainloop()
end

dlg:showxy(iup.CENTER,iup.CENTER)
dlg.usersize = nil

-- to be able to run this script inside another context
if (iup.MainLoopLevel()==0) then
iup.MainLoop()
iup.Close()
bgfx.destroy(ctx.vb)
bgfx.destroy(ctx.ib)
bgfx.destroy(ctx.prog)
ant.shutdown()
end
Loading

0 comments on commit a33b574

Please sign in to comment.