Search the Community
Showing results for tags 'c#'.
-
Actually it is very simple. As usual, we need to export the functions we are interested in to the Dynamic Library (DLL), and then import them into our C# program. Let's start. C++ DLL The first thing we need is to create a project in C++ for our future DLL, and of course configure it for the Leadwerks engine Configuration for Release Right-click on the project and select Property. In the window that appears, go to the tab "С/C++" / "General". Copy and Paste to a "Additional Include Directories" this: $(LeadwerksHeaderPath)\Libraries\NewtonDynamics\sdk\dgCore;$(LeadwerksHeaderPath)\Libraries\NewtonDynamics\sdk\dgNewton;$(LeadwerksHeaderPath)\Libraries\libvorbis\include;$(LeadwerksHeaderPath)\Libraries\libogg\include;$(LeadwerksHeaderPath)\Libraries\openssl\include;$(LeadwerksHeaderPath);$(LeadwerksHeaderPath)\Libraries\VHACD\src\VHACD_Lib\inc;$(LeadwerksHeaderPath)\Libraries\glslang;$(LeadwerksHeaderPath)\Libraries\freetype-2.4.7\include;$(LeadwerksHeaderPath)\Libraries\OpenAL\include;$(LeadwerksHeaderPath)\Libraries\NewtonDynamics\sdk\dMath;$(LeadwerksHeaderPath)\Libraries\NewtonDynamics\sdk\dgTimeTracker;$(LeadwerksHeaderPath)\Libraries\NewtonDynamics\sdk\dContainers;$(LeadwerksHeaderPath)\Libraries\NewtonDynamics\sdk\dCustomJoints;$(LeadwerksHeaderPath)\Libraries\RecastNavigation\RecastDemo\Include;$(LeadwerksHeaderPath)\Libraries\RecastNavigation\DetourCrowd\Include;$(LeadwerksHeaderPath)\Libraries\RecastNavigation\DetourTileCache\Include;$(LeadwerksHeaderPath)\Libraries\RecastNavigation\DebugUtils\Include;$(LeadwerksHeaderPath)\Libraries\RecastNavigation\Recast\Include;$(LeadwerksHeaderPath)\Libraries\RecastNavigation\Detour\Include;$(LeadwerksHeaderPath)\Libraries\tolua++-1.0.93\include;$(LeadwerksHeaderPath)\Libraries/lua-5.1.4;$(LeadwerksHeaderPath)\Libraries/glew-1.6.0/include/GL;$(LeadwerksHeaderPath)\Libraries\glew-1.6.0\include;$(LeadwerksHeaderPath)\Libraries\enet-1.3.1\include;$(LeadwerksHeaderPath)\Libraries\zlib-1.2.5;$(LeadwerksHeaderPath)\Libraries\freetype-2.4.3\include;%(AdditionalIncludeDirectories) Go to "Preprocessor", in "Preprocessor Definitions" copy and paste this: WIN32;NDEBUG;LEADWERKS_EXPORTS;_WINDOWS;_USRDLL;PSAPI_VERSION=1;__STEAM__;_CUSTOM_JOINTS_STATIC_LIB;FT2_BUILD_LIBRARY;LEADWERKS_3_1;DG_DISABLE_ASSERT;WINDOWS;OS_WINDOWS;OPENGL;PLATFORM_WINDOWS;_WIN_32_VER;_NEWTON_USE_LIB;PTW32_STATIC_LIB;PTW32_BUILD;_NEWTON_STATIC_LIB;_LIB;DG_USE_NORMAL_PRIORITY_THREAD;GLEW_STATIC;_STATICLIB;%(PreprocessorDefinitions) Go to "Code Generation". Set these values: Enable Minimal Rebuild = Yes(/Gm) Runtime Library = Multi-threaded (/MT) Enable Function-Level-Linking = Yes (/Gy) Go to "Precompiled Header" and set: "Not Using Precompiled Headers" Now go to the "Linker" / "General" tab, then in "Additional Library Directories" copy and paste this: $(LeadwerksLibPath)\Windows\x86;$(LeadwerksLibPath)\Windows\x86\Release;C:/Leadwerks\Engine\Source\Libraries\OpenAL/libs/Win32/EFX-Util_MT;C:/Leadwerks\Engine\Source\Libraries\OpenAL/libs/Win32;%(AdditionalLibraryDirectories) Go to "Input", in "Additional Dependencies" copy and paste this: newton.lib;dContainers.lib;dCustomJoints.lib;libcryptoMT.lib;libsslMT.lib;Rpcrt4.lib;crypt32.lib;libcurl.lib;Leadwerks.lib;msimg32.lib;lua51.lib;steam_api.lib;OpenAL32.lib;ws2_32.lib;libovr.lib;newton.lib;dContainers.lib;dCustomJoints.lib;OpenGL32.lib;Glu32.lib;winmm.lib;Psapi.lib;%(AdditionalDependencies) Propery Sheet Right-click on the project and select "Add \ New Item \ Property Sheets \ Property Sheet" click Add button. Open it and paste this text: Warning! Keep in mind that the paths may be different, check them out. <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ImportGroup Label="PropertySheets" /> <PropertyGroup Label="UserMacros"> <LeadwerksHeaderPath>C:/Program Files (x86)/Steam/steamapps/common/Leadwerks\Include</LeadwerksHeaderPath> <LeadwerksLibPath>C:/Program Files (x86)/Steam/steamapps/common/Leadwerks\Library</LeadwerksLibPath> </PropertyGroup> <PropertyGroup /> <ItemDefinitionGroup /> <ItemGroup> <BuildMacro Include="LeadwerksHeaderPath"> <Value>$(LeadwerksHeaderPath)</Value> <EnvironmentVariable>true</EnvironmentVariable> </BuildMacro> <BuildMacro Include="LeadwerksLibPath"> <Value>$(LeadwerksLibPath)</Value> <EnvironmentVariable>true</EnvironmentVariable> </BuildMacro> </ItemGroup> </Project> If all the paths match, you can import it into the project. Go to menu "VIEW / Other Windows / Property Manager" Click button "Add Existing Property Sheet". On this with the project settings everything =). Now we can go directly to the code. This is part of the functions required for a simple program; you can add other functions yourself. // Leadwerks.cpp : Defines the exported functions for the DLL application. // #include "Leadwerks.h" using namespace Leadwerks; #define EXPORT extern "C" __declspec(dllexport) // ---------------------------------------------------------------------------------- // SYSTEM // ---------------------------------------------------------------------------------- EXPORT void LE_System_Initialize() { System::Initialize(); } EXPORT void LE_System_Shutdown() { System::Shutdown(); } EXPORT void LE_System_SetAppName(const char* name) { System::AppName = name; } EXPORT void LE_System_SetAppPath(const char* path) { System::AppPath = path; } // ---------------------------------------------------------------------------------- // WINDOW // ---------------------------------------------------------------------------------- EXPORT Window* LE_Window_Create(HWND hwnd) { return Window::Create(hwnd); } EXPORT void LE_Window_Free(Window* window) { delete window; } EXPORT bool LE_Window_Closed(Window* window) { return window->Closed(); } EXPORT bool LE_Window_KeyHit(Window* window, int keycode) { return window->KeyHit(keycode); } // ---------------------------------------------------------------------------------- // CONTEXT // ---------------------------------------------------------------------------------- EXPORT Context* LE_Context_Create(Window* window) { return Context::Create(window); } EXPORT void LE_Context_Free(Context* context) { delete context; } EXPORT void LE_Context_Sync(Context* context, bool sync) { context->Sync(sync); } // ---------------------------------------------------------------------------------- // WORLD // ---------------------------------------------------------------------------------- EXPORT World* LE_World_Create() { return World::Create(); } EXPORT void LE_World_Free(World* world) { delete world; } EXPORT void LE_World_Update(World* world) { world->Update(); } EXPORT void LE_World_Render(World* world) { world->Render(); } // ---------------------------------------------------------------------------------- // CAMERA // ---------------------------------------------------------------------------------- EXPORT Camera* LE_Camera_Create() { return Camera::Create(); } EXPORT void LE_Camera_SetClearColor(Camera* camera, float r, float g, float b, float a) { camera->SetClearColor(r, g, b, a); } Press "Ctrl+Shift+B" C# After a successful build, let's move on to C#. Let's create a new project "Windows Forms App" Here is the program code for an example: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace LETest { public partial class Form1 : Form { const string LEDLL = "Leadwerks.dll"; [DllImport(LEDLL)] public static extern void LE_System_Initialize(); [DllImport(LEDLL)] public static extern void LE_System_Shutdown(); [DllImport(LEDLL)] public static extern void LE_System_SetAppName(String name); [DllImport(LEDLL)] public static extern void LE_System_SetAppPath(String path); IntPtr window; [DllImport(LEDLL)] public static extern IntPtr LE_Window_Create(IntPtr hwnd); [DllImport(LEDLL)] public static extern void LE_Window_Free(IntPtr window); IntPtr context; [DllImport(LEDLL)] public static extern IntPtr LE_Context_Create(IntPtr window); [DllImport(LEDLL)] public static extern void LE_Context_Free(IntPtr context); [DllImport(LEDLL)] public static extern void LE_Context_Sync(IntPtr context, bool sync); IntPtr world; [DllImport(LEDLL)] public static extern IntPtr LE_World_Create(); [DllImport(LEDLL)] public static extern void LE_World_Free(IntPtr world); [DllImport(LEDLL)] public static extern void LE_World_Update(IntPtr world); [DllImport(LEDLL)] public static extern void LE_World_Render(IntPtr world); IntPtr camera; [DllImport(LEDLL)] public static extern IntPtr LE_Camera_Create(); [DllImport(LEDLL)] public static extern void LE_Camera_SetClearColor(IntPtr camera, float r, float g, float b, float a); Thread loopThread; bool isAppWork; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { isAppWork = true; loopThread = new Thread(EngineUpdate); loopThread.IsBackground = true; loopThread.Start(); } private void EngineUpdate() { //Initialize LE_System_Initialize(); window = LE_Window_Create(panel1.Handle); context = LE_Context_Create(window); world = LE_World_Create(); camera = LE_Camera_Create(); LE_Camera_SetClearColor(camera, 0.0f, 0.0f, 1.0f, 1.0f); //Main loop while (isAppWork) { LE_World_Update(world); LE_World_Render(world); LE_Context_Sync(context, true); } //Free LE_World_Free(world); LE_Context_Free(context); LE_Window_Free(window); LE_System_Shutdown(); } private void Form1_FormClosed(object sender, FormClosedEventArgs e) { //isAppWork = false; loopThread.Abort(); loopThread = null; } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { isAppWork = false; } } } Copy you'r "DLL" to bin folder. UPDATE: Copy these file from you'r leadwekrs project to c# bin folder: Shaders folder dContainers.dll dContainers_d.dll dCustomJoints.dll dCustomJoints_d.dll libcurl.dll lua51.dll newton.dll newton_d.dll openvr_api.dll steam_api.dll
-
I have had the most difficulty creating transparency that doesn't cause a graphical glitch like the image below. Browsing through the tutorials, it seems that none of them reference using the FramewOrk methods. Do they automatically set the clearmode appropriately? Neither smoke (alpha) or fire (light) MAT settings work to fix this issue. I've also tried creating my own textures to replace the defaults, and have had no luck. Either way, this is my basic emitter setup in C#. //transparency refers to foreground World.Current = Framework.Layers.Transparency.World; Framework.Layers.Transparency.Camera.ClearMode = CameraClearMode.None; Emitter flames = new Emitter(new Vector3(-.5F, -.5F, 0),200); flames.Material = Material.Load("abstract::fire.mat"); flames.Area = new Vector3(.2F, 1, .2F); flames.Radii = new Radii(.5F, 0); flames.Waver = 1; World.Current = Framework.Layers.Main.World; In case you're wondering about the enum values public enum CameraClearMode : int //byte { Unique = -1, // suggested by Canardian, only godrays visible None = 0, Depth = 1, Color = 2, } I'm so frustrated, if this doesn't get fixed it's possible I may have to use another engine at this point. Please help, oh wise and knowledgeable forum users. So you have a secret transparency recipe? EDIT: Secondly, why does the vertical camera angle effect particle intensity?
-
Hi, How to replace the standard window, on to any other window or object ?. For rendering engine.
-
Tower defense games are my favorite casual games. The last few weeks I have been spending some free time on playing several of them. Steam had a lot of sales recently which gave me no choice but to buy them. Here are a few: Defense Grid: The awakening Orcs must die iBomber: Pacific They are quite addictive and found myself buying a lot of available DLC´s. Mutant Madness I want to build a simple tower defense game. That means: Build a tower on flat ground Tower shoots on enemy Enemy dies: you get money for a new tower If the enemy reaches your base, you base will get partially destroyed. You win the game by surviving all the waves. You loose if your base is destroyed. There are many things that can be build to improve the simple basics of this game. However, experience has learned that I have to keep it simple. Trying to complete something with easy rules, is complex enough. Todo On my current todo list: Building placement on flat terrain Simple GUI display Tower shooting Different enemies Steering behaviour
-
I am working on a simple Tower defense tech demo and I have a little problem. I want to address a roadnode in the editor via C#. After that, I want to make a simple loop that goes though the nodes with GetEntityTarget. At the moment I search for the first road node in a level. Then I loop through the roadnodes to get a list that represents the path. The problem is, that it can not find a target in the scene, while the road nodes are deffinitly connected in the editor. //Load the first level TEntity level1 = LE.LoadScene("abstract::level1.sbx"); //Get the path TEntity currentNode = LE.FindChild(level1, "node_1"); List<TVec3> path = new List<TVec3>(); bool pathEnded = false; while(pathEnded == false) { TEntity nextNode = LE.GetEntityTarget(currentNode); if (nextNode == null) pathEnded = true; else { path.Add(LE.EntityPosition(nextNode)); currentNode = nextNode; } }
-
Allways wondered how to create pathfinding for your game? Check out this in depth tutorial about the A* pathfinding in Leadwerks using LE.NET. This tutorial covers all points of setting up a basic program using the A* algorithm. The tutorial uses LE.NET and Visual Studio 2010. This tutorial covers: Pathfinding in general Dijkstra algorithm Setting up a grid with tiles A* algorithm Getting the path How to improve Download Available! Start project Finished project Powerpoint used in the video http://www.leadwerks.com/werkspace/files/file/321-a-star-a-pathfinding/
-
Hi guys, finally I have some more freetime back and have restarted developing with Leadwerks more intensively in C#. Currently I'm working on multiple extensions for the .NET Wrapper of Leadwerks and I'm also finishing / continuing developing my tools. Later I hope this will all fit in one easy to use framework. First here is a screen of new nightsky texture used in my lua daynight script (not completely correct scaled) : the texture was made by taking screenshots from the stellarium software ( http://www.stellarium.org ) and building a cubemap out of them. Also I have started an advanced 2D Library for Leadwerks.Net : This is the current 2D code for the image above: public void Render() { Drawing2D.Enabled = true; //Enables Rendering of 2D Elements in native OpenGL Drawing2D.SetViewRotation(m_angle2, 1024f/ 2f, 768f / 2f); //Rotates the complete Viewport around given point Drawing2D.SetBlend(BlendMode.Alpha); // Set differten Blendmodes Drawing2D.SetColor(255, 0, 0, 1.0f); // Set Color for the following drawing calls Drawing2D.DrawLine(0, 0, 1024, 768); // Draws a line Drawing2D.SetColor(0, 255, 0, 0.5f); Drawing2D.DrawLine(0, -100, 1024, 768); Drawing2D.SetColor(0, 0, 255, 0.5f); Drawing2D.DrawLine(0, 100, 1024, 768); Drawing2D.SetColor(255, 0, 255, .5f); // Set the Drawing Handle of the next items to draw //(eg: normally all items are rotated at their local [0,0] coordinate, this function offsets this point by the given point) //values of 10,10 would rotate the following rects around their center. Drawing2D.SetHandle(50, 50); for (int i = 0; i < 150; i++) { if (i % 2 == 0) Drawing2D.SetRotation(m_angle); //Sets current rotation for the following drawings else Drawing2D.SetRotation(-m_angle); Drawing2D.DrawRect(10.24f + i * 10.24f, 7.68f + i * 7.68f, 20, 20); // Draws a rect } m_angle += 0.02f; m_angle2 += 0.04f; Drawing2D.Enabled = false; // Disables raw OpenGL Mode } The module will have its own Image handling (Leadwerks textures can be used as well) and much more. This is a brief overview and will be continued...
-
Lazlo just released his managed C# Library for use with Leadwerks! C# Headers The Object-Oriented layout of this library is wonderfully organized, just like a game engine library should be! With this code the objects aren't stored as pointers, but classes. All of the same features are structured, and each object has related functions to the types of entities per Namespace. Every .Net Leadwerks developer should download this library.
- 3 comments
-
- C#
- Visual Basic
-
(and 2 more)
Tagged with: