#ifndef yC_GLES32_Window_H
#define yC_GLES32_Window_H
#include <QWindow>
#include <QOpenGLContext>

#include <QSurfaceFormat>
#include <iostream>
#include "core.h"

class Window : public QWindow {
public:
    QOpenGLContext *context;
    bool initialized;
    QSurfaceFormat format;
    Window() : context(nullptr), initialized(false) {
        format = GL::surface_format();
        setSurfaceType(OpenGLSurface);
        setFormat(format);

    }

    ~Window() override {
        delete context;
    }

    void exposeEvent(QExposeEvent *event) override {
        if (isExposed()) {
            if (!initialized) {
                context = GL::context_init(this, format);
                initialized = true;
            }
            context->makeCurrent(this);
            render();
            context->swapBuffers(this);
        }
    }

private:
    virtual void render() {
        // 在这里编写OpenGL ES渲染指令
        glClearColor(0.0f, 0.0f, 1.0f, 1.0f);  // 清除背景为蓝色
        glClear(GL_COLOR_BUFFER_BIT);  // 清空颜色缓冲
        // 更多OpenGL ES渲染指令...
    }
};


#endif