解释一下我做错了什么.我已经将3d模型加载到自编码的opengl渲染(v 3.3)并尝试使用顶点着色器使其像xray效果一样透明:
#version 330
attribute vec3 coord3d;
attribute vec2 texcoord;
varying vec2 f_texcoord;
uniform mat4 projectionMatrix;
uniform mat4 modelViewMatrix;
layout (location = 0) in vec3 inPosition;
layout (location = 1) in vec4 inColor;
smooth out vec4 theColor;
void main()
{
gl_Position = projectionMatrix*modelViewMatrix*vec4(inPosition, 1.0);
theColor = vec4(0.0,0.2,0.4,0.4);
f_texcoord = texcoord;
}
Run Code Online (Sandbox Code Playgroud)
该模型在编辑器中进行了三角测量并绘制:
glDrawArrays(GL_TRIANGLE_FAN, 0, (vertices.at(i)->size()/3));
Run Code Online (Sandbox Code Playgroud)
如果我使用
glEnable(GL_ALPHA_TEST);
glEnable( GL_BLEND );
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glEnable(GL_DEPTH_TEST);
glClearDepth(1.0);
Run Code Online (Sandbox Code Playgroud)
我看到一些不需要的三角形或线条:
如果我没有深度测试,我看到多个triangless内部面孔(我不想要):
如何摆脱不必要的影响并实施像Google Sketchup这样的X射线效果
如果我希望所有模型都透明,我应该实施深度排序吗?
我该如何实现这个:
根据docs, send() 函数:
\n\n\n\n\n“恢复执行,并将 \xe2\x80\x9csends\xe2\x80\x9d 一个值发送到生成器函数中。value 参数成为当前生成表达式的结果。send() 方法返回生成器生成的下一个值,或者如果生成器退出而没有产生另一个值,则引发 StopIteration。当调用 send() 来启动生成器时,必须使用 None 作为参数来调用它,因为没有可以接收该值的 Yield 表达式。
\n
但我不明白,为什么“值参数成为当前yield表达式的结果”在下面的例子中没有发生:
\n\ndef gen():\n yield 1\n x = (yield 42)\n print(x)\n yield 2\n\n>>>c=gen() #create generator\n>>>next(c) #prints \'1\' and stop execution, which is caused by yield 1\n>>>c.send(100) #prints \'42\', because \'The send() method returns the next value yielded by the generator\'\n>>>next(c) #prints \'None\' and \'2\'\n
Run Code Online (Sandbox Code Playgroud)\n\n那么为什么 x 变量保持“无”,尽管我通过 c.send(100) 向它发送了 100?看来,右侧的yield表达式分两步工作:首先,它将值返回给生成器的调用者,第二步,它返回生成器内发送函数的参数。如果在 send(42) 之前添加额外的 next(c) 我将得到预期的行为并且程序打印“100”。从文档中我不清楚为什么当我调用 send() 时这两个步骤不应同时发生。
\n