Jump to content

Recommended Posts

Posted

simple example of fading to black and to white:

window = Window:Create("fade example",0,0,800,600, Window.Center)
context = Context:Create(window)
world = World:Create()
camera = Camera:Create()
camera:Move(0,0,-3)
light = DirectionalLight:Create()
light:SetRotation(35,35,0)
model = Model:Box()
model:SetColor(0,0,1)

alpha = 0.01
toggle = 0.005
color = 1

while window:KeyDown(Key.Escape)==false do

	if window:Closed() then break end
	
	model:Turn(0,Time:GetSpeed(),0)

	if alpha>=1.0 then toggle = -0.005 end
	if alpha<=0.0 then
		toggle = 0.005
		color = 1 - color
	end
	alpha = alpha + toggle

	Time:Update()
	world:Update()
	world:Render()

	context:SetBlendMode(Blend.Alpha)
	context:SetColor(color,color,color,alpha)
	context:DrawRect(0,0,800,600)
	context:SetColor(1,0,0,1)
	context:DrawText(string.format("alpha: %.2f",alpha),0,2)
	context:DrawText("color: "..color..", "..color..", "..color,0,22)
	context:SetBlendMode(Blend.Solid)
	context:Sync(true)
end

 

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

LE / 3DWS / BMX / Hexagon

macklebee's channel

Posted

Bits of code like that should be kept somewhere, maybe a code snipets section. Very usefull.

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

  • 1 year later...
Posted
4 minutes ago, CangoJoe said:

Ok cool thanks,

I'm just trying to wrap my head around the purpose of DrawRect()  in your sample.

All I am doing is drawing a rectangle the same size as the window/context and fading to black/white by just adjusting the alpha component in the rectangle's color settings.

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

LE / 3DWS / BMX / Hexagon

macklebee's channel

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.

×
×
  • Create New...