• FEATURED

View more

View more

View more

Image of the Day Submit

IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Triangles visibility

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.

11 replies to this topic

#1Jerry.Mouse  Members

Posted 24 May 2014 - 10:54 AM

Hello, I have a petty problem. I have two triangles - see "triangles perspective.bmp"

Axis +X is marked RED cross, +Y is marked GREEN cross, axis +Z is marked BLUE cross.

Both are ClockWise and CULL mode is off.

// TRIANGLE A, GREEN color, is close to me
v[0].pose = SlimDX::Vector3( -0.5f, +0.0f, -10.5f );
v[0].color = 0xff00ff00; //

v[1].pose = SlimDX::Vector3( +0.0f, +1.5f, -10.5f );
v[1].color = 0xff00ff00; //

v[2].pose = SlimDX::Vector3( +5.5f, +0.0f, -10.5f );
v[2].color = 0xff00ff00; //

// TRIANGE B, BLUE color, ias FAR / further
v[3].pose = SlimDX::Vector3( -3.5f, +0.0f, 10.5f );
v[3].color = 0xff0000f0; //

v[4].pose = SlimDX::Vector3( +0.0f, +2.5f, 10.5f );
v[4].color = 0xff0000f0; //

v[5].pose = SlimDX::Vector3( +3.5f, +0.0f, 10.5f );
v[5].color = 0xff0000f0; //

sl_device->SetTransform( SlimDX::Direct3D9::TransformState::View,
SlimDX::Matrix::LookAtLH( SlimDX::Vector3( 0.0f,  0.0f, -15.0f ), //
SlimDX::Vector3( 0.0f,  0.0f, +15.0f ),
SlimDX::Vector3( 0.0f, +1.0f,  0.0f ) ) );

If camera is set to Z: -15 to +15, I see this: "triangle camera.bmp". The Blue triangle is depicted in front ot the green.
It is not normal. Please, where is error ?

Thanks.

"triangle camera.bmp" - no World rotation

sl_device->SetTransform( SlimDX::Direct3D9::TransformState::World,
SlimDX::Matrix::Translation( 0.0f, 0.0f, 0.0f ) *
SlimDX::Matrix::RotationY( 0.0f ) *
SlimDX::Matrix::RotationX( 0.0f ) *
SlimDX::Matrix::RotationZ( 0.0f )
);

"triangles perspective.bmp", small rotation

sl_device->SetTransform( SlimDX::Direct3D9::TransformState::World,
SlimDX::Matrix::Translation( 0.0f, 0.0f, 0.0f ) *
SlimDX::Matrix::RotationY( +0.3f ) *
SlimDX::Matrix::RotationX( -0.2f ) *
SlimDX::Matrix::RotationZ( 0.0f )
);

Attached Files

Edited by Jerry.Mouse, 24 May 2014 - 11:31 AM.

#2Samith  Members

Posted 24 May 2014 - 11:42 AM

It sounds like you don't have depth testing enabled. You'll need a depth buffer and the proper depth-stencil state set in order to get the correct sorting of those triangles.

#3Jerry.Mouse  Members

Posted 24 May 2014 - 12:56 PM

Great. How can I set depth buffer ?

If I set

_presentParameters->EnableAutoDepthStencil = true;

I see nothing ... black screen

#4Buckeye  GDNet+

Posted 24 May 2014 - 01:13 PM

The Blue triangle is depicted in front ot the green.

That's correct. Your camera is at -15, the Blue triangle is at -10.5, the Green triangle is at +10.5.

EDIT: I was incorrect. I had the colors reversed. See response below.

Edited by Buckeye, 24 May 2014 - 01:24 PM.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

#5Jerry.Mouse  Members

Posted 24 May 2014 - 01:16 PM

_device->SetRenderState( SlimDX::Direct3D9::RenderState::ZEnable, true );

leads to  D3DERR_INVALIDCALL: Invalid call (-2005530516)

at

_device->Clear( SlimDX::Direct3D9::ClearFlags::Target | ClearFlags::ZBuffer, SlimDX::Color4( SlimDX::Color3( 0.0f, 0.0f, 0.0f )) , 1.0f, 0 );

#6Jerry.Mouse  Members

Posted 24 May 2014 - 01:20 PM

no no BLUE triangle is at +10.5f, GREEN at -10.5f,

it means, that GREEN is before BLUE, I should have seen GREEN first, that BLUE

terrible

#7Jerry.Mouse  Members

Posted 24 May 2014 - 01:23 PM

COLOR  0xff00ff00;

means:

