Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3663630
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:33:08+00:00 2026-05-19T01:33:08+00:00

I am creating a simple application to get familiar with SlimDX library. I found

  • 0

I am creating a simple application to get familiar with SlimDX library. I found some code written in MDX and I’m trying to convert it to run on SlimDX. I am having some problems with the light because everything is being shown as black. The code is:

public partial class DirectTest : Form
{
    private Device device= null;
    private float angle = 0.0f;
    Light light = new Light();

    public DirectTest()
    {
        InitializeComponent();

        this.Size = new Size(800, 600);
        this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
    }
    /// <summary>
    /// We will initialize our graphics device here
    /// </summary>
    public void InitializeGraphics()
    {
        PresentParameters pres_params = new PresentParameters()
        {
            Windowed = true,
            SwapEffect = SwapEffect.Discard
        };
        device = new Device(new Direct3D(), 0, DeviceType.Hardware, this.Handle, 
                    CreateFlags.SoftwareVertexProcessing, pres_params);
    }

    private void SetupCamera()
    {
        device.SetRenderState(RenderState.CullMode, Cull.None);
        device.SetTransform(TransformState.World, Matrix.RotationAxis(new Vector3(angle / ((float)Math.PI * 2.0f),
                         angle / ((float)Math.PI * 4.0f), angle / ((float)Math.PI * 6.0f)),
                        angle / (float)Math.PI));
        angle += 0.1f;
        device.SetTransform(TransformState.Projection, Matrix.PerspectiveFovLH((float)Math.PI /
            4, this.Width / this.Height, 1.0f, 100.0f));
        device.SetTransform(TransformState.View, Matrix.LookAtLH(new Vector3(0, 0, 5.0f),
            new Vector3(), new Vector3(0, 1, 0)));
        device.SetRenderState(RenderState.Lighting, false);
    }

    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
        device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.CornflowerBlue, 1.0f, 0);
        SetupCamera();

        CustomVertex.PositionColored[] verts = new CustomVertex.PositionColored[3];
        verts[0].Position = new Vector3(0.0f, 1.0f, 1.0f);
        verts[0].Normal = new Vector3(0.0f, 0.0f, -1.0f);
        verts[0].Color = System.Drawing.Color.White.ToArgb();
        verts[1].Position = new Vector3(-1.0f, -1.0f, 1.0f);
        verts[1].Normal = new Vector3(0.0f, 0.0f, -1.0f);
        verts[1].Color = System.Drawing.Color.White.ToArgb();
        verts[2].Position = new Vector3(1.0f, -1.0f, 1.0f);
        verts[2].Normal = new Vector3(0.0f, 0.0f, -1.0f);
        verts[2].Color = System.Drawing.Color.White.ToArgb();

        light.Type = LightType.Point;
        light.Position = new Vector3();
        light.Diffuse = System.Drawing.Color.White;
        light.Attenuation0 = 0.2f;
        light.Range = 10000.0f;

        device.SetLight(0, light);
        device.EnableLight(0, true);

        device.BeginScene();

        device.VertexFormat = CustomVertex.PositionColored.format;
        device.DrawUserPrimitives<CustomVertex.PositionColored>(PrimitiveType.TriangleList, 1, verts);
        device.EndScene();

        device.Present();
        this.Invalidate();
    }
}

}

The Vertex Format that I am using is the following

    [StructLayout(LayoutKind.Sequential)]
    public struct PositionNormalColored
    {
        public Vector3 Position;
        public int Color;
        public Vector3 Normal;
        public static readonly VertexFormat format = VertexFormat.Diffuse | VertexFormat.Position | VertexFormat.Normal;
    }

Any suggestions on what the problem might be?
Thanks in Advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:33:08+00:00Added an answer on May 19, 2026 at 1:33 am

    Why are you calling device.SetRenderState(RenderState.Lighting, false)? I don’t see where you turn lighting back on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a simple web application. I need to get reference to ServletContext
Was creating a simple console application to do some prototyping and was shocked to
I am creating a simple web site to get more familiar with MVC 2.0.
I'm creating a threaded message board and I'm trying to keep it simple. There's
I've been trying to build a simple prototype application in Django, and am reaching
I am creating a simple application with Django. I realized that I am doing
I'm creating a simple application that simply populates a DataGridView with a strongly typed
Im attempting to use Silverlight and MVC together. After creating a simple Silverlight application
I'm creating a simple application with xcode and objc and I need to load
I did a simple view based application. what i did is creating view additional

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.