• Advertisement
Sign in to follow this  

[MDX] Rendering from library problem (solved)

This topic is 3858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I'm working on an application that renders something in a PictureBox control using a library (my own). All the DirectX and engine stuff is located in the library. However it doesn't work. In other words, the application MyApp has a reference to MyLib. MyApp starts and passes the PictureBox.Handle to MyLib, which creates a D3D device using the passed Handle. There are no compilation or runtime errors but nothing is displayed in the PictureBox during runtime. I do get a LoaderLock warning in Debug mode however (any solutions to that? I currently suppress it). Code is in C# MyApp code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MyLib;                       /* The engine lib */

namespace MyApp
{
    public partial class FormMain : Form
    {
        private Renderer            _renderer      = null;

        public FormMain()
        {
            InitializeComponent();

            /*
            pbxViewports is the PictureBox I want MyLib to draw stuff to.                       
            */
            _renderer = new Renderer(pbxViewports.Handle);
        }
        
        private void FormMain_Shown(object sender, EventArgs e)
        {
            /*Render scene (will only clear the screen to black atm*/
            _renderer.Render();
        }
    }
}




MyLib code (a standard class library):
using System;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace MyLib
{
    public sealed class Renderer
    {
        public  static Device        _device;            /*D3D device*/
        private PresentParameters    _presentParameters;

        /*
        Constructor
        -----------
        Takes the passed handle and creates a device for it
        */
        public Renderer(IntPtr deviceHandle)
        {
            _presentParameters = new PresentParameters();
            _presentParameters.PresentationInterval = PresentInterval.Default;
            _presentParameters.SwapEffect = SwapEffect.Discard;
            _presentParameters.Windowed = true;

            _device = new Device(0, DeviceType.Hardware, deviceHandle,
                                    CreateFlags.HardwareVertexProcessing,
                                    _presentParameters);

            _device.RenderState.CullMode = Cull.None;
            _device.RenderState.ZBufferEnable = true;
            _device.RenderState.ZBufferWriteEnable = true;  
        }

        
        public void Render()
        {
            /*Clear to black and display*/
            _device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);
            _device.Present();
        }
    }
}




I'm running Windows Vista Ultimate 64-bit. Both MyApp and MyLib are compiled as x86 though, because MDX is x86. Any suggestions would be very appreciated. [Edited by - Pauluss86 on June 27, 2007 6:57:17 AM]

Share this post


Link to post
Share on other sites
Advertisement
Have you tried creating and rendering from within your MyApp program, to ensure that device creation and rendering works altogether? Also, if you get an all black PictureBox chances are everything works fine (seeing as you only clear the screen in the Render function). Is the Render function called at all (try a breakpoint there)?

I've made something similar to this, only MyLib references an unmanaged 3D renderer in my case. I've got the code at home though, so I'll post something when I get out of work.

Share this post


Link to post
Share on other sites
Pass in a reference of the class Control to your renderer constructor, then you will be able to create your renderer with any Control, that's the way I do it.



//this is not my constructor but that's the way to do it
public ManagerGrafico(ref Control foControl){
xoDevice = new Device(Manager.Adapters.Default.Adapter, DeviceType.Hardware, foControl, flags, doParams);
}

Share this post


Link to post
Share on other sites
@DarthJappie
Yes, rendering from within the app is no problem. Also, the picturebox didn't display anything (e.g. 'transparant', not black). The strange thing is, the renderfunction is indeed called, the device properly set up, but nothing rendered. When I suddenly exit the application and still try to render I get a DeviceLost exception though.

@Dreamy
Works like a charm! Thanks dude :) The difference a 3 character expression can make :P

edit:
Although my problem is now solved, is this a proper way to render things on screen? I mean, the rendering code can be plugged into any application right now, which is great and also my intention. However, how does this turn out performance wise? Right now I have an application that links to my library which links to the MDX wrapper which communicates with Dx (right?). Any thoughts on this?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement