Results 1 to 11 of 11

Thread: OpenGL Interface

  1. #1
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default OpenGL Interface

    Hi Guys,

    I'm trying to make an OpenGL window without the native "title bar", minimise, maximise and resize buttons as well as the border that you get when you run a normal application.

    I tried:

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. MainWindow w;
    5. //w.show();
    6. w.showFullScreen();
    7.  
    8. return a.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

    Having added a widget to my window as per below attachment but I get a white border (you can't really see the white border in full screen mode, but basically you see a black screen with a white border of around 10-15 pixels in size) if I run the program in full screen mode which I also don't want. So basically I want to be able to create my own interface for example:

    http://i.ytimg.com/vi/hFoHYmWWYMI/maxresdefault.jpg

    Which can run in full screen or not full screen mode.

    EDIT: I've added another example for the black screen with border, you can see a bit off my second monitor and then the black screen with the white border on the main screen.
    Attached Images Attached Images
    Last edited by Atomic_Sheep; 11th October 2015 at 07:51.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL Interface

    Have you set the margins of your outermost layout to 0?

    Cheers,
    _

  3. #3
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: OpenGL Interface

    Ah, I think you're probably right. I spent an hour trying to figure this out by my programming isn't up to scratch.

    I found the margin size in the xml

    Qt Code:
    1. <layoutdefault spacing="6" margin="11"/>
    To copy to clipboard, switch view to plain text mode 

    I know I'm supposed to use:

    Qt Code:
    1. layout()->setContentsMargin(0,0,0,0);
    To copy to clipboard, switch view to plain text mode 

    But I'm not sure where I'm supposed to use that in my code:

    main.cpp

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8. //w.show();
    9. w.setContentsMargins(0,0,0,0); ///////////////////////////////Having this here doesn't work
    10. w.showFullScreen();
    11.  
    12. return a.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.c

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
    5. {
    6. ui->setupUi(this);
    7. }
    8.  
    9. MainWindow::~MainWindow()
    10. {
    11. delete ui;
    12. }
    To copy to clipboard, switch view to plain text mode 

    glwidget.cpp

    Qt Code:
    1. #include "glwidget.h"
    2.  
    3. GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent)
    4. {
    5. }
    6.  
    7. void GLWidget::initializeG()
    8. {
    9.  
    10. }
    11.  
    12. void GLWidget::paintGL()
    13. {
    14.  
    15. }
    16.  
    17. void GLWidget::resizeGL(int w, int h)
    18. {
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Atomic_Sheep; 11th October 2015 at 12:11.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL Interface

    Well, since you say you found the margins in XML, I assume you mean a .ui file as generated by Qt Designer.
    So the easiest way is to change the margins in designer.

    Or, if the GLWidget is the one that should be full screen, don't embed it into another and just create an instance of GLWidget in main().

    Cheers,
    _

  5. #5
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: OpenGL Interface

    Quote Originally Posted by anda_skoa View Post
    Well, since you say you found the margins in XML, I assume you mean a .ui file as generated by Qt Designer.
    So the easiest way is to change the margins in designer.

    Or, if the GLWidget is the one that should be full screen, don't embed it into another and just create an instance of GLWidget in main().

    Cheers,
    _
    Yes I was referring to the ui file generated by Qt Designer.

    I think I know which setting I need to change in designer although you can see it showing 9 x 9 rather 11 x 11 as shown in the .ui file, but I can't modify it since it's grayed out for some reason.
    Attached Images Attached Images
    • File Type: jpg 2.jpg (9.3 KB, 2 views)

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL Interface

    No, that's the widget's geometry.
    Is is disabled because it is in a layout and the layout controls the geometry.

    Change the margins of the layout.

    Any specific reason you need a parent widget at all?

    Cheers,
    _

  7. #7
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: OpenGL Interface

    Got the result I was looking for in terms of borders thanks:

    Qt Code:
    1. QApplication a(argc, argv);
    2.  
    3. GLWidget glwidget;
    4. MainWindow w;
    5.  
    6. w.setCentralWidget(&glwidget);
    7. QHBoxLayout mainLayout;
    8. mainLayout.setMargin(0);
    9.  
    10. w.show();
    11. //w.showFullScreen();
    12.  
    13. return a.exec();
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by anda_skoa View Post
    No, that's the widget's geometry.
    Is is disabled because it is in a layout and the layout controls the geometry.
    Ah that makes sense.

    Quote Originally Posted by anda_skoa View Post
    Any specific reason you need a parent widget at all?
    What do you mean?
    Last edited by Atomic_Sheep; 13th October 2015 at 12:55.

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL Interface

    Quote Originally Posted by Atomic_Sheep View Post
    What do you mean?
    I mean why put the GL widget inside another widget if that widget is not visible at all?

    Cheers,
    _

  9. #9
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: OpenGL Interface

    Quote Originally Posted by anda_skoa View Post
    I mean why put the GL widget inside another widget if that widget is not visible at all?

    Cheers,
    _
    If I understood you correctly, I've re-made my code to now have just one class as per below:

    windows2_0.pro
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2015-10-14T16:48:53
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core opengl
    8.  
    9. QT -= gui
    10.  
    11. TARGET = Windows2_0
    12. CONFIG += console
    13. CONFIG -= app_bundle
    14.  
    15. TEMPLATE = app
    16.  
    17.  
    18. SOURCES += main.cpp \
    19. glwidget.cpp
    20.  
    21. HEADERS += \
    22. glwidget.h
    To copy to clipboard, switch view to plain text mode 

    glwidget.h
    Qt Code:
    1. #ifndef GLWIDGET_H
    2. #define GLWIDGET_H
    3.  
    4. #include <QGLWidget>
    5. #include <QDebug>
    6.  
    7. class GLWidget : public QGLWidget
    8. {
    9. Q_OBJECT
    10. public:
    11. explicit GLWidget(QWidget *parent = 0);
    12.  
    13. void initializeGL();
    14. void paintGL();
    15. void resizeGL(int w, int h);
    16.  
    17. };
    18.  
    19. #endif // GLWIDGET_H
    To copy to clipboard, switch view to plain text mode 

    glwidget.cpp
    Qt Code:
    1. #include "glwidget.h"
    2.  
    3. GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent)
    4. {
    5. }
    6.  
    7. void GLWidget::initializeGL()
    8. {
    9. qDebug() << "2";
    10. }
    11.  
    12. void GLWidget::paintGL()
    13. {
    14. qDebug() << "3";
    15.  
    16. glClear(GL_COLOR_ARRAY_STRIDE | GL_DEPTH_BUFFER_BIT);
    17. glLoadIdentity();
    18.  
    19. /*
    20.   glBegin(GL_TRIANGLES);
    21.   glVertex3f(0,0, 1.0, 0.0);
    22.   glVertex3f(-1,0, -1.0, 0.0);
    23.   glVertex3f(1,0, -1.0, 0.0);
    24.   glEnd();
    25.   */
    26. }
    27.  
    28. void GLWidget::resizeGL(int w, int h)
    29. {
    30. qDebug() << "1";
    31. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include "glwidget.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QCoreApplication a(argc, argv);
    7.  
    8. GLWidget glWidget;
    9.  
    10. glWidget.show();
    11.  
    12. return a.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 

    However, now I'm getting a linker error:

    debug/moc_glwidget.o:moc_glwidget.cpp.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x38): undefined reference to `QWidget::devType() const'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x3c): undefined reference to `QWidget::setVisible(bool)'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x40): undefined reference to `QWidget::sizeHint() const'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x44): undefined reference to `QWidget::minimumSizeHint() const'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x48): undefined reference to `QWidget::heightForWidth(int) const'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x4c): undefined reference to `QWidget::getDC() const'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x50): undefined reference to `QWidget::releaseDC(HDC__*) const'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x58): undefined reference to `QWidget::mousePressEvent(QMouseEvent*)'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x5c): undefined reference to `QWidget::mouseReleaseEvent(QMouseEvent*)'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x60): undefined reference to `QWidget::mouseDoubleClickEvent(QMouseEvent*)'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x64): undefined reference to `QWidget::mouseMoveEvent(QMouseEvent*)'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x68): undefined reference to `QWidget::wheelEvent(QWheelEvent*)'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x6c): undefined reference to `QWidget::keyPressEvent(QKeyEvent*)'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x70): undefined reference to `QWidget::keyReleaseEvent(QKeyEvent*)'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x74): undefined reference to `QWidget::focusInEvent(QFocusEvent*)'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x78): undefined reference to `QWidget::focusOutEvent(QFocusEvent*)'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x7c): undefined reference to `QWidget::enterEvent(QEvent*)'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x80): undefined reference to `QWidget::leaveEvent(QEvent*)'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x88): undefined reference to `QWidget::moveEvent(QMoveEvent*)'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x90): undefined reference to `QWidget::closeEvent(QCloseEvent*)'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x94): undefined reference to `QWidget::contextMenuEvent(QContextMenuEvent*)'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x98): undefined reference to `QWidget::tabletEvent(QTabletEvent*)'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0xd8): undefined reference to `QWidget:aletteChange(QPalette const&)'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0xdc): undefined reference to `QWidget::fontChange(QFont const&)'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0xe0): undefined reference to `QWidget::windowActivationChange(bool)'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0xe4): undefined reference to `QWidget::languageChange()'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x120): undefined reference to `non-virtual thunk to QWidget::devType() const'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x128): undefined reference to `non-virtual thunk to QWidget::getDC() const'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x12c): undefined reference to `non-virtual thunk to QWidget::releaseDC(HDC__*) const'
    debug/moc_glwidget.o:moc_glwidget.cpp: (.rdata$_ZTV8GLWidget[vtable for GLWidget]+0x130): undefined reference to `non-virtual thunk to QWidget::metric(QPaintDevice::PaintDeviceMetric) const'
    collect2: ld returned 1 exit status
    mingw32-make[1]: *** [debug\Windows2_0.exe] Error 1
    mingw32-make: *** [debug] Error 2
    The process "D:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
    Error while building project Windows2_0 (target: Desktop)
    When executing build step 'Make'
    So I obviously need something like widgets or gui in my .PRO file and something like <QMainWindow> in my glwidget.h and inherit from QMainWindow/QWidget, but haven't figured out exactly what. Hopefully you could point me in right direction.

    I've never tried to understand linker errors before, so this is new territory for me.

    I'm aware that I don't have a destructor at this point in time, still trying to work that out.
    Last edited by Atomic_Sheep; 14th October 2015 at 09:02.

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL Interface

    Quote Originally Posted by Atomic_Sheep View Post
    Qt Code:
    1. QT -= gui
    To copy to clipboard, switch view to plain text mode 
    How do you expect this to work?
    QtGui is a dependency of QtWidgets.

    Quote Originally Posted by Atomic_Sheep View Post
    So I obviously need something like widgets or gui in my .PRO file
    Yes, of course.
    I assumed you already had that. How did you get the window to show up if you can't even build the program?

    Quote Originally Posted by Atomic_Sheep View Post
    and something like <QMainWindow> in my glwidget.h
    Why would you need that?

    Quote Originally Posted by Atomic_Sheep View Post
    I'm aware that I don't have a destructor at this point in time, still trying to work that out.
    If you don't need to do any special destruction handling you won't need a destructor.

    Cheers,
    _

  11. #11
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: OpenGL Interface

    Quote Originally Posted by anda_skoa View Post
    I assumed you already had that. How did you get the window to show up if you can't even build the program?
    I started a new program as a console application, that's why the .PRO file was wrong, totally forgot to ammend it in the new program (have been away from programming for a while), thanks for reminding me. The V1.0 had a correct .PRO file I just didn't post it in my initial posts.

    Quote Originally Posted by anda_skoa View Post
    Why would you need that?
    Still trying to figure it out how to get a glwidget to show up, but at least I got this code to work:

    WidgetTest.pro
    Qt Code:
    1. QT += core gui
    2.  
    3. TARGET = WidgetTest
    4.  
    5. TEMPLATE = app
    6.  
    7. SOURCES += main.cpp \
    8. mywidget.cpp
    9.  
    10. HEADERS += \
    11. mywidget.h
    To copy to clipboard, switch view to plain text mode 

    mywidget.h
    Qt Code:
    1. #ifndef MYWIDGET_H
    2. #define MYWIDGET_H
    3.  
    4. #include <QWidget>
    5.  
    6. class MyWidget : public QWidget
    7. {
    8. Q_OBJECT
    9. public:
    10. explicit MyWidget(QWidget *parent = 0);
    11. ~MyWidget();
    12.  
    13. protected:
    14. virtual void mousePressEvent( QMouseEvent *e );
    15. virtual void mouseMoveEvent( QMouseEvent *e );
    16. virtual void mouseReleaseEvent( QMouseEvent *e );
    17.  
    18. private:
    19. bool _mousePressed;
    20. QPoint _mousePosition;
    21. };
    22.  
    23. #endif // MYWIDGET_H
    To copy to clipboard, switch view to plain text mode 

    mywidget.cpp
    Qt Code:
    1. #include "mywidget.h"
    2.  
    3. MyWidget::MyWidget(QWidget *parent) : QWidget(parent), _mousePressed(false), _mousePosition(QPoint())
    4. {
    5. setWindowFlags( Qt::FramelessWindowHint );
    6. }
    7.  
    8. void MyWidget::mousePressEvent( QMouseEvent *e )
    9. {
    10. /*
    11.   if ( e->button() == Qt::LeftButton ) {
    12.   _mousePressed = true;
    13.   _mousePosition = e->pos();
    14.   }*/
    15. }
    16.  
    17. void MyWidget::mouseMoveEvent( QMouseEvent *e )
    18. {
    19. /*if ( _mousePressed ) {
    20.   move( mapToParent( e->pos() - _mousePosition ) );
    21.   }*/
    22. }
    23.  
    24. void MyWidget::mouseReleaseEvent( QMouseEvent *e )
    25. {
    26. /*if ( e->button() == Qt::LeftButton ) {
    27.   _mousePressed = false;
    28.   _mousePosition = QPoint();
    29.   }
    30.   */
    31. }
    32.  
    33. MyWidget::~MyWidget()
    34. {
    35. // delete stuff.
    36. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mywidget.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7.  
    8. MyWidget myWidget;
    9. myWidget.show();
    10.  
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    My problem was that I created the new project as a console app and it used QCoreApplication rather than QApplication, so the main.cpp had the incorrect statement:

    Qt Code:
    1. QCoreApplication a(argc, argv);
    To copy to clipboard, switch view to plain text mode 

    Now I get a grey window as I wanted . Now I just need to figure out how to get my opengl window to show up.

    I'm getting this error that wysota pointed out in this thread:

    http://www.qtcentre.org/archive/index.php/t-45162.html

    If I create a borderless opengl window, for some reason it doesn't show up, there is an application running, just nothing showing the moment I have:

    Qt Code:
    1. GLWidget::GLWidget(QGLWidget *parent) : QGLWidget(parent)
    2. {
    3. this->setWindowFlags(Qt::FramelessWindowHint);
    4. }
    To copy to clipboard, switch view to plain text mode 

    So trying to figure out how to use setMask. Hmm! Kinda funny, started with a bordered QMainWindow with an openGl widget in the middle and now that I just have glWidget, it still pops up in a window... one less class but still... strange...

    Which makes me wonder, why does the grey box for the simple MyWidget pop up?
    Last edited by Atomic_Sheep; 15th October 2015 at 12:57.

Similar Threads

  1. Replies: 2
    Last Post: 5th July 2017, 13:28
  2. Replies: 0
    Last Post: 17th May 2015, 18:03
  3. converting GLUT/OpenGL to Qt/OpenGL - displaying issue
    By yoti13 in forum Qt Programming
    Replies: 1
    Last Post: 25th November 2012, 00:45
  4. Replies: 0
    Last Post: 6th December 2009, 00:41
  5. draw transparent buttons on top of an opengl graphicsview
    By billconan in forum Qt Programming
    Replies: 0
    Last Post: 7th November 2009, 20:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.