FF is alpha, 00 is RED, FF is GREEN, 00 is BLUE =  GREEN

FF is aplha, 00 is RED, FF is GREEN, F0 is BLUE =  BLUE

BLUE triangle is far

#8Buckeye  GDNet+

Posted 24 May 2014 - 01:24 PM

no no BLUE triangle is at +10.5f, GREEN at -10.5f,

Apologies. You are correct.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

#9Jerry.Mouse  Members

Posted 24 May 2014 - 01:43 PM

nice,

please, can someone take a look at this simple severaal-lines code.

https://onedrive.live.com/redir?resid=6C2D62DDB1948596%21287

I really do not know why blue triangle is before green. It is not normal....maybe I am dumbass

#10unbird  Members

Posted 24 May 2014 - 02:25 PM

No, you're experiencing the frustrating first steps with a low level API. There are dozens of things that can go wrong. As you can see, that error isn't very informative, you wanna help yourself with Direct3D Programming Tip #5: Use The Debug Runtime. Post the error here when you got it working.

As Samith points out, you need a depth buffer and must set the related renderstates before drawing, This explains it quite well.

Also, get familiar with a graphics debugger, e.g. the tool PIX coming with the SDK (PIXWin.exe in the utilities directory).

PS: In the future you can post such things in the DirectX subforum here.

#11Jerry.Mouse  Members

Posted 24 May 2014 - 03:04 PM

ERROR was repaired.

My biggest problem is why BLUE triangle is in front of GREEN triangle ...

source code is here

https://onedrive.live.com/redir?resid=6C2D62DDB1948596%21287        File named CLRW58

Yes I am frustrated .... very much ...

Edited by Jerry.Mouse, 25 May 2014 - 02:19 AM.

#12Jerry.Mouse  Members

Posted 24 May 2014 - 03:17 PM

WOU, it is really working. I feel so free   .. ecstatic-ally

So, here is working source code, maybe, it will help to someone....

#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 SlimDX;
using namespace SlimDX::Direct3D9;
using namespace SlimDX::DirectInput;

/// <summary>
/// Summary for Form1
///          resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:

SlimDX::Direct3D9::PresentParameters^ sl_pp;
SlimDX::Direct3D9::Device^ sl_device;
SlimDX::Direct3D9::Direct3D^ sl_direct3D;
SlimDX::Direct3D9::VertexBuffer^ sl_vb;
SlimDX::Direct3D9::VertexBuffer^ sl_vb2;
SlimDX::Direct3D9::VertexBuffer^ sl_vb3;
SlimDX::Direct3D9::IndexBuffer^ sl_ib;

value struct CustomVertex {
SlimDX::Vector3 pose;
Int32 color;
};

