BigNickBrick Posted January 7, 2014 Share Posted January 7, 2014 I was wondering how I take that nice sky background and well, use it! Quote Link to comment Share on other sites More sharing options...
Rick Posted January 7, 2014 Share Posted January 7, 2014 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. 1 Quote Link to comment Share on other sites More sharing options...
Rick Posted January 7, 2014 Share Posted January 7, 2014 Here you go: http://www.leadwerks.com/werkspace/files/file/463-skybox/ Easy peasy now Note this uses a camera that you add to your scene via the editor and not code. 1 Quote Link to comment Share on other sites More sharing options...
BigNickBrick Posted January 7, 2014 Author Share Posted January 7, 2014 I can't download it, it says im unable too! Edit: I dont have Permission! Quote Link to comment Share on other sites More sharing options...
Rick Posted January 7, 2014 Share Posted January 7, 2014 Oh, you aren't a developer yet on these forums. Did you buy the engine? It's possible Josh just didn't change your forum status. If you did I can post the code here. Quote Link to comment Share on other sites More sharing options...
BigNickBrick Posted January 7, 2014 Author Share Posted January 7, 2014 I bought the indie edition through steam, that could be why. Quote Link to comment Share on other sites More sharing options...
BigNickBrick Posted January 7, 2014 Author Share Posted January 7, 2014 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 Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 7, 2014 Share Posted January 7, 2014 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 Quote Link to comment Share on other sites More sharing options...
BigNickBrick Posted January 7, 2014 Author Share Posted January 7, 2014 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 Quote Link to comment Share on other sites More sharing options...
Rick Posted January 7, 2014 Share Posted January 7, 2014 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 Nothing will work if you don't load a map Quote Link to comment Share on other sites More sharing options...
BigNickBrick Posted January 7, 2014 Author Share Posted January 7, 2014 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 Quote Link to comment Share on other sites More sharing options...
shadmar Posted January 7, 2014 Share Posted January 7, 2014 App:Start() is missing return true at the end btw if you create a new project a default script is provided which should be correct. And then you can add the skybox part. Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
BigNickBrick Posted January 7, 2014 Author Share Posted January 7, 2014 thank you! I tried to start a new project and it's still the same app.lua file. im not sure exactly where that should go but i'll play with it! Quote Link to comment Share on other sites More sharing options...
BigNickBrick Posted January 7, 2014 Author Share Posted January 7, 2014 Problem fixed thanks to Rick just dropped a clean app.lua file in the script folder, thanks to all for helping! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.