Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


A small Problem with SharpDX


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Jerry.Mouse   Members   -  Reputation: 106

Like
0Likes
Like

Posted 20 May 2014 - 01:06 AM

Hello,

 

I do not know if this is the right forum, but I am looking for help with SharpDX 2.6. I have very simple

algorithm to create and draw a triangle. unfortunately, I see nothing.

Can anyone help ?

 

Source is here:

 

http://1drv.ms/1jkL2Py

 

Jerry

Attached Files

  • Attached File  _1.ZIP   3.45KB   23 downloads


Sponsor:

#2 Tasty Texel   Members   -  Reputation: 1357

Like
0Likes
Like

Posted 20 May 2014 - 07:54 AM

Why are you using a DirectX binding for C# under C++? Because of the SharpDX Toolkit?



#3 Jerry.Mouse   Members   -  Reputation: 106

Like
0Likes
Like

Posted 20 May 2014 - 12:54 PM

Because  I do not know C#......wacko.png



#4 Jerry.Mouse   Members   -  Reputation: 106

Like
0Likes
Like

Posted 20 May 2014 - 12:57 PM

Wou, mabybe I found a solution: ( SharpDX, SlimDX, ManagedDX ) with C++/CLI

 


#pragma once
 
 
namespace CLRW58 {
 
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 System::Threading; 
 
using namespace Microsoft::DirectX; 
using namespace Microsoft::DirectX::Direct3D;
 
#define RGB(r,g,b) ((®<<16) | ((g)<<8) | (b))
 
