Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Using Direct3D 9 with Qt - flicker problem

This topic is 4005 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've created a widget class (Direct3D_9_Widget : public QWidget) that uses IDirect3DDevice9 to draw inside QWidget::paintEvent. This works fine, until I try to animate anything. At the moment, all my app does is render a spinning cube. Unfortunately, the spinning cube is blurry and difficult to see. The animation is not smooth at all. I'm using a QBasicTimer to do the animation. The timer forces a screen repaint every 20 ms. According to the Qt docs, if you want to use GDI or Direct3D on Windows with Qt, you need to: 1) Override QWidget::paintEngine to return NULL 2) Call QWidget::setAttribute(Qt::WA_PaintOnScreen, true) The documentation also advises that if you do this, you need to implement your own double-buffering. I've done 1) and 2). You can't use Direct3D without using double-buffering, so I didn't think I needed to worry about that. I've pasted my Direct3D initialisation code below. I'm unsure how to trouble shoot this. The Qt OpenGL examples run very nicely on my computer, so I would expect D3D performance to be at least as good. If anyone has any advice, I'd appreciate it. Thanks,
HRESULT Direct3D_9_Widget::Create_Direct3D_Device_9(void)
    HRESULT l_hr = m_Interface_Direct3D_9->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, & m_Adapter_Display_Mode);
    if ( FAILED(l_hr) )
        return l_hr;

    // Use the width of the client area of the hDeviceWindow (or the focus window if hDeviceWindow is NULL)
    m_Present_Parameters.BackBufferWidth = 0;
    // Use the height of the client area of the hDeviceWindow (or the focus window if hDeviceWindow is NULL)
    m_Present_Parameters.BackBufferHeight = 0;
    //m_Present_Parameters.BackBufferFormat = m_Adapter_Display_Mode.Format;
    m_Present_Parameters.BackBufferFormat = D3DFMT_UNKNOWN;
    m_Present_Parameters.BackBufferCount = 1;

    m_Present_Parameters.MultiSampleType = D3DMULTISAMPLE_NONE;
    m_Present_Parameters.MultiSampleQuality = 0;

    m_Present_Parameters.SwapEffect = D3DSWAPEFFECT_COPY;

    m_Present_Parameters.hDeviceWindow = (HWND) winId();
    m_Present_Parameters.Windowed = true;

    m_Present_Parameters.EnableAutoDepthStencil = true;
// Returns a valid depth stencil format
    m_Present_Parameters.AutoDepthStencilFormat = Find_Best_Depth_Stencil_Format();


    m_Present_Parameters.FullScreen_RefreshRateInHz = D3DPRESENT_INTERVAL_DEFAULT;

    m_Present_Parameters.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;


    l_hr = m_Interface_Direct3D_9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, 0, l_Behaviour_Flags, & m_Present_Parameters, & m_Interface_Direct3D_Device_9);
    return l_hr;

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!