日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Qt利用openGL绘制三棱锥

發(fā)布時間:2024/3/12 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Qt利用openGL绘制三棱锥 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

直接上代碼:

Pro中添加QT?????? += core gui openglwin32:LIBS+=-lOpengl32\-lglu32 \-lglutmainwindow.h中添加:#include <QWindow>#include <QOpenGLFunctions_4_5_Core>class MainWindow : public QWindow,QOpenGLFunctions_4_5_Core{Q_OBJECTpublic:MainWindow(QWindow *parent = nullptr);~MainWindow();virtual void render();virtual void initialize();protected:void exposeEvent(QExposeEvent *);void resizeEvent(QResizeEvent *);private:void myPerspective(GLdouble fov,GLdouble aspectRatio,GLdouble zNear,GLdouble zFar);QOpenGLContext *m_context;};mainwindow.cpp中添加:#include "mainwindow.h"#include <QOpenGLContext>MainWindow::MainWindow(QWindow *parent): QWindow(parent), m_context(0){setSurfaceType(QWindow::OpenGLSurface);}MainWindow::~MainWindow(){}void MainWindow::myPerspective(GLdouble fov, GLdouble aspectRatio, GLdouble zNear, GLdouble zFar){GLdouble rFov= fov * 3.14159265/ 180.0;glFrustum(-zNear * tan(rFov /2.0)* aspectRatio, zNear * tan(rFov / 2.0)*aspectRatio,-zNear * tan(rFov /2.0), zNear * tan(rFov /2.0),zNear,zFar);}void MainWindow::render(){glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glViewport(0,0,(GLint)width(),(GLint)height());glMatrixMode(GL_PROJECTION);glLoadIdentity();myPerspective(45.0,(GLfloat)width()/(GLfloat)height(),0.1,100.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();glTranslatef(0.0f,0.0f,-5.0f);glRotatef(30,1.0f,1.0f,1.0f);glBegin(GL_TRIANGLES);glColor3f(0.0,0.0,1.0);glVertex3f(0.0f,0.0f,0.0f);glVertex3f(1.0f,1.0f,0.0f);glVertex3f(1.0f,0.0f,1.0f);glColor3f(1.0,0.0,1.0);glVertex3f(1.0f,1.0f,0.0f);glVertex3f(2.0f,0.0f,0.0f);glVertex3f(1.0f,0.0f,1.0f);glColor3f(0.0,1.0,0.0);glVertex3f(0.0f,0.0f,0.0f);glVertex3f(1.0f,1.0f,0.0f);glVertex3f(2.0f,0.0f,0.0f);glColor3f(0.0,1.0,1.0);glVertex3f(0.0f,0.0f,0.0f);glVertex3f(1.0f,0.0f,1.0f);glVertex3f(2.0f,0.0f,0.0f);glEnd();}void MainWindow::initialize(){glShadeModel(GL_SMOOTH);glClearColor(1.0f,1.0f,1.0f,1.0f);glClearDepth(1.0f);glEnable(GL_DEPTH_TEST);glDepthFunc(GL_LEQUAL);glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);}void MainWindow::exposeEvent(QExposeEvent *){if (!isExposed()) return;bool needsInitialize =false;if(!m_context){m_context = new QOpenGLContext(this);m_context ->setFormat(requestedFormat());m_context->create();needsInitialize= true;}m_context->makeCurrent(this);if(needsInitialize){initializeOpenGLFunctions();initialize();}render();m_context->swapBuffers(this);}void MainWindow::resizeEvent(QResizeEvent *){if (!isExposed()) return;bool needsInitialize =false;if(!m_context){m_context = new QOpenGLContext(this);m_context ->setFormat(requestedFormat());m_context->create();needsInitialize= true;}m_context->makeCurrent(this);if(needsInitialize){initializeOpenGLFunctions();initialize();}render();m_context->swapBuffers(this);}

總結(jié)

以上是生活随笔為你收集整理的Qt利用openGL绘制三棱锥的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。