Python:pyglet学习(2)图形的旋转&batch
这次讲讲图形的旋转和批量渲染(rotate、batch)
1:图形旋转
先看看上次的代码中的一段:
glRotatef(rot_y, 0, 1, 0)
glRotatef(rot_z,0,0,1)
glRotatef(rot_x,1,0,0)
这就是旋转的代码,函数是glRotatef,第一个参数是旋转的角度,后三个中那个是1就转哪个(从左往右依次是x,y,z)
简化成一个函数:
def rotate(xdeg,ydeg,zdeg):
glRotatef(ydeg,0,1,0)
glRotatef(zdeg,0,0,1)
glRotatef(xdeg,1,0,0)
2:batch
还是看看官网:
Batched rendering
For optimal OpenGL performance, you should render as many vertex lists as possible in a single draw call. Internally, pyglet uses VertexDomain and IndexedVertexDomain to keep vertex lists that share the same attribute formats in adjacent areas of memory. The entire domain of vertex lists can then be drawn at once, without calling draw() on each individual list. It is quite difficult and tedious to write an application that manages vertex domains itself, though. In addition to maintaining a vertex domain for each set of attribute formats, domains must also be separated by primitive mode and required OpenGL state. The Batch class implements this functionality, grouping related vertex lists together and sorting by OpenGL state automatically. A batch is created with no arguments: batch = pyglet.graphics.Batch()
Vertex lists can now be created with the add() and add_indexed() methods instead of pyglet.graphics.vertex_list() and pyglet.graphics.vertex_list_indexed() functions. Unlike the module functions, these methods accept a mode parameter (the primitive mode) and a group parameter (described below). The two coloured points from previous pages can be added to a batch as a single vertex list with: vertex_list = batch.add(2, pyglet.gl.GL_POINTS, None,
('v2i', (10, 15, 30, 35)),
('c3B', (0, 0, 255, 0, 255, 0))
)
The resulting vertex_list can be modified as described in the previous section. However, instead of calling VertexList.draw to draw it, call Batch.draw() to draw all vertex lists contained in the batch at once: batch.draw()
For batches containing many vertex lists this gives a significant performance improvement over drawing individual vertex lists. To remove a vertex list from a batch, call VertexList.delete(). If you don’t need to modify or delete vertex lists after adding them to the batch, you can simply ignore the return value of the add() and add_indexed() methods.
之前绘制正方形的代码可以简化成(吗)
b=Batch()
b.add(1,GL_POLYGON,None,('v3i',(-5,-5,0,5,-5,0,5,5,0,-5,5,0))) b.draw()
然后。。。
Traceback (most recent call last):
File "D:\桌面\python\python程序\制作中\3d-2.py", line 14, in <module>
b.add(1,GL_POLYGON,None,('v3i',(-5,-5,0,5,-5,0,5,5,0,-5,5,0)))
File "C:\Users\steven\AppData\Local\Programs\Python\Python310-32\lib\site-packages\pyglet\graphics\__init__.py", line 371, in add vlist._set_attribute_data(i, array)
File "C:\Users\steven\AppData\Local\Programs\Python\Python310-32\lib\site-packages\pyglet\graphics\vertexdomain.py", line 447, in _set_attribute_data region.array[:] = data
ValueError: Can only assign sequence of same size
再看看官网:
Alternatively, the NV_primitive_restart extension can be used if it is present. This also permits use of GL_POLYGON, GL_LINE_LOOP and GL_TRIANGLE_FAN. Unfortunately the extension is not provided by older video drivers, and requires indexed vertex lists.
不能在Batch中使用GL_POLYGON, GL_LINE_LOOP,GL_TRIANGLE_FAN!
所以改为
b=pyglet.graphics.Batch()
b.add(8,GL_LINES,None,("v3i",dotlst[0][0]+dotlst[0][1]+dotlst[0][2]+dotlst[0][3]+dotlst[0][1]+dotlst[0][2]+dotlst[0][3]+dotlst[0][0])) b.draw()
但不能涂色了。这里的话,GL_LINES的参数是2n个坐标,表示A0->A1,A2->A3......
如果要涂色的话用三角形覆盖
Python:pyglet学习(2)图形的旋转&batch的更多相关文章
- 开始写下自己的python的cocos2d, pyglet学习
开始写下自己的python的cocos2d, pyglet学习 2014年01月18日 13:52:36 我要做程序达人 阅读数 9051更多 分类专栏: python的cocos2d和pyglet ...
- 以Tkinter模块来学习Python实现GUI(图形用户界面)编程
tk是什么:它是一个图形库,支持多个操作系统,使用tcl语言开发的.tkinter是Python内置的模块, 与tk类似的第三方图形库(GUI库)还有很多,比如:Qt,GTK,wxWidget,wxP ...
- 数百个 HTML5 例子学习 HT 图形组件 – WebGL 3D 篇
<数百个 HTML5 例子学习 HT 图形组件 – 拓扑图篇>一文让读者了解了 HT的 2D 拓扑图组件使用,本文将对 HT 的 3D 功能做个综合性的介绍,以便初学者可快速上手使用 HT ...
- 数百个 HTML5 例子学习 HT 图形组件 – 拓扑图篇
HT 是啥:Everything you need to create cutting-edge 2D and 3D visualization. 这口号是当年心目中的产品方向,接着就朝这个方向慢慢打 ...
- HTML5 例子学习 HT 图形组件
HTML5 例子学习 HT 图形组件 HT 是啥:Everything you need to create cutting-edge 2D and 3D visualization. 这口号是当年心 ...
- python爬虫学习视频资料免费送,用起来非常666
当我们浏览网页的时候,经常会看到像下面这些好看的图片,你是否想把这些图片保存下载下来. 我们最常规的做法就是通过鼠标右键,选择另存为.但有些图片点击鼠标右键的时候并没有另存为选项,或者你可以通过截图工 ...
- Python人工智能学习笔记
Python教程 Python 教程 Python 简介 Python 环境搭建 Python 中文编码 Python 基础语法 Python 变量类型 Python 运算符 Python 条件语句 ...
- 杨韬的Python/Jupyter学习笔记
Python语法学习 https://zhuanlan.zhihu.com/p/24162430 Python 安装库 安装Jupyter Notebook 先安装Python cmd 进入K:\Ju ...
- python高级学习目录
1. Linux介绍.命令1.1. 操作系统(科普章节) 1.2. 操作系统的发展史(科普章节) 1.3. 文件和目录 1.4. Ubuntu 图形界面入门 1.5. Linux 命令的基本使用 1. ...
随机推荐
- 简单实现支付密码输入框 By HL
密码输入框在微信,支付宝中比较常见 主要功能点 1.6位(或者N位)密码输入框封装
- 优化UITableViewCell高度计算的那些事 by --胡 xu
这篇总结你可以读到: UITableView高度计算和估算的机制 不同iOS系统在高度计算上的差异 iOS8 self-sizing cell UITableView+FDTemplateLayout ...
- 一个实用批处理指令制作过程分享:Perforce更新完后打开VisualStudio再编译
需求来源 笔者从事Unreal游戏客户端工作,使用VisualStudio开发,然后经常干一个事:就是使用Perforce(或svn)拉取最新代码,(一些时间后)拉取完之后然后打开 项目.sln,即V ...
- 7、前端--jQuery简介、基本选择器、基本筛选器、属性选择器、表单选择器、筛选器方法、节点操作、绑定事件
jQuery简介 宗旨:Write less, do more. 内部封装了js代码 是编程更加简单并且兼容所有的主流浏览器 版本:1.x 2.x 3.x # 可以使用3.x最新版 是第三方的类库:使 ...
- 03.python语法入门--注释、变量
注释 """多行注释加在整个py文件的开头用来对该py文件进行一个整体性的说明通常一个py中只有一个多行注释"""# 这是一行贼溜的代码p ...
- Solution -「ZJOI 2016」「洛谷 P3352」线段树
\(\mathcal{Descrtiption}\) 给定 \(\{a_n\}\),现进行 \(m\) 次操作,每次操作随机一个区间 \([l,r]\),令其中元素全部变为区间最大值.对于每个 \ ...
- Solution -「LOJ #138」「模板」类欧几里得算法
\(\mathcal{Description}\) Link. \(T\) 组询问,每次给出 \(n,a,b,c,k_1,k_2\),求 \[\sum_{x=0}^nx^{k_1}\left\ ...
- Solution -「CF 510E」Fox And Dinner
\(\mathcal{Description}\) Link. 给定正整数集合 \(\{a_n\}\),求一种把这些数放置在任意多个圆环上的方案,使得每个环的大小大于 \(2\) 且环上相邻两 ...
- [LeetCode]1313. 解压缩编码列表
给你一个以行程长度编码压缩的整数列表 nums . 考虑每对相邻的两个元素 [freq, val] = [nums[2i], nums[2i+1]] (其中 i >= 0 ),每一对都表示解压后 ...
- 【测试必备】k8s基本使用(更新中。。。)
测试为什么要学习容器技术及k8s k8s不是运维的专属技术 随着互联网技术的发展,架构也已经从单体架构发展到容器云( "微服务 + k8s" 完美结合) 很多人认为,k8s只是运维 ...