feat: set opengl format

This commit is contained in:
parker
2025-06-25 17:12:29 +01:00
parent 27da7177ae
commit bdfc5822ec
3 changed files with 23 additions and 11 deletions

View File

@@ -1,7 +1,8 @@
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <iostream>
#include <QOpenGLFunctions_3_2_Core>
class MyGLWidget : public QOpenGLWidget
class MyGLWidget : public QOpenGLWidget, protected QOpenGLFunctions_3_2_Core
{
public:
MyGLWidget(QWidget *parent) : QOpenGLWidget(parent) { }
@@ -11,24 +12,28 @@ protected:
void initializeGL() override
{
// Set up the rendering context, load shaders and other resources, etc.:
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
f->glClearColor(0.16f, 0.16f, 0.16f, 1.0f);
initializeOpenGLFunctions();
GLuint vao;
glGenVertexArrays(1,&vao);
glBindVertexArray(vao);
QSurfaceFormat fmt = context()->format();
std::cout << "format: " << (fmt.renderableType() == QSurfaceFormat::OpenGLES ? "GLES" : "Desktop") << "\n";
std::cout << "format: " << (fmt.renderableType() == QSurfaceFormat::OpenGL ? "true" : "false") << "\n";
glClearColor(0.16f, 0.16f, 0.16f, 1.0f);
}
void resizeGL(int w, int h) override
{
// // Update projection matrix and other size related settings:
// m_projection.setToIdentity();
// m_projection.perspective(45.0f, w / float(h), 0.01f, 100.0f);
}
void paintGL() override
{
// Draw the scene:
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
f->glClear(GL_COLOR_BUFFER_BIT);
initializeOpenGLFunctions();
glClear(GL_COLOR_BUFFER_BIT);
}
};