Skip to content

Commit

Permalink
exposed MOAIDraw::Bind () to lua; updated audio-meter sample to not c…
Browse files Browse the repository at this point in the history
…rash on render
  • Loading branch information
Patrick Meehan committed Dec 2, 2018
1 parent 6047561 commit a9cf617
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
8 changes: 5 additions & 3 deletions samples/audio-meter/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ viewport = MOAIViewport.new ()
viewport:setSize ( 1024, 512 )
viewport:setScale ( 1024, 512 )

layer = MOAIPartitionViewLayer.new ()
layer = MOAITableViewLayer.new ()
layer:setViewport ( viewport )
layer:setClearColor ( 1, 1, 1, 1 )
layer:pushRenderPass ()
Expand Down Expand Up @@ -86,6 +86,8 @@ elapsedFrames = 0

onDraw = function ()

MOAIDraw.bind ()

meter:seek ( 0 )

local span = 1024 / bands
Expand All @@ -95,9 +97,9 @@ onDraw = function ()
local x = (( i - 1 ) * span ) - ( 1024 / 2 )
local y = ( meter:readFloat () * 64 ) - 256

MOAIGfxMgr.setPenColor ( 1, 0, 0, 1 )
MOAIDraw.setPenColor ( 1, 0, 0, 1 )
MOAIDraw.fillRect ( x, y, x + span, -256 )
end
end

layer:setOverlayTable ({ onDraw })
layer:setRenderTable ({ onDraw })
10 changes: 10 additions & 0 deletions src/moai-sim/MOAIDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,15 @@ void MOAIDraw::EndDrawString () {
// lua
//================================================================//

//----------------------------------------------------------------//
// TODO: doxygen
int MOAIDraw::_bind ( lua_State* L ) {
MOAI_LUA_SETUP_SINGLE ( MOAIDraw, "" )

self->Bind ();
return 0;
}

//----------------------------------------------------------------//
// TODO: doxygen
int MOAIDraw::_bindFrameBuffer ( lua_State* L ) {
Expand Down Expand Up @@ -1546,6 +1555,7 @@ void MOAIDraw::RegisterLuaClass ( MOAILuaState& state ) {
state.SetField ( -1, "WORLD_MATRIX", ( u32 )MOAIGfxState::MODEL_TO_WORLD_MTX );

luaL_Reg regTable [] = {
{ "bind", _bind },
{ "bindFrameBuffer", _bindFrameBuffer },
{ "bindIndexBuffer", _bindIndexBuffer },
{ "bindShader", _bindShader },
Expand Down
1 change: 1 addition & 0 deletions src/moai-sim/MOAIDraw.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class MOAIDraw :
private:

//----------------------------------------------------------------//
static int _bind ( lua_State* L );
static int _bindFrameBuffer ( lua_State* L );
static int _bindIndexBuffer ( lua_State* L );
static int _bindShader ( lua_State* L );
Expand Down

0 comments on commit a9cf617

Please sign in to comment.