 //using namespace Microsoft::Xna::Framework;
//using namespace Microsoft::Xna::Framework::Content; 
//using namespace Microsoft::Xna::Framework::Graphics;   
 
/// <summary>
/// Summary for Form1
///          resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Microsoft::DirectX::Direct3D::Device^ _dev; 
Microsoft::DirectX::Direct3D::IndexBuffer^ ib; 
  Microsoft::DirectX::Direct3D::VertexBuffer^ _vb;
Microsoft::DirectX::Direct3D::Font^ font;
 
public:
Form1(void)
{
InitializeComponent();
 
this->Show(); 
 
Application::DoEvents(); 
 
Microsoft::DirectX::Direct3D::PresentParameters^ _presentParams = gcnew Microsoft::DirectX::Direct3D::PresentParameters();
_presentParams->Windowed = true;
_presentParams->SwapEffect = Microsoft::DirectX::Direct3D::SwapEffect::Discard;
_presentParams->EnableAutoDepthStencil = false;
_presentParams->BackBufferCount = 1;
_presentParams->BackBufferWidth = this->panel1->Width;
_presentParams->BackBufferHeight = this->panel1->Height;
 
array<Microsoft::DirectX::Direct3D::PresentParameters^,1>^ _pp = gcnew array<Microsoft::DirectX::Direct3D::PresentParameters^>(1);
_pp[0] = _presentParams;
 
/* _pp[0]->Windowed = true;
_pp[0]->SwapEffect = Microsoft::DirectX::Direct3D::SwapEffect::Discard;
_pp[0]->EnableAutoDepthStencil = false;
_pp[0]->BackBufferCount = 1;
_pp[0]->BackBufferWidth = this->panel1->Width;
_pp[0]->BackBufferHeight = this->panel1->Height; */
 
 
_dev = 
gcnew Microsoft::DirectX::Direct3D::Device( 0, 
                                           Microsoft::DirectX::Direct3D::DeviceType::Hardware,
Control::FromHandle( this->panel1->Handle ),
Microsoft::DirectX::Direct3D::CreateFlags::HardwareVertexProcessing,
                                                _presentParams );
 
 
_dev->SetRenderState( Microsoft::DirectX::Direct3D::RenderStates::Lighting, false );
 
 
    _vb = 
gcnew VertexBuffer( CustomVertex::PositionColored::typeid,//; //PositionColored::typeid,
                       8,
      _dev,
      Microsoft::DirectX::Direct3D::Usage::None,
    CustomVertex::PositionColored::Format,
    Pool::Managed );
 
 
array<CustomVertex::PositionColored>^ v =
 gcnew array<CustomVertex::PositionColored>(8);
 
  for ( int n = 0; n < 8; n++ ) {
    v[n].Position = Vector3( (float)(n&4), (float)(n&2), (float)(n&1));
v[n].Color = RGB(0xff*((n>>2)&1), 0xff*((n>>1)&1), 0xff*(n&1)); // #define RGB(r,g,b) ((®<<16) | ((g)<<8) | (b))
 }//
 
GraphicsStream^ gs = _vb->Lock(0, 0, (LockFlags)0);
 gs->Write(v);
 _vb->Unlock();
 
  ib = gcnew IndexBuffer(Int16::typeid, 36, _dev, (Usage)0, Pool::Managed);
 
  array<Int16>^ data = {
    0,4,2,6,2,4, // yz:
    7,5,3,1,3,5, // yz:
    0,2,1,3,1,2, // xy:
    7,6,5,4,5,6, // xy:
    0,1,4,5,4,1, // zx:
    7,3,6,2,6,3, // zx:
  };
  ib->SetData(data, 0, (LockFlags)0);
 
FontDescription fd;
  fd.Height = 20;
  fd.FaceName = "Arial";
font = gcnew Direct3D::Font(_dev, fd);
 
 
   Int32 counter = 0;
 
while ( this->IsDisposed == false ) {
 
    _dev->Transform->World = Matrix::RotationY( Environment::TickCount / 3000.0f) *
                            Matrix::RotationX( Environment::TickCount / 4000.0f);
_dev->RenderState->CullMode = Cull::Clockwise; // None;
   
     //
     _dev->Transform->View = Matrix::LookAtLH( Vector3(8.0f, 8.0f, 8.0f),
                                              Vector3(0.0f, 0.0f, 0.0f),
                                              Vector3(0.0f, 1.0f, 0.0f));
     _dev->Transform->Projection = Matrix::PerspectiveFovLH((float)Math::PI / 4,
                                  (float)ClientSize.Width / ClientSize.Height, 3.0f, 15.0f);
     _dev->RenderState->Lighting = false;
 
 
 _dev->Clear( ClearFlags::Target, System::Drawing::Color::Red, 1.0f, 0 );
 
_dev->BeginScene(); 
 
      _dev->SetStreamSource(0, _vb, 0);
   _dev->Indices = ib;
_dev->VertexFormat = CustomVertex::PositionColored::Format;
_dev->DrawIndexedPrimitives(PrimitiveType::TriangleList, 0, 0, 8, 0, 12);
font->DrawText( nullptr, "HELLO  " + counter.ToString(), 20, 20, Color::White);
 
 
counter++;
 
//Microsoft::DirectX::Direct3D::Surface^ _surface = gcnew Microsoft::DirectX::Direct3D::Surface( _dev,BITMAP, pool ); 
//Microsoft::DirectX::Direct3D::Surface::^ _backbuffer = _dev->GetBackBuffer( 0, 0, Microsoft::DirectX::Direct3D::BackBufferType::Mono ); 
//_backBuffer
/*
    // acquire access to the back buffer
    Surface^ backbuffer;
backbuffer = _dev->GetBackBuffer( 0, 0, Microsoft::DirectX::Direct3D::BackBufferType::Mono );
System::Drawing::Graphics^ graphics;
graphics = backbuffer->GetGraphics();
 
    // draw a rectangle using GDI+
    graphics->DrawRectangle(Pens::Beige, 10, 20, 50, 60);
 
      // release
      backbuffer->ReleaseGraphics();*/
 
 
   _dev->EndScene();
 
 
   try 
{
   _dev->Present();
   }
   catch (DeviceLostException^) 
{
      Int32 hResult = 0;
 
     if (!_dev->CheckCooperativeLevel(hResult)) {
 
       switch (hResult) {
         case ResultCode::DeviceLost:
          Thread::Sleep(10);
          break;
         case ResultCode::DeviceNotReset:
          _dev->Reset( _presentParams );
          break;
       }// switch
 
}// if
 
   }// try catch 
 
 
      _dev->Present();
 
   Application::DoEvents(); 
 
}// 
 
//
//TODO: Add the constructor code here
//
}
 
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Panel^  panel1;
protected: 
 
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
 
#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->panel1 = (gcnew System::Windows::Forms::Panel());
this->SuspendLayout();
// 
// panel1
// 
this->panel1->Location = System::Drawing::Point(0, 0);
this->panel1->Name = L"panel1";
this->panel1->Size = System::Drawing::Size(456, 396);
this->panel1->TabIndex = 0;
// 
// Form1
// 
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(478, 396);
this->Controls->Add(this->panel1);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
 
}
#pragma endregion
 
 
 
};
}
 


#5 Jerry.Mouse   Members   -  Reputation: 106

Like
0Likes
Like

Posted 20 May 2014 - 12:59 PM

Of course several DLL need to be added

 

Microsoft.DirectX.dll

Microsoft.DirectX.Direct3D.dll

Microsoft.DirectX.Direct3DX.dll

Microsoft.DirectX.DirectDraw.dll 

 

from Win XP, so called managed DirectX






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS