Jump to content

Leadwerks 5 example


Josh
 Share

Recommended Posts

Here's an example program in Leadwerks 4:

#include "Leadwerks.h"

using namespace Leadwerks;

int main(int argc, const char *argv[])
{
    Leadwerks::Window* window = Leadwerks::Window::Create();
    Context* context = Context::Create(window);
    World* world = World::Create();
  
    Camera* camera = Camera::Create();
    camera->Move(0,0,-3);
  
    Light* light = DirectionalLight::Create();
    light->SetRotation(35,35,0);
        
    Model* model = Model::Box();
    model->SetColor(0.0,0.0,1.0);

    while (true)
    {
        if (window->Closed() || window->KeyDown(Key::Escape)) return false;
        model->Turn(0,Leadwerks::Time::GetSpeed(),0);
        Leadwerks::Time::Update();
        world->Update();
        world->Render();
        context->Sync(true);
    }
    return 0;
}

And here is the same code in Leadwerks 5:

#include "Leadwerks.h"

using namespace Leadwerks;

int main(int argc, const char *argv[])
{
    auto window = CreateWindow();
    auto context = CreateContext(window);
    auto world = CreateWorld();
  
    auto camera = CreateCamera(world);
    camera->Move(0,0,-3);
  
    auto light = CreateDirectionalLight(world);
    light->SetRotation(35,35,0);
        
    auto model = CreateBoxModel(world);
    model->SetColor(0.0,0.0,1.0);

    while (true)
    {
        if (window->Closed() or window->KeyDown(EscapeKey)) return false;
        model->Turn(0,world->GetSpeed(),0);
        world->Update();
        world->Render(context,true);
    }
    return 0;
}

And in Lua:

local window = CreateWindow()
local context = CreateContext(window)
local world = CreateWorld()

local camera = CreateCamera(world)
camera:Move(0,0,-3)

local light = CreateDirectionalLight(world)
light:SetRotation(35,35,0)

local model = CreateBoxModel(world)
model:SetColor(0.0,0.0,1.0)

while true do
	if window:Closed() or window:KeyDown(EscapeKey) then return end
	model:Turn(0,world:GetSpeed(),0)
	world:Update()
	world:Render(context,true)
end

 

  • Like 1
  • Thanks 1
  • Upvote 3

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Note there is no call the context::Sync because once you start the world render, it goes off on a separate thread and goes out all the way to the monitor.  There are no drawing commands you can call after that.  I think we're going to have a system of persistent 2D sprites you create, rather than drawing commands you call.

The Render command itself only passes any changed positions to the culling thread and returns to your program, so there is really nothing to slow your game code down and if the timing isn't limited it will execute at like 1000 updates per second.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

51 minutes ago, Ma-Shell said:

It might be a good idea to allow us to register a callback before the context-sync is executed, so we can put other drawing stuff there.

I guess if your callback was thread safe it would work.

  • Upvote 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Here's the first Leadwerks 5 program ever run:

#include "Leadwerks.h"

using namespace Leadwerks;

int main(int argc, const char *argv[])
{
	auto window = CreateWindow();
	auto context = CreateContext(window);
	auto world = CreateWorld();

	auto camera = CreateCamera(world);
	camera->Move(0, 0, -3);

	auto light = CreateDirectionalLight(world);
	light->SetRotation(35, 35, 0);

	auto model = CreateBoxModel(world);
	model->SetColor(0,0,255);
	
	while (not window->Closed())
	{
		model->Turn(0, 1, 0);
		world->Update();
		world->Render(context);
	}
	return 0;
}

 

  • Upvote 2

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

26 minutes ago, Roland said:

while (not window->Closed()

'not' :)

It's standard C++.  There's a header you have to include for VS support, but 'not', 'or', and 'and' are standard.

  • Upvote 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

15 hours ago, Josh said:

Note there is no call the context::Sync because once you start the world render, it goes off on a separate thread and goes out all the way to the monitor.  There are no drawing commands you can call after that.  I think we're going to have a system of persistent 2D sprites you create, rather than drawing commands you call.

The Render command itself only passes any changed positions to the culling thread and returns to your program, so there is really nothing to slow your game code down and if the timing isn't limited it will execute at like 1000 updates per second.

er - what? you need then to give access to the render thread so we can use drawing commands. All custom post-process and geometry shaders would be affected by this, would they not? A 2D sprite doesnt isnt quite the same. So you are saying GUI's now will all be sprites?

  • Upvote 2

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

7 hours ago, macklebee said:

er - what? you need then to give access to the render thread so we can use drawing commands. All custom post-process and geometry shaders would be affected by this, would they not? A 2D sprite doesnt isnt quite the same. So you are saying GUI's now will all be sprites?

Custom post-process effects are attached to a camera.  I do not understand how a geometry shader relates to this.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

12 hours ago, Josh said:

Custom post-process effects are attached to a camera.  I do not understand how a geometry shader relates to this.

Thats because my custom geometry shaders use Draw()-related commands. So you are saying something as simple as text now will require a sprite? Sounds very counter-intuitive. How will custom buffers be supported? Or are they going to be officially supported finally in LE5? 

  • Upvote 1

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