我在 RTD 上记录了一个 python 模块:http : //modernglextexttools.readthedocs.io
这是另一个模块的扩展,我想在两者之间建立联系。我希望参数和返回类型作为链接工作。这是一个例子。
我的conf.py
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.githubpages',
'sphinx.ext.intersphinx', # added this but does not help
'sphinxcontrib.napoleon'
]
Run Code Online (Sandbox Code Playgroud)
以下是链接外部类的方法示例。外部类是ModernGL.Context. 我不确定是否必须配置此类的记录位置。但它应该指向这个链接。
def load(filename, convert=None, ctx=None) -> ModernGL.Texture:
'''
Load a texture. If ctx is ``None`` the default_context is used.
Args:
filename (str): The name of the file to load.
Keyword Args:
convert (str): Convert the texture before loading. Possible values are: ('L', 'RGB', 'RGBA')
ctx …Run Code Online (Sandbox Code Playgroud) 我有 2 个 FBO 之一,我一直在用它在 glsl 中进行一些计算,我需要将纹理数据(dtype='f4')读回一个 numpy 数组以进行进一步计算。我在文档中没有找到任何解释如何执行此操作的内容。有什么帮助吗?
我用这个创建纹理
self.texturePing = self.ctx.texture( (width, height), 4, dtype='f4')
self.texturePong = self.ctx.texture( (width, height), 4, dtype='f4')
Run Code Online (Sandbox Code Playgroud)
我像这样处理它们:
def render(self, time, frame_time):
self.line_texture.use(0)
self.transform['lineImg'].value = 0
for _ in range (2):
self.fbo2.use()
self.texturePing.use(1)
self.transform['prevData'].value = 1
self.process_vao.render(moderngl.TRIANGLE_STRIP)
#this rendered to texturePong
self.fbo1.use() #texture Ping
self.texturePong.use(1)
self.transform['prevData'].value = 1
self.process_vao.render(moderngl.TRIANGLE_STRIP)
#stop drawing to the fbo and draw to the screen
self.ctx.screen.use()
self.ctx.clear(1.0, 1.0, 1.0, 0.0) #might be unnecessary
#tell the canvas to use this …Run Code Online (Sandbox Code Playgroud) 当没有抗锯齿 ( samples=0) 时,此代码会呈现一个彩色三角形。但是当我打开抗锯齿 ( samples=1...32) 时,它无法渲染任何内容。如何使其与抗锯齿一起使用?也许我无法直接从多重采样 fbos 或纹理中读取像素,但我不知道如何解决这个问题。
import numpy as np
from PIL import Image
import moderngl
ctx = moderngl.create_standalone_context(backend='egl')
fbo = ctx.framebuffer(
color_attachments=ctx.texture((512, 512), 4, samples=2),
depth_attachment=ctx.depth_texture((512, 512), samples=2)
)
fbo.use()
vertices = np.array([
-1.0, -1.0, 1.0, 0.0, 0.0,
1.0, -1.0, 0.0, 1.0, 0.0,
0.0, 1.0, 0.0, 0.0, 1.0],
dtype='f4',
)
prog = ctx.program(vertex_shader="""
#version 330
in vec2 in_vert;
in vec3 in_color;
out vec3 color;
void main() {
gl_Position = vec4(in_vert, 0.0, 1.0);
color = …Run Code Online (Sandbox Code Playgroud) 渲染这个立方体时,我使用moderngl DEPTH_TEST以正确的深度正确绘制面,效果很好,如图所示:
但是,我想让立方体透明。给它一个稍微透明的纹理后,它的渲染如下:
由于某种原因,立方体正面后面的部分被忽略,导致它只是被染成红色。
这是旋转时的样子:
有些角度有效,有些则无效。
当我禁用深度测试时,所有内容都会正确呈现,但顺序错误。有没有什么办法解决这一问题?(使用Python Moderngl)