1 Star 1 Fork 0

Bruce / OpenGL_CV

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
opengl3.py 1.13 KB
一键复制 编辑 原始数据 按行查看 历史
Bruce 提交于 2023-12-04 03:11 . 测试粒子
import glfw
from OpenGL.GL import *
import numpy as np
# 控制点
control_points = np.array([
[-0.8, 0.0],
[-0.5, 1.0],
[0.5, 1.0],
[0.8, 0.0]
])
# 初始化glfw
glfw.init()
# 创建窗口
window = glfw.create_window(800, 600, "OpenGL Window", None, None)
if not window:
glfw.terminate()
raise Exception("Failed to create GLFW window")
# 设置窗口为当前上下文
glfw.make_context_current(window)
# 计算抛物线上的点
# 计算抛物线上的点
t_values = np.linspace(0, 1, 100)[:, np.newaxis] # 或者使用 t_values = np.linspace(0, 1, 100).reshape(-1, 1)
parabola_points = (1 - t_values)**2 * control_points[0] + 2 * (1 - t_values) * t_values * control_points[1] + t_values**2 * control_points[2]
# 主循环
while not glfw.window_should_close(window):
# 渲染
glClear(GL_COLOR_BUFFER_BIT)
# 绘制抛物线
glBegin(GL_LINE_STRIP)
glColor3f(1.0, 1.0, 1.0) # 设置颜色为白色
for point in parabola_points:
glVertex2f(point[0], point[1])
glEnd()
# 交换缓冲区并轮询事件
glfw.swap_buffers(window)
glfw.poll_events()
# 清理资源
glfw.terminate()
1
https://gitee.com/54993306/open-gl_-cv.git
git@gitee.com:54993306/open-gl_-cv.git
54993306
open-gl_-cv
OpenGL_CV
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891