Unsolved Qt OpenGL Quad not showing
-
What my code is missing to display a quad?
i don't get any error just the widget display the clear color, in this case black
This is my current code;"MyOpenGLWidget.cpp"
#include "MyOpenGLWidget.h" #include "QOpenGLWidget" #include <QOpenGLFunctions> MyOpenGLWidget::MyOpenGLWidget(QWidget* parent) : QOpenGLWidget(parent) { qDebug("constructor"); } void MyOpenGLWidget::initializeGL() { qDebug("initialize"); initializeOpenGLFunctions(); glClearColor(0, 0, 0, 0); } void MyOpenGLWidget::paintGL() { qDebug("paint"); glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.0, 0.0, -10.0); glBegin(GL_QUADS); glColor3f(1, 0, 0); glVertex2f(-0.5f, -0.5f); glVertex2f(0.5f, -0.5f); glVertex2f(-0.5f, 0.5f); glVertex2f(0.5f, 0.5f); glEnd(); glFlush(); } void MyOpenGLWidget::resizeGL(int width, int height) { qDebug("resize"); }
"mainwindow.cpp"
#include "mainwindow.h" #include "ui_mainwindow.h" #include "MyOpenGLWidget.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; }
-
Hi and welcome to the forums
My best bet is that your openGL is so new that
glBegin(GL_QUADS); is no longer supported in the core profile/openGL 3.3 ( i think)
Its part of the so called old fixed pipeline.
It might be possible to request older profile but would be better just to use
modern openGl.
https://learnopengl.com/Introduction
https://learnopengl.com/Getting-started/Hello-Triangle