Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) QGLWidgetExample1

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppQGLWidgetExample1/CppQGLWidgetExample1.pro

 

exists(../../DesktopApplication.pri) {
  include(../../DesktopApplication.pri)
}
!exists(../../DesktopApplication.pri) {
  QT       += core gui
  greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

  win32 {
    greaterThan(QT_MAJOR_VERSION, 4): QT += svg
  }

  TEMPLATE = app

  CONFIG(debug, debug|release) {
    message(Debug mode)
  }

  CONFIG(release, debug|release) {
    message(Release mode)
    DEFINES += NDEBUG NTRACE_BILDERBIKKEL
  }

  QMAKE_CXXFLAGS += -std=c++1y -Wall -Wextra -Weffc++

  unix {
    QMAKE_CXXFLAGS += -Werror
  }
}

exists(../../Libraries/Boost.pri) {
  include(../../Libraries/Boost.pri)
}
!exists(../../Libraries/Boost.pri) {
  INCLUDEPATH += \
    ../../Libraries/boost_1_55_0
}

QT += opengl

SOURCES += main.cpp

 

 

 

 

 

./CppQGLWidgetExample1/main.cpp

 

#include <cassert>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include <QApplication>
#include <QGLWidget>
#pragma GCC diagnostic pop

struct MyWidget : public QGLWidget
{
  //Q_OBJECT

public:
  MyWidget(QWidget * const parent = nullptr) : QGLWidget(parent) {}

protected:
  void initializeGL()
  {
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glEnable(GL_DEPTH_TEST);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
  }
  void resizeGL(int width, int height )
  {
    glViewport(0, 0,width,height);
    glFrustum(-1.0,1.0,-1.0,1.0,-1.0,1.0);
  }
  void paintGL()
  {
    //glRotatef(...);
    //glMaterialfv(...);
    glBegin(GL_TRIANGLES);
      glVertex3f( 1.0, 0.0, 0.0);
      glVertex3f( 0.0, 1.0, 0.0);
      glVertex3f( 0.0, 0.0, 1.0);
    glEnd();
  }
};

int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  MyWidget * const widget = new MyWidget;
  widget->show();
  return a.exec();
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml