Jump to content

[SOLVED] Does CreateCustomBuffer work with c++?


Von04
 Share

Recommended Posts

Just wondering if anyone has gotten CreateCustomeBuffer to work with c++ and windows forms yet? I want to make a GMF Fracture tool for destructibles objects, but I can only use c++ because converting the code to c# would take way to long.

3d world studio. 3ds Max 8. GTX 260. Visual Studio 2010. Dual Core 2.6 Mhz processor.

Link to comment
Share on other sites

Not that I've ever seen although MasterXilo did release some code for changing the graphics resolution in game which I seem to remember used a custom buffer so you might glean some useful info from that. Whisper may have done something with managed code and windows forms but it's so long ago I can't remember exactly.

Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++

Link to comment
Share on other sites

I know it's been done with Windows Forms.

With C# it certainly has, can you point us at a C++ implementation because I'd be interested in that too!

Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++

Link to comment
Share on other sites

So here is what I've come up with so far. The program ran fine and the createcustombuffer function seems to be working. Although when I added the line World = CreateWorld(), the program hangs up and freezes and never gets to the line MessageBox::Show("Failed to create world!"). Do you think this is because CreateCustomBuffer isn't being made current or isn't getting a valid DC?

 

#pragma warning(disable: 4793)
#pragma warning(disable: 4441)

#pragma once
#include "stdafx.h"
#include "Engine.Cpp"

namespace GMFTool {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace Tao::Platform::Windows;
using namespace Tao::OpenGl;
using namespace LE;

static void _stdcall GetSize(int *width, int *height)
	{
		width[0] = 800; 
		height[0] = 600;
	}
static void _stdcall MakeCurrent()
	{
		wglMakeCurrent(wglGetCurrentDC(), wglGetCurrentContext());
	}

public ref class Form1 : public System::Windows::Forms::Form
{
public:
	TBuffer Buffer;
	TWorld  World;

public: 

	Form1(void)
	{
		InitializeComponent();
		Window->InitializeContexts();
		Initialize();
		Buffer = CreateCustomBuffer((byte *)&GetSize, (byte*)&MakeCurrent);

		World = CreateWorld();
		if (!World) MessageBox::Show("Failed to create world!", "Error!");
    }

protected:
	~Form1()
	{
		if (components)
		{
			delete components;
		}
	}
public:  Tao::Platform::Windows::SimpleOpenGlControl^  Window;
private: System::ComponentModel::IContainer^  components;

public: 

#pragma region Windows Form Designer generated code
	/// <summary>
	/// Required method for Designer support - do not modify
	/// the contents of this method with the code editor.
	/// </summary>
	void InitializeComponent(void)
	{
	this->Window = (gcnew Tao::Platform::Windows::SimpleOpenGlControl());
	this->SuspendLayout();
	// 
	// Window
	// 
	this->Window->AccumBits = static_cast<System::Byte>(0);
	this->Window->AutoCheckErrors = false;
	this->Window->AutoFinish = false;
	this->Window->AutoMakeCurrent = true;
	this->Window->AutoSwapBuffers = true;
	this->Window->BackColor = System::Drawing::Color::Black;
	this->Window->ColorBits = static_cast<System::Byte>(32);
	this->Window->DepthBits = static_cast<System::Byte>(16);
	this->Window->Dock = System::Windows::Forms::DockStyle::Fill;
	this->Window->Location = System::Drawing::Point(0, 0);
	this->Window->Name = L"Window";
	this->Window->Size = System::Drawing::Size(1184, 662);
	this->Window->StencilBits = static_cast<System::Byte>(0);
	this->Window->TabIndex = 0;
	// 
	// Form1
	// 
	this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
	this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
	this->ClientSize = System::Drawing::Size(1184, 662);
	this->Controls->Add(this->Window);
	this->Name = L"Form1";
	this->Text = L"Form1";
	this->WindowState = System::Windows::Forms::FormWindowState::Maximized;
	this->ResumeLayout(false);

		}
#pragma endregion

	};
}



3d world studio. 3ds Max 8. GTX 260. Visual Studio 2010. Dual Core 2.6 Mhz processor.

Link to comment
Share on other sites

  • 2 weeks later...

Finally, after many tiring hours, I have succesfully created an OpenGL Control that renders leadwerks to a custum buffer on a c++ windows forms application. All you have to do is drag and drog the control onto your form and it sets up leadwerks for you with or without framework, it's your choice. I just need to tidy up my code and do some bug testing, and then I will release the control and a demo project to the community. Hopefully this helps a lot of people.

3d world studio. 3ds Max 8. GTX 260. Visual Studio 2010. Dual Core 2.6 Mhz processor.

Link to comment
Share on other sites

Wow! That's brilliant. I'm sure a lot of people will be very grateful. Many thanks for your effort and for making this available once its complete.

Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++

Link to comment
Share on other sites

I have no idea what happened to my code. I went to run my test form, and every time it gets to the line CreateWorld the form closes without any errors. What would cause CreateWorld to crash my form? Is it that there is not a active GLContext? I don't believe that I changed any of the code to cause this. I'm at a loss.

3d world studio. 3ds Max 8. GTX 260. Visual Studio 2010. Dual Core 2.6 Mhz processor.

Link to comment
Share on other sites

Any update on this? Did you manage to resolve the problem?

 

I did resolve the problems. The only thing now is trying to implement a Timer inside of the control to fire an event, and use that to create an internal loop. The problem is that whenever I add a Threading.Timer to the control it crashes Visual Studio. I've read about a lot of other people having the same problem but I haven't figured out a work-around yet. If I can't figure this out by tomorrow, I'll just release the code as-is, and users will just have to add their own timer to their windows forms, and use that as a render loop. I post later tonight when I have some more time to work on this.

3d world studio. 3ds Max 8. GTX 260. Visual Studio 2010. Dual Core 2.6 Mhz processor.

Link to comment
Share on other sites

I did resolve the problems. The only thing now is trying to implement a Timer inside of the control to fire an event, and use that to create an internal loop. The problem is that whenever I add a Threading.Timer to the control it crashes Visual Studio. I've read about a lot of other people having the same problem but I haven't figured out a work-around yet. If I can't figure this out by tomorrow, I'll just release the code as-is, and users will just have to add their own timer to their windows forms, and use that as a render loop. I post later tonight when I have some more time to work on this.

 

Just uploaded a working version of the control to the Asset Store -> Tools section. Check it out and let me know how it goes. Hope my directions are clear enough for setting it up. The included LEControl.Dll contains the control. The example.cpp and form1.h files included are examples of how to set up leadwerks using the control. Best of luck.

3d world studio. 3ds Max 8. GTX 260. Visual Studio 2010. Dual Core 2.6 Mhz processor.

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