zoukankan      html  css  js  c++  java
  • QT笔记 -- (6) opengl

    参考 http://blog.csdn.net/myths_0/article/details/24431597

    用glut绘制一个茶壶

    一句话,继承QGLWidget,实现下面三个函数,用子类定义窗口就行了。

    三个函数:

        void initializeGL();
        void paintGL();
        void resizeGL(int width, int height);

    下面是我的QGLWidget的子类的源码。

    GLWidget.h

    #pragma once
    #include "qgl.h"
    #include <gl/GLU.h>
    #include <OpenGL/GLUT.H>

    class GLWidget : public QGLWidget{
        Q_OBJECT

    public:
        GLWidget(QWidget *parent = nullptr) :QGLWidget(parent){};
        ~GLWidget();

    protected:
        void initializeGL();
        void paintGL();
        void resizeGL(int width, int height);

        void keyPressEvent(QKeyEvent *e);
    };

    GLWidget.cpp

    #include "GLWidget.h"


    GLWidget::~GLWidget(){}

    void GLWidget::initializeGL(){
        glShadeModel(GL_SMOOTH);
        glClearColor(0.0, 0.0, 0.0, 0.0);
        glClearDepth(1.0);
        glEnable(GL_DEPTH_TEST);
        glDepthFunc(GL_LEQUAL);
        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    }

    void GLWidget::paintGL(){
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glLoadIdentity();
        glScalef(0.1,0.1,0.1);
        gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);
        glutWireTeapot(2);
    }

    void GLWidget::resizeGL(int width, int height){
        glViewport(0, 0, (GLint)width, (GLint)height);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45.0, (GLfloat)width / (GLfloat)height, 0.1, 100.0);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    }

    void GLWidget::keyPressEvent(QKeyEvent *e){
        
    }
  • 相关阅读:
    允许debian wheezy支持IOS7+的iphone.
    openSUSE 国内镜像摘要
    策略模式总结
    顺序串
    WindowState注意事项
    NLP | 自然语言处理
    Using Autorelease Pool Blocks
    NSAutoreleasePool & thread
    oc语言特性
    oc语言基础整理
  • 原文地址:https://www.cnblogs.com/redips-l/p/7041038.html
Copyright © 2011-2022 走看看