opengl pyqt 显示文字

目录

效果图


效果图

python 复制代码
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QOpenGLWidget

from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *

class OpenGLWidget(QOpenGLWidget):
    def __init__(self, parent=None):
        super(OpenGLWidget, self).__init__(parent)

    def initializeGL(self):
        glClearColor(0, 0, 0, 0)
        glEnable(GL_DEPTH_TEST)
        glutInit()

    def resizeGL(self, width, height):
        glViewport(0, 0, width, height)
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective(45, width / height, 1, 100)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

    def paintGL(self):
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()
        glTranslatef(-1.5, 0.0, -6)

        # 使用GLUT渲染数字
        glColor3f(1.0, 1.0, 1.0)  # 设置数字颜色
        glRasterPos2f(0, 0)  # 设置数字位置
        for char in "123":
            glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, ord(char))

class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setCentralWidget(OpenGLWidget(self))
        self.setWindowTitle("PyQt OpenGL Example")

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec_())
相关推荐
深蓝海拓2 分钟前
基于QtPy (PySide6) 的PLC-HMI工程项目(二)系统规划
笔记·python·qt·学习·plc
We་ct6 分钟前
LeetCode 295. 数据流的中位数:双堆解法实战解析
开发语言·前端·数据结构·算法·leetcode·typescript·数据流
迷藏49410 分钟前
**雾计算中的边缘智能:基于Python的轻量级任务调度系统设计与实现**在物联网(IoT)飞速发展的今天,传统云
java·开发语言·python·物联网
biubiubiu070615 分钟前
从 Python 和 Node.js 的流行看 Java 的真实位置
java·python·node.js
大鹏说大话19 分钟前
MySQL与PostgreSQL:底层架构差异与项目选型指南
开发语言
大江东去浪淘尽千古风流人物20 分钟前
【Basalt】Basalt void SqrtKeypointVioEstimator<Scalar_>::optimize() VIO优化流程
数据库·人工智能·python·机器学习·oracle
番茄去哪了38 分钟前
任务调度功能实现
java·开发语言·spring boot
CoberOJ_1 小时前
(2026-04-01更新)小白自己写,量化回测系统stock-quant(六)
python·ai·股票·量化·交易·回测·a股港股美股
qq_283720051 小时前
Python:time/datetime 模块教程
python·时间·模块·日期
Beginner x_u1 小时前
前端八股整理|JavaScript|高频小题 01
开发语言·前端·javascript