Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Managed Direct X

Status
Not open for further replies.

tougo

Technical User
Sep 9, 2002
27
GB
...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::Drawing;
using namespace System::Drawing::Imaging;
using namespace System::Drawing::Drawing2D;
using namespace Microsoft::DirectX;
using namespace Microsoft::DirectX::Direct3D;


// Gracie Form Constructor
__gc public class ImageForm : public Form {
private:

Device* ds;
VertexBuffer* vbx;

public: ImageForm()
{
ds = NULL;
vbx = NULL;

Text = S&quot;Image View&quot;;
FormBorderStyle = FormBorderStyle::Sizable;
ClientSize = System::Drawing::Size(300,300);

InitializeGraphics();
Render();
}
bool InitializeGraphics()
{
PresentParameters* presentParams = new PresentParameters();
presentParams->Windowed=true;
presentParams->SwapEffect = SwapEffect::Discard;
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::Dynamic, CustomVertex::TransformedColored::Format, Pool::Default);
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::Drawing::Color::Aqua.ToArgb();
verts[1].X=250;verts[1].Y=250;verts[1].Z=0.5f; verts[1].Rhw=1; verts[1].Color = System::Drawing::Color::Brown.ToArgb();
verts[2].X=50;verts[2].Y=250;verts[2].Z=0.5f; verts[2].Rhw=1; verts[2].Color = System::Drawing::Color::LightPink.ToArgb();
stm->Write(verts);
vbx->Unlock();
}
private:
void Render()
{
if (ds == NULL)
return;

ds->Clear(ClearFlags::Target, System::Drawing::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();
}
};
 
try to use debugger to see what is internally hapening.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
i already did that and the debugger breaks at

vbx = new VertexBuffer(tp, 3, ds, Direct3D::Usage::Dynamic, CustomVertex::TransformedColored::Format, Pool::Default);

but i cannot understand what's wrong, save for the Tostring conversion in the previous line that maybe it ruins the GetType but even then there is no obvious reason why the application throws an exception when it gets there
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top