基于QT 实现的LearnGL例子

        LOpenGL 是学习OpenGL非常好的资料,网址是:LearnOpenGL CN (learnopengl-cn.github.io)

        最近复习OpenGL,基于QT,拷贝实现了LearnGL的一些例子。下载地址:

        QT+OpenGL+学习基于QT开发OpenGL应用

        例子效果如下,一些代码如有问题,请参考LearnOpenGL网站。

 

 

         例子中的主要类说明如下:

1. OpenGL视图类OpenGlView(openglview.h),继承了QOpenGLWidget,QOpenGLExtraFunctions

class OpenGlView : public QOpenGLWidget,public QOpenGLExtraFunctions
{
public:    
        OpenGlView();
protected:    
        virtual void initializeGL() override;    
        virtual void paintGL() override;    
        virtual void resizeGL(int w, int h) override;    
        void keyPressEvent(QKeyEvent *event) override;    
        void mousePressEvent(QMouseEvent *event)override;    
        void mouseReleaseEvent(QMouseEvent *event)override;   
        void mouseDoubleClickEvent(QMouseEvent *event)override;    
        void mouseMoveEvent(QMouseEvent *event)override;    
        void wheelEvent(QWheelEvent *event)override;
private slots:    
        void OnTimerUpdate();
private:    
        AbstractOpenGLRender* myPreRender; //LearnOpenGL例子的抽象类   
        QTimer* myTimer;
};

视图类的主要逻辑是在paintGL方法中,调用例子的渲染含方法:

void OpenGlView::paintGL()
{   
        AbstractOpenGLRender* render = OpenGLRenders::CurrRender();    
        if(myPreRender != render)    
        {        
                if(myPreRender != nullptr)           
                myPreRender->releaseGLRS(this);       
                myPreRender = render;   
        }    
        if(render != nullptr)    
        {        
                render->ResetSize(this->width(),this->height());        
                render->renderGL(this);    
        }
}

2. 例子的具体实现在OpenGLLearn目录

3. 2D游戏的代码在2DGame目录

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Learn the fundamentals of QT 5 framework to develop interactive cross-platform applications Key Features A practical guide on the fundamentals of application development with QT 5 Learn to write scalable, robust and adaptable C++ code with QT Deploy your application on different platforms such as Windows, Mac OS, and Linux Book Description Qt is a mature and powerful framework for delivering sophisticated applications across a multitude of platforms. It has a rich history in the Linux world, is widely used in embedded devices, and has made great strides in the Mobile arena over the past few years. However, in the Microsoft Windows and Apple Mac OS X worlds, the dominance of C#/.NET and Objective-C/Cocoa means that Qt is often overlooked. This book demonstrates the power and flexibility of the Qt framework for desktop application development and shows how you can write your application once and deploy it to multiple operating systems. Build a complete real-world line of business (LOB) solution from scratch, with distinct C++ library, QML user interface, and QtTest-driven unit-test projects. This is a suite of essential techniques that cover the core requirements for most LOB applications and will empower you to progress from a blank page to shipped application. What you will learn Install and configure the Qt Framework and Qt Creator IDE Create a new multi-project solution from scratch and control every aspect of it with QMake Implement a rich user interface with QML Learn the fundamentals of QtTest and how to integrate unit testing Build self-aware data entities that can serialize themselves to and from JSON Manage data persistence with SQLite and CRUD operations Reach out to the internet and consume an RSS feed Produce application packages for distribution to other users Who This Book Is For This book is for application developers who want a powerful and flexible framework to create modern, responsive applications on Microsoft Windows, Apple Mac OS X, and Linux desktop platforms. You should be comfortable with C++ but no prior knowledge of Qt or QML is required. Table of Contents Install the Qt Framework and Qt Creator IDE Create a new solution and sub projects ready for application development. UX layout and navigation Styling QML and adding custom components Implement self aware data entities and JSON serialisation Unit testing our data entities Persist our data in a SQLite database Connect to the internet and consume a RSS feed Create a customised installation package for our application

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值