Jump to content

Finally Leadwerks framework renders to Custom Control


klepto2
 Share

Recommended Posts

After revisiting the TKControl again I wasn't able to find a big bug or anything else i have made wrong (ok the refreshrate calculation is buggy) but then i have tried to get the Framework to work with the LETKControl and :

 

Success!!!

 

post-4-12774690253404_thumb.jpg

 

As said, there is nothing wrong with the Control itself, but something small is needed to get the Control working with the Framework.

 

Here is the code:

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Leadwerks;

namespace Leadwerks_FormsFramewerk_Test
{
   public partial class Form1 : Form
   {
       private Leadwerks.Buffer buffer;

       public Form1()
       {
           InitializeComponent();
       }

       private void RenderContext_Init(object sender, EventArgs e)
       {

           Leadwerks.FileSystem.AbstractPath = @"D:\LESDK232r5";

           //Create a render buffer
           buffer = new Leadwerks.Buffer(RenderContext.Width, RenderContext.Height, (int)(BufferType.Color | BufferType.Depth | BufferType.Normal));
           RenderContext.Start();

           Leadwerks.Framework.Initialize(true);
           Leadwerks.Framework.StatisticMode = StatisticMode.Detailed;

           Leadwerks.Scene scene = Scene.Load("abstract::Test.sbx");

           Framework.Layers.Main.Camera.Position = new Vector3(4, 3, -4);
           Framework.Layers.Main.Camera.Point(new Pivot());
       }

       private void RenderContext_Redraw(object sender, EventArgs e)
       {

           //Set the created renderbuffer as current buffer and let LE render to it
           Leadwerks.Buffer.Current = buffer;//Leadwerks.Buffer.Back;

           Leadwerks.Framework.Update();
           Leadwerks.Framework.Render();

           //Set the buffer of the Control as current and draw the flipped image of the 'framework' buffer
           Leadwerks.Buffer.Current = RenderContext.Buffer;
           Leadwerks.Drawing.Image(buffer.GetColorTexture(0), 0, RenderContext.Buffer.Height, RenderContext.Buffer.Width, -RenderContext.Buffer.Height);
        }


       private void RenderContext_Resize(object sender, EventArgs e)
       {
           buffer = new Leadwerks.Buffer(RenderContext.Width, RenderContext.Height, (int)(BufferType.Color | BufferType.Depth | BufferType.Normal));
       }


       private void RenderContext_KeyDown(object sender, KeyEventArgs e)
       {
           if (e.KeyCode == Keys.Q)
               Framework.Layers.Main.Camera.Move(new Vector3(0, 1 * Leadwerks.Core.AppSpeed(), 0));

           if (e.KeyCode == Keys.Y)
               Framework.Layers.Main.Camera.Move(new Vector3(0, -1 * Leadwerks.Core.AppSpeed(), 0));
       }

   }
}

 

I hope this will help you. I will now try to integrate this a bit more into the control so that you won't need to handle this by your own.

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

Yes it should. Well i havn't tried it yet, but others already have used VB.Net with this control.

I'm also working on a WPF Control. But this is a bit more difficult as WPF uses DirectX natively and i need to wrap the Forms Control to a WPF control.

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

Guest Red Ocktober

coool... you've opened up a lot of possibilities for the dotNET guys... and given the Blitz and c++ guys a reason to take a look at C# and VB...

 

 

--Mike

Link to comment
Share on other sites

There really is a million different reasons to switch to .NET. Having access to the .NET framework just provides SOOOO much functionality. The down sides would be speed (although probably nothing to major), and cross platform. It can work on Mac and Linux with Mono, but I think most of the portable platforms don't really support it from what I know. Namely iPhone, Andriod.

Link to comment
Share on other sites

Guest Red Ocktober

i'm a lil familiar with dotNET Rick... you don't need to sell me on it... i used to work for a firm and we used vb and c# a lot...

 

like everything else, dotNET has its advantages and disadvantages...

 

as far as mono goes... what do you think your chances are of porting Leadwerks over to run under the current stable release of mono... and have that execute on a macintosh...

 

 

--Mike

Link to comment
Share on other sites

So getting an error. The first event fired is Resize(). On the one line in there that creates a buffer I get the following error.

 

"A first chance exception of type 'System.AccessViolationException' occured in Leadwerks.dll"

 

 

Wouldn't Graphics() need to be called before creating buffers?

Link to comment
Share on other sites

The Leadwerks.dll I'm using is the one from http://code.google.com/p/leadwerks-csharp/downloads/list. I think that's the R5 one. Then the engine.dll I'm using looks also to be the R5 one. So not sure what's up there.

 

 

Interestingly enough, I can get it working if I comment out the resize line. So since Resize() was getting called first and was bombing I created a boolean and check it in resize and if true run that code for the buffer. I set it to true in the Init() method. This seems to work then. Interesting.

 

 

 

Also, it seems one of the "bad" things about using the .NET key events is that it does the whole delay until repeating when holding the key. Gives a very choppy feel. I tried using the following in the Redraw() but KeyDown() never returned true. Is there a way to get a smoother keyboard input for this?

 

           if(Leadwerks.Keyboard.KeyDown(Key.Q))
               Framework.Layers.Main.Camera.Move(new Vector3(0, 1 * Leadwerks.Core.AppSpeed(), 0));

           if(Leadwerks.Keyboard.KeyDown(Key.Y))
               Framework.Layers.Main.Camera.Move(new Vector3(0, -1 * Leadwerks.Core.AppSpeed(), 0));

