Jump to content

Implementing "Sky"


BigNickBrick
 Share

Recommended Posts

http://leadwerks.wikidot.com/wiki:skybox

 

This is a little wiki some of us just created and trying to populate.

 

Open up App.lua and copy/paste this function

 

-- credit to shadmar for the skybox
function App:MakeSkyBox()
self.camera:Move(0,4,-20)

--Create skybox
sky = Model:Create()
--just render a plane and project cubemap onto it
local surface = sky:AddSurface()
surface:AddVertex(-0.5,-0.5,0, 0,0,-1)
surface:AddVertex(0.5,-0.5,0, 0,0,-1)
surface:AddVertex(0.5,0.5,0, 0,0,-1)
surface:AddVertex(-0.5,0.5,0, 0,0,-1)
surface:AddTriangle(2,1,0)
surface:AddTriangle(0,3,2)

--position in front of camera but far out to near camera clip plane
sky:SetPosition(self.camera:GetPosition())
sky:SetRotation(self.camera:GetRotation())
sky:Move(0,0,self.camera:GetRange().y-50)
sky:SetScale(self.camera:GetRange().y*10)
sky:SetParent(self.camera)

-- and paint it
skymat = Material:Load("Materials/Sky/skybox_texture.mat")
sky:SetMaterial(skymat)
end

 

Then in App:Start() call the function:

 


function App:Start()

-- set the application title
self.title = "MyGame"

-- create a window
self.window = Window:Create(self.title)
self.window:HideMouse()

-- create the graphics context
self.context = Context:Create(self.window,0)
if self.context == nil then return false end

self.world = World:Create()

-- load the starting map
local mapfile = System:GetProperty("map","Maps/start.map")
if Map:Load(mapfile)==false then return false end

self:MakeSkyBox()

[size=4]return true[/size]
end

 

 

Thanks to Shadmar for this code. I plan on moving it to an entity script so we can just place it in our scene and drag in a texture file to use.

 

 

The thing to note with this is the camera variable inside the MakeSkyBox() function. If you create your camera in code then you can create it in the Start() function after the world is created with self.camera = Camera:Create(). If you add a camera into your scene via the editor, then you'll want to make a new Lua script to attach to that camera and inside the Script:Start() function do:

 

function Script:Start()
  App.camera = self.entity
end

 

You are then assigning self.entity (which because it's attached to the camera entity is the camera) to the App variable camera. App is global and all scripts can see the variables and functions with it.

  • Upvote 1
Link to comment
Share on other sites

ah **** i deleted something out of the app.lua file maybe you could help me get it back to right

 

--This function will be called once when the program starts

function App:Start()

 

--Set the application title

self.title="MyGame"

 

--Create a window

self.window=Window:Create(self.title)

self.window:HideMouse()

 

--Create the graphics context

self.context=Context:Create(self.window,0)

if self.context==nil then return false end

 

--Create a world

self.world=World:Create()

end

Link to comment
Share on other sites

Looks like you still have to be granted to the developers category. When you buy the steam edition you should have full access to the forum.

 

Looks like you deleted the main loop.


--This is our main program loop and will be called continuously until the program ends
function App:Loop()

--If window has been closed, end the program
if self.window:Closed() or self.window:KeyDown(Key.Escape) then return false end

--Update the app timing
Time:Update()

--Update the world
self.world:Update()

--Render the world
self.world:Render()

--Refresh the screen
self.context:Sync()

--Returning true tells the main program to keep looping
return true
end

Link to comment
Share on other sites

Sorry, I do have that portion in my app.lua i'll post the whole thing, something has to be missing i can't run anything not even the tutorial!

 

--This function will be called once when the program starts

function App:Start()

 

--Set the application title

self.title="MyGame"

 

--Create a window

self.window=Window:Create(self.title)

self.window:HideMouse()

 

--Create the graphics context

self.context=Context:Create(self.window,0)

if self.context==nil then return false end

 

--Create a world

self.world=World:Create()

 

end

 

--This is our main program loop and will be called continuously until the program ends

function App:Loop()

 

--If window has been closed, end the program

if self.window:Closed() or self.window:KeyDown(Key.Escape) then return false end

 

--Update the app timing

Time:Update()

 

--Update the world

self.world:Update()

 

--Render the world

self.world:Render()

 

--Render statistics

self.context:SetBlendMode(Blend.Alpha)

if DEBUG then

self.context:SetColor(1,0,0,1)

self.context:DrawText("Debug Mode",2,2)

self.context:SetColor(1,1,1,1)

self.context:DrawStats(2,22)

self.context:SetBlendMode(Blend.Solid)

else

self.context:SetColor(1,1,1,1)

self.context:DrawText("FPS: "..Math:Round(Time:UPS()),2,2)

end

 

--Refresh the screen

self.context:Sync(false)

 

--Returning true tells the main program to keep looping

return true

end

Link to comment
Share on other sites

Like this? Obviously, something is still off, as it's not loading still! Thank you for the help by the way, I really do appreciate it, hard being a noob, but my learning curve is usually pretty good.

--This function will be called once when the program starts

function App:Start()

 

--Set the application title

self.title="MyGame"

 

--Create a window

self.window=Window:Create(self.title)

self.window:HideMouse()

 

--Create the graphics context

self.context=Context:Create(self.window,0)

if self.context==nil then return false end

 

--Create a world

self.world=World:Create()

self.world = World:Create()

 

-- load the starting map

local mapfile = System:GetProperty("map", "Maps/start.map")

if Map:Load(mapfile) == false then return false end

end

 

--This is our main program loop and will be called continuously until the program ends

function App:Loop()

 

--If window has been closed, end the program

if self.window:Closed() or self.window:KeyDown(Key.Escape) then return false end

 

--Update the app timing

Time:Update()

 

--Update the world

self.world:Update()

 

--Render the world

self.world:Render()

 

--Render statistics

self.context:SetBlendMode(Blend.Alpha)

if DEBUG then

self.context:SetColor(1,0,0,1)

self.context:DrawText("Debug Mode",2,2)

self.context:SetColor(1,1,1,1)

self.context:DrawStats(2,22)

self.context:SetBlendMode(Blend.Solid)

else

self.context:SetColor(1,1,1,1)

self.context:DrawText("FPS: "..Math:Round(Time:UPS()),2,2)

end

 

--Refresh the screen

self.context:Sync(false)

 

--Returning true tells the main program to keep looping

return true

end

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...