Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to use opengl native function in my function ,not in initializeGL(),paintGL(),resizeGL(int w, int h)
Forum Updated to NodeBB v4.3 + New Features

how to use opengl native function in my function ,not in initializeGL(),paintGL(),resizeGL(int w, int h)

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 111 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr Lonely
    wrote on 13 Jul 2021, 12:44 last edited by
    #1

    I write a program to read 3D obj file and show it in QopenglWidget. When I read the file in initializeGL() and set the VAO in it,everything is ok.Also I try to change the path, the result is fine.But when I do these things in my function mySlotOpenFile() ,I get wrong result,why?
    frist picture is the sphere1.obj contain a plane and a sphere
    ![5804d1e6-9df7-4f57-8937-a30470fdc980-N$Z$4KP8]WPWF4V8]FUQ}CR.png](https://ddgobkiprc33d.cloudfront.net/216346b9-fc56-4038-81fb-ae83f720091e.png)
    second picture is sphere.obj contain a small sphere
    bb2b362a-7717-47cc-a608-8e79679e8850-SCHO35Q2$_BB@2FT@U9)75G.png
    And in third pciure ,I open sphere1.obj in nitializeGL() ,and then open sphere.obj in my function mySlotOpenFile() .which I get is this ,why?
    6507c61c-a9fe-4142-a145-6ea1ee944959-5I}(AOW651F2XHI2GULHJI7.png

    #include "glWidget.h"
    #include <QMessageBox>
    #include<Qmath.h>
    #include<Qdebug>
    #include<FileSystem>
    glWidget::glWidget(QWidget *parent)
    	: QOpenGLWidget(parent)
    {
    	myrender = NULL;
    }
    
    glWidget::~glWidget()
    {
    }
    
    void glWidget::initializeGL()
    {
    	core = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_4_3_Core>();
    	myrender = new MyRender(core);
    	//myrender->openFile("easymodel/sphere.obj");
    	drawFlag = true;
    }
    
    void glWidget::paintGL()
    {
    	if (drawFlag==false)
    	{
    		return;
    	}
    	myrender->Draw();
    	update();
    }
    
    void glWidget::resizeGL(int w, int h)
    {
    	
    }
    
    
    void glWidget::mySlot2(int front, int back,int left,int right)
    {
    	myrender->setCameraPos(front, back, left, right);
    }
    
    void glWidget::mySlotMosue(QPointF firstPoint, QPointF nextPoint)
    {
    	myrender->setCameraFront(firstPoint, nextPoint);
    }
    
    void glWidget::mySlotOpenFile()
    {
    	this->makeCurrent();
    	//auto *ctx = QOpenGLContext::currentContext();
    	drawFlag = false;
    	//myrender = new MyRender(core);
    	QString fileName = QFileDialog::getOpenFileName(NULL, "标题", ".");
    	if (fileName!="")
    	{
    		myrender->openFile(fileName);
    	}
    	core->glClearColor(0.6f, 0.2f, 0.2f, 1.0f);
    
    	drawFlag = true;
    	this->doneCurrent();
    	update();
    }
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 13 Jul 2021, 18:37 last edited by
      #2

      Hi and welcome to devnet,

      I would start with using QOpenGLWidget::context to use the one associated with your widget.

      Are you sure your MyRender class does not do anything unusual with regard to the OpenGL state ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      1/2

      13 Jul 2021, 12:44

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved