Jump to content

AddHook outside Sandbox


Rekindled Phoenix
 Share

Recommended Posts

i assume its for doing 2d draw commands?

 

you can do them three ways...

1) just set the FlipHook function in the initial part of the program

function FlipHook() --or this works automatically without needing hooks.lua
SetBlend(1) 
SetColor(Vec4(1,0,0,0.25)) 
DrawText("hello",50,300)
SetColor(Vec4(1,1,1,1)) 
SetBlend(0) 
end

 

2) set a function with the hook command via "scripts/hooks" lua script

function DrawStuff()
SetBlend(1)
SetColor(Vec4(0,1,1,1))
DrawText("hello",0,300)
SetColor(Vec4(1,1,1,1))
SetBlend(0)
end
AddHook("Flip", DrawStuff)

 

3) and of course right before the Flip in the main loop

 

note that the FlipHook function doesnt play well with the AddHook's function in the standalone for some reason...

 

require("scripts/constants/engine_const")
require("scripts/hooks")
RegisterAbstractPath("")        
Graphics(800,600)        
fw=CreateFramework() 

fw.main.camera:SetPosition(Vec3(0,0,-2))
light=CreateSpotLight(10) 
light:SetRotation(Vec3(45,55,0)) 
light:SetPosition(Vec3(5,5,-5)) 

material=LoadMaterial("abstract::cobblestones.mat") 

mesh=CreateCube() 
mesh:Paint(material) 

ground=CreateCube() 
ground:SetScale(Vec3(10.0,1.0,10.0)) 
ground:SetPosition(Vec3(0.0,-2.0,0.0)) 
ground:Paint(material) 

light=CreateDirectionalLight() 
light:SetRotation(Vec3(45,45,45)) 

--add your own via hooks.lua
function DrawStuff()
SetBlend(1)
SetColor(Vec4(0,1,1,1))
DrawText("hello",0,300)
SetColor(Vec4(1,1,1,1))
SetBlend(0)
end
AddHook("Flip", DrawStuff)

--[[function FlipHook() --or this works automatically without needing hooks.lua
SetBlend(1) 
SetColor(Vec4(1,0,0,0.25)) 
DrawText("hello",50,300)
SetColor(Vec4(1,1,1,1)) 
SetBlend(0) 
end]]

while AppTerminate()==0 do 

if KeyHit(KEY_ESCAPE)==1 then
	break
end 

mesh:Turn(Vec3(AppSpeed()*0.5,AppSpeed()*0.5,AppSpeed()*0.5)) 

fw:Update()
fw:Render()
-- or just add the 2d drawcommands here
SetBlend(1)
SetColor(Vec4(0,0,1,1))
DrawText("something",100,300)
SetColor(Vec4(1,1,1,1))
SetBlend(0)
Flip(0)
end

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Addhook in the standalone script or a object script works fine if there is no FlipHook() function in the standalone... but yeah the two together in the standalone do not play well together or a fliphook with an addhook in an object script... but to get around it you can just use an Addhook function in the standalone as well and it works with object scripts that have addhooks

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...