Link to comment
Share on other sites

Ok, the buffer thing maybe due to wrong timer initialisation. So it tries to update the buffer before LE is initialised. This should be a minor issue and easy to solve.

The issue with using events is a bit more complicated. The problem is that the events and the redraw maybe asyncron. So you press the key, update the camera but the next frame will not be updated. To solve this you can do the following:

 

       private bool KeyW = false;
       private bool KeyS = false;
       private bool KeyA = false;
       private bool KeyD = false;

       private void RenderContext_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
       {
           if (e.KeyCode == Keys.W)
               KeyW = true;

           if (e.KeyCode == Keys.S)
               KeyS = true;

           if (e.KeyCode == Keys.A)
               KeyA = true;

           if (e.KeyCode == Keys.D)
               KeyD = true;
       }

       private void RenderContext_KeyUp(object sender, KeyEventArgs e)
       {
           if (e.KeyCode == Keys.W)
               KeyW = false;

           if (e.KeyCode == Keys.S)
               KeyS = false;

           if (e.KeyCode == Keys.A)
               KeyA = false;

           if (e.KeyCode == Keys.D)
               KeyD = false;
       }

 

And in the main loop do the standard Move code

 move = Maths.Curve((float)(Convert.ToDouble(KeyW) - Convert.ToDouble(KeyS)), move, 20);
           strafe = Maths.Curve((float)(Convert.ToDouble(KeyD) - Convert.ToDouble(KeyA)), strafe, 20);
           Framework.Layers.Main.Camera.Move(new Vector3(strafe / 10.0f, 0, move / 10.0f));

 

I will add a similar eventhandling like the original LE Polledinput later. eg: LETKControl.KeyDown(Key.A) or something like this.

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

So what exactly did you change to make it work?

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

I'd like Klepto to join the Commit Members on our official SVN and works with us and with the same code so he can personally apply updates instead of working on its own control (even if it's the same as that released on SVN)... just to work all together :unsure:

 

PS: In the download section of the project there is now also a link for a pre-build version of Leadwerks Controls which contains LETKControl (and eventually will contain new controls if any)

?? FRANCESCO CROCETTI ??

http://skaredcreations.com

Link to comment
Share on other sites

What language is your game being written in?

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

Has anyone done the basic camera look functionality within this control? I can't get it to work. Something like the FPS lua file where it lets you look around with the mouse. Since it's in a control some things like GraphicsWidth/Height() and MoveMouse() won't work.

 

--Camera look
gx=Round(GraphicsWidth()/2)
gy=Round(GraphicsHeight()/2)
dx=Curve((MouseX()-gx)/4.0,dx,3.0/AppSpeed())
dy=Curve((MouseY()-gy)/4.0,dy,3.0/AppSpeed())
MoveMouse(gx,gy)
camerapitch=camerapitch+dy
camerayaw=camerayaw-dx
camerapitch=math.min(camerapitch,90)
camerapitch=math.max(camerapitch,-90)
fw.main.camera:SetRotationf(camerapitch,camerayaw,0,1)

Link to comment
Share on other sites

  • 3 weeks later...

Hi, I just want to inform you that i will release a newer Version of this Control Thursday or Friday.

 

There will be a lot of new small functions in the control which will make the handlicng of the Control much easier.

 

A short summary:

  1. Handling of PolledInput with the same function like the raw version of Leadwerks

    1. MoveMouse, KeyDown, KeyHit, MouseHit, etc.

  1. You will be able to assign a Framework directly to the control so the buffer rendering is done internal

 

And this is how the current Cam View code looks like in the control:



if (RenderContext.MouseDown(MouseButtons.Left))
{
//Camera look
mx = Maths.Curve(RenderContext.MouseX() - RenderContext.Width/2, mx, 6);
my = Maths.Curve(RenderContext.MouseY() - RenderContext.Height/2, my, 6);

RenderContext.MoveMouse(RenderContext.Width/2, RenderContext.Height/2);
// Leadwerks.Mouse.Move(RenderContext.Width / 2 , RenderContext.Height / 2 );

camrotation.X = camrotation.X + my/5.0f;
camrotation.Y = camrotation.Y - mx/5.0f;

Leadwerks.Framework.Layers.Main.Camera.Rotation = camrotation;
}


move =
Maths.Curve(
(float)
(Convert.ToDouble(RenderContext.KeyDown(Key.W)) - Convert.ToDouble(RenderContext.KeyDown(Key.S))),
move, 20);

strafe =
Maths.Curve(
(float)
(Convert.ToDouble(RenderContext.KeyDown(Key.D)) - Convert.ToDouble(RenderContext.KeyDown(Key.A))),
strafe, 20);

Leadwerks.Framework.Layers.Main.Camera.Move(new Vector3(strafe/10.0f, 0, move/10.0f));

 

This code gives the same smooth results as the original one. Also the MoveMouse method already takes the control offset into acount so no offset is needed.

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
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...