qt5.6.2 opengl GL_INVALID_OPERATION
Unsolved
General and Desktop
-
rencently, i used to render a model. but a problem come with me. when i init vao and vbo of my model in the Init() function, it can render nomal. but when drag and drop a model and in which callback function init vao and vbo of my model ,a error GL_INVALID_OPERATION come out. i try to do in many ways, but no method solves.how i can do? the code is below.
#include "XLogin.h" #include "XMainWindow.h" #include "./OpenGL/XOpenGLWindow.h" #include <QtWidgets/QApplication> #include <QFile> int main(int argc, char *argv[]) { QApplication::setAttribute(Qt::AA_UseDesktopOpenGL); QApplication::setAttribute(Qt::AA_UseSoftwareOpenGL); QApplication a(argc, argv); //当前目录 QDir dir; qDebug() << "------ Start : Current Program Dir is = " << dir.currentPath() << endl; //设置风格 - 读取文件编码为UTF-8,否则需要转码。 QFile styleSheet("app.css"); styleSheet.open(QIODevice::ReadOnly); QString typle = styleSheet.readAll(); a.setStyleSheet(typle); //设置OpenGL的版本信息 QSurfaceFormat format; format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); format.setRenderableType(QSurfaceFormat::OpenGL); format.setProfile(QSurfaceFormat::CoreProfile); format.setVersion(3, 3); format.setRedBufferSize(8); format.setGreenBufferSize(8); format.setBlueBufferSize(8); format.setAlphaBufferSize(8); format.setDepthBufferSize(24); format.setStencilBufferSize(8); format.setSamples(8); QSurfaceFormat::setDefaultFormat(format); //打开窗口 XOpenGLWindow xOpenGLWindow; xOpenGLWindow.setFormat(format); xOpenGLWindow.setFixedSize(1280, 800); xOpenGLWindow.show(); return a.exec(); }
#include "XOpenGLWindow.h" XOpenGLWindow::XOpenGLWindow(QWidget *parent) :QOpenGLWidget(parent) { //全屏 m_bFullScreen = true; m_Width = 0; m_Height = 0; m_TimerID = 0; m_LastMouseX = 0; m_LastMouseY = 0; } XOpenGLWindow::~XOpenGLWindow() { killTimer(m_TimerID); } void XOpenGLWindow::initializeGL() { setAcceptDrops(true); //Init XManager::GetRef().Init(); //启动定时器 m_TimerID = startTimer(30); } void XOpenGLWindow::resizeGL(int width, int height) { m_Width = width; m_Height = height; //Resize XManager::GetRef().m_Render->Resize(m_Width, m_Height); } void XOpenGLWindow::paintGL() { //Logic //更新 XManager::GetRef().m_Camera->OnUpdate(); //Render XManager::GetRef().m_Render->Render(XManager::GetRef(), m_Width, m_Height); //XManager::GetRef().m_Skybox->Render(XManager::GetRef(), m_Width, m_Height); } void XOpenGLWindow::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::RightButton) { XManager::GetRef().m_Camera->OnRightButtonDown(event->x(), event->y()); ShowCursor(FALSE); m_LastMouseX = event->x(); m_LastMouseY = event->y(); } } void XOpenGLWindow::mouseReleaseEvent(QMouseEvent *event) { if (event->button() == Qt::RightButton) { XManager::GetRef().m_Camera->OnRightButtonUp(event->x(), event->y()); ShowCursor(TRUE); QPoint rect = this->pos(); SetCursorPos(rect.x() + m_LastMouseX, rect.y() + m_LastMouseY); } } void XOpenGLWindow::mouseDoubleClickEvent(QMouseEvent *event) { Q_UNUSED(event); } void XOpenGLWindow::mouseMoveEvent(QMouseEvent *event) { XManager::GetRef().m_Camera->OnMouseMove(event->x(), event->y()); } #ifndef QT_NO_WHEELEVENT void XOpenGLWindow::wheelEvent(QWheelEvent *event) { if (event->delta() > 0) { XManager::GetRef().m_Camera->OnZoomIn(); } else { XManager::GetRef().m_Camera->OnZoomOut(); } } #endif void XOpenGLWindow::keyPressEvent(QKeyEvent *event) { switch (event->key()) { case Qt::Key_W: case Qt::Key_S: case Qt::Key_A: case Qt::Key_D: XManager::GetRef().m_Camera->OnKeyDown(event->key()); break; case Qt::Key_1: if (event->modifiers() == Qt::AltModifier) close(); break; default: QWidget::keyPressEvent(event); break; } } void XOpenGLWindow::keyReleaseEvent(QKeyEvent *event) { switch (event->key()) { case Qt::Key_W: case Qt::Key_S: case Qt::Key_A: case Qt::Key_D: XManager::GetRef().m_Camera->OnKeyUp(event->key()); break; default: QWidget::keyPressEvent(event); break; } } void XOpenGLWindow::dragEnterEvent(QDragEnterEvent *event) { if (event->mimeData()->hasFormat("text/uri-list")); { event->acceptProposedAction(); } } void XOpenGLWindow::dropEvent(QDropEvent *event) { QList<QUrl> urls = event->mimeData()->urls(); if (urls.isEmpty()) return; QString fileName = urls.first().toLocalFile(); if (fileName.isEmpty()) return; qDebug() << fileName; XManager::GetRef().m_Render->ResetFile("./Resources/Model/skin_man.FBX"); } void XOpenGLWindow::timerEvent(QTimerEvent * event) { repaint(); }
#include "Render.h" #include <QMatrix4x4> #include "../Manager.h" XRender::XRender() { } XRender::~XRender() { } void XRender::Init() { //Init OpenGL Functions initializeOpenGLFunctions(); //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); //Init value glClearColor(0.2f, 0.3f, 0.5f, 1.0f); glEnable(GL_DEPTH_TEST); glClearDepth(1.0f); fbx = new XFbxLoader(); fbx->Init(); fbx->LoadFbxFile("./Resources/Model/skin_man.fbx"); fbx->Reset(); fbx->LoadFbxFile("./Resources/Model/skin_man.fbx"); } void XRender::ResetFile(const char* pFileName) { fbx->Reset(); fbx->LoadFbxFile("./Resources/Model/tauren.fbx"); } void XRender::Resize(int width, int height) { glViewport(0, 0, width, height); } void XRender::Render(XManager& xManager, int width, int height) { glViewport(0, 0, width, height); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (fbx) fbx->Render(width, height); }