public:
Form1(void)
{
InitializeComponent();

this->Show();

sl_pp = gcnew SlimDX::Direct3D9::PresentParameters();

sl_pp->Windowed = true;
sl_pp->EnableAutoDepthStencil = true;  //  Z Buffer
sl_pp->BackBufferCount = 1;
sl_pp->BackBufferWidth = this->panel1->Width;
sl_pp->BackBufferHeight = this->panel1->Height;
sl_pp->AutoDepthStencilFormat = SlimDX::Direct3D9::Format::D16;  // Z buffer format

sl_direct3D = gcnew SlimDX::Direct3D9::Direct3D();
sl_device = gcnew SlimDX::Direct3D9::Device( sl_direct3D,
0,
SlimDX::Direct3D9::DeviceType::Hardware,
this->panel1->Handle,
SlimDX::Direct3D9::CreateFlags::SoftwareVertexProcessing, // ::HardwareVertexProcessing,
sl_pp  );

sl_device->SetRenderState( SlimDX::Direct3D9::RenderState::Lighting, false );

// TWO TRIANGLES, BLUE and GREEN
//***************************************************************
sl_vb = gcnew SlimDX::Direct3D9::VertexBuffer( sl_device,
6 * 16,
SlimDX::Direct3D9::Usage::None,
SlimDX::Direct3D9::VertexFormat::Position | SlimDX::Direct3D9::VertexFormat::Diffuse, //SlimDX::Direct3D9::VertexFormat::Diffuse,
SlimDX::Direct3D9::Pool::Managed );

array<CustomVertex>^ v = gcnew array<CustomVertex>(6);

// GREEN
v[0].pose = SlimDX::Vector3( -0.5f, +0.0f, -10.5f );
v[0].color = 0xff00ff00; //

v[1].pose = SlimDX::Vector3( +0.0f, +1.5f, -10.5f );
v[1].color = 0xff00ff00; //

v[2].pose = SlimDX::Vector3( +5.5f, +0.0f, -10.5f );
v[2].color = 0xff00ff00; //

// BLUE
v[3].pose = SlimDX::Vector3( -3.5f, +0.0f, 10.5f );
v[3].color = 0xff0000f0; //

v[4].pose = SlimDX::Vector3( +0.0f, +2.5f, 10.5f );
v[4].color = 0xff0000f0; //

v[5].pose = SlimDX::Vector3( +3.5f, +0.0f, 10.5f );
v[5].color = 0xff0000f0; //

SlimDX::DataStream^ sl_ds;
sl_ds = sl_vb->Lock( 0,0,SlimDX::Direct3D9::LockFlags::None );
sl_ds->WriteRange( v ); //Write( v );
sl_vb->Unlock();

//***************************************************************

sl_vb3 = gcnew SlimDX::Direct3D9::VertexBuffer( sl_device,
18 * 16,
SlimDX::Direct3D9::Usage::None,
SlimDX::Direct3D9::VertexFormat::Position | SlimDX::Direct3D9::VertexFormat::Diffuse, //SlimDX::Direct3D9::VertexFormat::Diffuse,
SlimDX::Direct3D9::Pool::Managed );

array<CustomVertex>^ v3 = gcnew array<CustomVertex>(18);

// cross
v3[0].pose  = SlimDX::Vector3( -10.0f, 0.0f, 0.0f );
v3[0].color = 0xffff0000; //
v3[1].pose  = SlimDX::Vector3( +10.0f, 0.0f, 0.0f );
v3[1].color = 0xffff0000; //
v3[2].pose  = SlimDX::Vector3( 0.0f, -10.0f, 0.0f );
v3[2].color = 0xffff0000; //
v3[3].pose  = SlimDX::Vector3( 0.0f, +10.0f, 0.0f );
v3[3].color = 0xffff0000; //
v3[4].pose  = SlimDX::Vector3( 0.0f, 0.0f, -10.0f );
v3[4].color = 0xffff0000; //
v3[5].pose  = SlimDX::Vector3( 0.0f, 0.0f, +20.0f );
v3[5].color = 0xffff0000; //

// markers
// +X
v3[6].pose  = SlimDX::Vector3( +10.0f, 1.0f, 0.0f );
v3[6].color = 0xffff0000; //
v3[7].pose  = SlimDX::Vector3( +10.0f, -1.0f, 0.0f );
v3[7].color = 0xffff0000; //
v3[8].pose  = SlimDX::Vector3( +10.0f, 0.0f, -1.0f );
v3[8].color = 0xffff0000; //
v3[9].pose  = SlimDX::Vector3( +10.0f, 0.0f, +1.0f );
v3[9].color = 0xffff0000; //

// +Y
v3[10].pose  = SlimDX::Vector3( -1.0f, +10.0f, 0.0f );
v3[10].color = 0xff00ff00; //
v3[11].pose  = SlimDX::Vector3( +1.0f, +10.0f, 0.0f );
v3[11].color = 0xff00ff00; //
v3[12].pose  = SlimDX::Vector3( 0.0f, +10.0f, +1.0f );
v3[12].color = 0xff00ff00; //
v3[13].pose  = SlimDX::Vector3( 0.0f, +10.0f, -1.0f );
v3[13].color = 0xff00ff00; //

// +Z
v3[14].pose  = SlimDX::Vector3( 0.0f, -1.0f, +10.0f );
v3[14].color = 0xff0000ff; //
v3[15].pose  = SlimDX::Vector3( 0.0f, +1.0f, +10.0f );
v3[15].color = 0xff0000ff; //
v3[16].pose  = SlimDX::Vector3( -1.0f, 0.0f, +10.0f );
v3[16].color = 0xff0000ff; //
v3[17].pose  = SlimDX::Vector3( +1.0f, 0.0f, +10.0f );
v3[17].color = 0xff0000ff; //

SlimDX::DataStream^ sl_ds3;
sl_ds3 = sl_vb3->Lock( 0,0,SlimDX::Direct3D9::LockFlags::None );
sl_ds3->WriteRange( v3, 0 , v3->Length ); //
sl_vb3->Unlock();

//***************************************************************

System::Drawing::Font^ _sysfont = gcnew System::Drawing::Font( "Arial", 20 );
SlimDX::Direct3D9::Font^ _font = gcnew SlimDX::Direct3D9::Font( sl_device, _sysfont );

sl_device->SetRenderState( SlimDX::Direct3D9::RenderState::CullMode, SlimDX::Direct3D9::Cull::None ); //::Counterclockwise );// :Clockwise ); // ::None );
sl_device->SetRenderState( SlimDX::Direct3D9::RenderState::Lighting, false );
sl_device->SetRenderState( SlimDX::Direct3D9::RenderState::ZEnable, true );

SlimDX::Direct3D9::Sprite^ _sprite = gcnew SlimDX::Direct3D9::Sprite( sl_device );

Int32 counter = 0;

float angle = 0; //

SlimDX::DirectInput::DirectInput^ _directinput = gcnew SlimDX::DirectInput::DirectInput();
SlimDX::DirectInput::Mouse^ mouse = gcnew SlimDX::DirectInput::Mouse( _directinput );

mouse->Properties->AxisMode = SlimDX::DirectInput::DeviceAxisMode::Relative;

mouse->Acquire();

float pointM = -15.0f;
Int32 value = 0;

while ( this->IsDisposed == false ) {

value = mouse->GetCurrentState()->Z;

if ( value > 0 ) {
pointM = pointM + 1;
}//
if ( value < 0 ) {
pointM = pointM - 1;
}//

// camera / frustum
sl_device->SetTransform( SlimDX::Direct3D9::TransformState::View,
SlimDX::Matrix::LookAtLH( SlimDX::Vector3( 0.0f,  0.0f, pointM ), //
SlimDX::Vector3( 0.0f,  0.0f, 0.0f ),
SlimDX::Vector3( 0.0f, +1.0f,  0.0f ) ) );

// perspective projection
/*
sl_device->SetTransform( SlimDX::Direct3D9::TransformState::World,
SlimDX::Matrix::Translation( 0.0f, 0.0f, 0.0f ) *
SlimDX::Matrix::RotationY( +0.3f ) *
SlimDX::Matrix::RotationX( -0.2f ) *
SlimDX::Matrix::RotationZ( 0.0f )
);  */

sl_device->SetTransform( SlimDX::Direct3D9::TransformState::Projection,
SlimDX::Matrix::PerspectiveFovLH( (float)Math::PI / 2, 1.76795f, 0.1f, 100.0f) );

SlimDX::Color4 bkcolor( 255.0f, 0.0f, 0.0f, 0.0f );
sl_device->Clear( SlimDX::Direct3D9::ClearFlags::Target , SlimDX::Color4( SlimDX::Color3( 0.0f, 0.0f, 0.0f )) , 1.0f, 0 );
sl_device->Clear( SlimDX::Direct3D9::ClearFlags::ZBuffer, SlimDX::Color4( SlimDX::Color3( 0.0f, 0.0f, 0.0f )) , 1.0f, 0 );

sl_device->BeginScene();

// triangle
sl_device->SetStreamSource( 0, sl_vb, 0 , sizeof(CustomVertex) );
sl_device->VertexFormat = SlimDX::Direct3D9::VertexFormat::Position | SlimDX::Direct3D9::VertexFormat::Diffuse;
sl_device->DrawPrimitives( SlimDX::Direct3D9::PrimitiveType::TriangleList, 0, 2 );

// reticle
sl_device->SetStreamSource( 0, sl_vb3, 0 , sizeof(CustomVertex) );
sl_device->VertexFormat = SlimDX::Direct3D9::VertexFormat::Position | SlimDX::Direct3D9::VertexFormat::Diffuse;
sl_device->DrawPrimitives( SlimDX::Direct3D9::PrimitiveType::LineList, 0, 9 );

// text
_sprite->Begin( SlimDX::Direct3D9::SpriteFlags::AlphaBlend );
_font->DrawString( _sprite, "H e l l o : " + counter.ToString(), 20, 20, SlimDX::Color4( SlimDX::Color3( 1.0f, 1.0f, 1.0f ) ) );
_sprite->End();

sl_device->EndScene();

sl_device->Present();

Application::DoEvents();

angle =  angle + (float)0.017;
if ( angle > ( Math::PI * 2 ) ) angle = 0;

counter++;

}// while

return;

//
//TODO: Add the constructor code here
//
}

protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}

delete sl_device;
delete sl_vb;
delete sl_vb2;
delete sl_vb3;

}
private: System::Windows::Forms::Panel^  panel1;

/// <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(960, 543);
this->panel1->TabIndex = 0;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(996, 568);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);

}
#pragma endregion

};// public ref class Form1 : public System::Windows::Forms::Form

}// namespace CLRW58

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.