...and So i thought why not try Managed DirectX to make something (a simple vertice render with direct 3d)
and i wrote the code and it compilated without any errors
it throws an exception and i cannot understand the reason!
if anyone can help i would be glad
here is the code:
#using <mscorlib.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <Microsoft.DirectX.dll>
#using <Microsoft.DirectX.Direct3D.dll>
#using <System.Windows.Forms.dll>
#include <tchar.h>
#include <stdio.h>
using namespace System;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using namespace System:
rawing;
using namespace System:
rawing::Imaging;
using namespace System:
rawing:
rawing2D;
using namespace Microsoft:
irectX;
using namespace Microsoft:
irectX:
irect3D;
// Gracie Form Constructor
__gc public class ImageForm : public Form {
private:
Device* ds;
VertexBuffer* vbx;
public: ImageForm()
{
ds = NULL;
vbx = NULL;
Text = S"Image View";
FormBorderStyle = FormBorderStyle::Sizable;
ClientSize = System:
rawing::Size(300,300);
InitializeGraphics();
Render();
}
bool InitializeGraphics()
{
PresentParameters* presentParams = new PresentParameters();
presentParams->Windowed=true;
presentParams->SwapEffect = SwapEffect:
iscard;
ds = new Device(0, DeviceType::Hardware, this, CreateFlags::SoftwareVertexProcessing, presentParams);
ds->DeviceCreated += (new EventHandler(this, ImageForm::OnCreateDevice));
OnCreateDevice(ds, NULL);
return true;
}
public:
void OnCreateDevice(Object* pSender, EventArgs* e)
{
CustomVertex::TransformedColored tcc1;
pSender = tcc1.ToString();
Type* tp = pSender->GetType();
vbx = new VertexBuffer(tp, 3, ds, Direct3D::Usage:
ynamic, CustomVertex::TransformedColored::Format, Pool:
efault);
vbx->Created += (new EventHandler(this, &ImageForm::OnCreateVertexBuffer));
OnCreateVertexBuffer(vbx, NULL);
}
void OnCreateVertexBuffer(Object* pSender, EventArgs* pArgs)
{
GraphicsStream* stm = NULL;
vbx->Lock(0,0,LockFlags());
CustomVertex::TransformedColored verts[] = new CustomVertex::TransformedColored[3];
verts[0].X=150;verts[0].Y=50;verts[0].Z=0.5f; verts[0].Rhw=1; verts[0].Color = System:
rawing::Color::Aqua.ToArgb();
verts[1].X=250;verts[1].Y=250;verts[1].Z=0.5f; verts[1].Rhw=1; verts[1].Color = System:
rawing::Color::Brown.ToArgb();
verts[2].X=50;verts[2].Y=250;verts[2].Z=0.5f; verts[2].Rhw=1; verts[2].Color = System:
rawing::Color::LightPink.ToArgb();
stm->Write(verts);
vbx->Unlock();
}
private:
void Render()
{
if (ds == NULL)
return;
ds->Clear(ClearFlags::Target, System:
rawing::Color::Blue, 1.0f, 0);
ds->BeginScene();
ds->SetStreamSource( 0, vbx, 0);
ds->VertexFormat = CustomVertex::TransformedColored::Format;
ds->DrawPrimitives(PrimitiveType::TriangleList, 0, 1);
ds->EndScene();
ds->Present();
}
};
and i wrote the code and it compilated without any errors
it throws an exception and i cannot understand the reason!
if anyone can help i would be glad
here is the code:
#using <mscorlib.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <Microsoft.DirectX.dll>
#using <Microsoft.DirectX.Direct3D.dll>
#using <System.Windows.Forms.dll>
#include <tchar.h>
#include <stdio.h>
using namespace System;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using namespace System:
using namespace System:
using namespace System:
using namespace Microsoft:
using namespace Microsoft:
// Gracie Form Constructor
__gc public class ImageForm : public Form {
private:
Device* ds;
VertexBuffer* vbx;
public: ImageForm()
{
ds = NULL;
vbx = NULL;
Text = S"Image View";
FormBorderStyle = FormBorderStyle::Sizable;
ClientSize = System:
InitializeGraphics();
Render();
}
bool InitializeGraphics()
{
PresentParameters* presentParams = new PresentParameters();
presentParams->Windowed=true;
presentParams->SwapEffect = SwapEffect:
ds = new Device(0, DeviceType::Hardware, this, CreateFlags::SoftwareVertexProcessing, presentParams);
ds->DeviceCreated += (new EventHandler(this, ImageForm::OnCreateDevice));
OnCreateDevice(ds, NULL);
return true;
}
public:
void OnCreateDevice(Object* pSender, EventArgs* e)
{
CustomVertex::TransformedColored tcc1;
pSender = tcc1.ToString();
Type* tp = pSender->GetType();
vbx = new VertexBuffer(tp, 3, ds, Direct3D::Usage:
vbx->Created += (new EventHandler(this, &ImageForm::OnCreateVertexBuffer));
OnCreateVertexBuffer(vbx, NULL);
}
void OnCreateVertexBuffer(Object* pSender, EventArgs* pArgs)
{
GraphicsStream* stm = NULL;
vbx->Lock(0,0,LockFlags());
CustomVertex::TransformedColored verts[] = new CustomVertex::TransformedColored[3];
verts[0].X=150;verts[0].Y=50;verts[0].Z=0.5f; verts[0].Rhw=1; verts[0].Color = System:
verts[1].X=250;verts[1].Y=250;verts[1].Z=0.5f; verts[1].Rhw=1; verts[1].Color = System:
verts[2].X=50;verts[2].Y=250;verts[2].Z=0.5f; verts[2].Rhw=1; verts[2].Color = System:
stm->Write(verts);
vbx->Unlock();
}
private:
void Render()
{
if (ds == NULL)
return;
ds->Clear(ClearFlags::Target, System:
ds->BeginScene();
ds->SetStreamSource( 0, vbx, 0);
ds->VertexFormat = CustomVertex::TransformedColored::Format;
ds->DrawPrimitives(PrimitiveType::TriangleList, 0, 1);
ds->EndScene();
ds->Present();
}
};