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. multiple QOpenGLWidgets in the same window only show one and the other can't paint after set QSurfaceFormat::setDefaultFormat
Forum Updated to NodeBB v4.3 + New Features

multiple QOpenGLWidgets in the same window only show one and the other can't paint after set QSurfaceFormat::setDefaultFormat

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 223 Views
  • 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.
  • P Offline
    P Offline
    Princein
    wrote on last edited by
    #1

    I developed a cross-platform app which can work both mac and windows using qt framework, there are two QOpenGLWidgets in my project, and I need to change the QSurfaceFormat::defaultFormat using QSurfaceFormat::setDefaultFormat() method, here is the code for change QSurfaceFormat::defaultFormat in the main.cpp

    int main(int argc, char *argv[])
    {
       QSurfaceFormat defaultFormat = QSurfaceFormat::defaultFormat();
    //_defaultFormat = defaultFormat;
    QSurfaceFormat format;
    	format.setSamples(8);
    	format.setVersion(3, 3);
    #if __APPLE__
    	format.setProfile(QSurfaceFormat::CoreProfile);
    #elif _WIN32
    	format.setProfile(QSurfaceFormat::CompatibilityProfile);
    #endif
    	//setFormat(format);
    	QSurfaceFormat::setDefaultFormat(format);
    	QApplication a(argc, argv);
            return a.exec();
    }
    

    now, when I run the app, only one QOpenGLWidget can paint normal, the others can't paint anything, even I use a simple code to paint a simple rectangle, it can't paint too, here is the test code in the test .cpp file in my project to paint a simple rectangle :
    myopenglview.cpp

    
    #include "myopenglview.h"
    MyOpenGLView::MyOpenGLView(QWidget *parent) : QOpenGLWidget(parent)
    {
    	
    }
    void MyOpenGLView::initializeGL(){
         	glClearColor(0.0,0.0,0.0,0.0);
    	/*
    	 * initialize viewing values
    	 */
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
    
    
    }
    
    void MyOpenGLView::paintGL(){
       	glClear(GL_COLOR_BUFFER_BIT);
    	/*
    	 * draw white polyon (rectangle) with corners at
    	 * (0.25,0.25,0.0) and (0.75,0.75,0.0)
    
    	 */
    	glColor3f(1.0,1.0,1.0);
    	glBegin(GL_POLYGON);
    	glVertex3f(0.25,0.25,0.0);
    	glVertex3f(0.75,0.25,0.0);
    	glVertex3f(0.75,0.75,0.0);
    	glVertex3f(0.25,0.75,0.0);
    	glEnd();
    
    	/*
    	 * don't wait!
    	 * start processing buffered OpenGL routines
    	 */
    	glFlush();
    
    }
    void MyOpenGLView::resizeGL(int w,int h){
    
    }
    
    

    when I run the app, I can only see the black background of MyOpenGLView, It seems the MyOpenGLView can only paint the black background correct, the content can't paint, I don't why, can you give me some tips, thanks a lot!

    1 Reply Last reply
    0

    • Login

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