Cuboid Engine Editor moving to MFC

Well, the title says it all, I’ve decided to move my whole editor to a MFC application, and I have to say, i really like MFC.

PS. I’m working on properties right now.

Advertisements

CLI-C++ .net forms Game Loop

One of my past wonders was:
How can i render Direct 11(or…) on a .net form?

Its actually relatively simple, these are the steps:

When you create the project, create a new file called main.cpp, and an entrance for the program.

To start the .net form:

If you just declare an instance of the .net form inside the cpp file, it WILL go wrong, because it needs to be declared in a managed envoirement.
To do that, you need to do so:

#include <vcclr.h> // Include this one, containing a template class called gcroot.

public class ManagedGlobals
{
public:
gcroot<Editor ^> MainEditor;
};

ManagedGlobals MG;

Now you have a wrapper for your form, to start it in the appropriate way:

int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);

// Create the main window and run it
MG.MainEditor = gcnew Editor();
//Application::Run(MG.MainEditor);

MG.MainEditor->Show();
while (MG.MainEditor->Created)
{
Application::DoEvents();
RenderFrame();
}
return 0;
}

As you see i have a while loop simply saying:

While the editor(in this case) is open, do the following:

Let the application(editor) do all the stuff it has to do right now, check for input blablabla…
Then after that render the frame.

To render in a, lets say a frame, we can do so:

–In the startup of the editor–

HWND pHandle = (HWND)RenderPanel->Handle.ToPointer();
InitD3D(pHandle);
InitGraphics();

Here we’ve got the handle of the panel, and sent it to a function called InitD3D.

InitD3D:

void InitD3D(HWND hWnd)
{

….

// In the DXGI_SWAP_CHAIN_DESC

scd.OutputWindow = hWnd;

…..

}

Then for each of the frames, the panel is treated as a window, meaning that the output will appear in that panel.

Good Luck!