Giter VIP home page Giter VIP logo

qtdirect3d's Introduction


Qt Direct3D / DirectX Widgets

This project contains Direct3D widgets that can be used within the Qt Framework for DirectX 9, 10, 11 and 12.

There are also Direct3D widgets included that support Dear ImGui.

Contents

Getting Started

Clone the repository:

git clone --recursive https://github.com/giladreich/QtDirect3D.git

The main directories are source and examples:

Directory Description
source Qt custom widgets that you can copy to your projects depending on the Direct3D version you use. Note that under each Direct3D version, there is also the same widget with ImGui integration.
examples Showing how to integrate and interact with the widget.

Building Examples

Using the Widget

In your Qt Widgets Application project, do the following steps:

  • Copy the widget into your project and add it as an existing item.
  • Open MainWindow.ui with QtDesigner and promote the centeralWidget to the widget you copied.
  • Rename centeralWidget to view.
  • Compile to let Qt's uic & moc compiler to do their magic and have proper IntelliSense.

At this point you should have a basic setup to get started and interact with the widget.

Open MainWindow.h file and create the following Qt slots:

public slots:
    void init(bool success);
    void tick();
    void render();
    void renderUI();
Slot Remarks
bool init(bool success) Additional initialization step. success will be true if the widget successfully initialized.
void tick() Update the scene, e.g. change vertices positions.
void render() Present the scene.
void renderUI() Present and manage ImGui windows.

Open MainWindow.cpp and connect the Widget's signals to the previously created slots:

connect(ui->view, &QDirect3DXXWidget::deviceInitialized, this, &MainWindow::init);
connect(ui->view, &QDirect3DXXWidget::ticked, this, &MainWindow::tick);
connect(ui->view, &QDirect3DXXWidget::rendered, this, &MainWindow::render);
connect(ui->view, &QDirect3DXXWidget::renderedUI, this, &MainWindow::renderUI);

As a final step, add the following code to the end of the MainWindow::init function:

QTimer::singleShot(500, this, [&] { ui->view->run(); });

A short delay of 500 milliseconds before the frames are executed ensures that all Qt's internal signals and slots have finished processing.

Handling Close Event

It is necessary to override the closeEvent in order to properly release any used resources:

void MainWindow::closeEvent(QCloseEvent * event)
{
	event->ignore();

	ui->view->release();
	m_bWindowClosing = true;
	QTime dieTime = QTime::currentTime().addMSecs(500);
	while (QTime::currentTime() < dieTime)
		QCoreApplication::processEvents(QEventLoop::AllEvents, 100);

	event->accept();
}

Calling the function event->ignore() at the beginning will postpone the closeEvent allowing for calling the widget's function release. Lastly, giving the application a short delay of 500 milliseconds before accepting the closeEvent.

Preview

Using the widget with imgui and creating a basic scene:

Basic Scene

Game Engine editor using the widget (YouTube playlist):

FX Editor

Flag Editor

Motivation

I've been working with both MFC GUI applications as well as Qt in various projects.

Whilst rewriting some of the MFC applications to use Qt, I noticed that Qt only provides QOpenGLWidget, but no QDirect3DWidget. I therefore began to research different ways to accomplish this.

I realized Qt's internal rendering engine needed to be disabled in order to render into the widget's surface without the internal engine's interference. Once this was achieved, it was thrilling to use the power of Qt, whilst also using Direct3D as the graphics API.

Contributing

Pull-Requests are greatly appreciated should you like to contribute to the project.

Same goes for opening issues; if you have any suggestions, feedback or you found any bugs, please do not hesitate to open an issue.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the license for more details.

qtdirect3d's People

Contributors

giladreich avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.