[英]PyOpenGL Lighting Color Format Issue
I am attempting to make a 3D rotating torus with lighting.我正在尝试制作带照明的 3D 旋转圆环。 The rotating torus works fine.
旋转环面工作正常。 The lighting is the problem;
照明是问题; if I leave
GL_SPECULAR
to its default, the light works fine.如果我将
GL_SPECULAR
保留为默认值,则灯可以正常工作。 When I try to set it to a RGBA float quadruplet (what it is supposed to be) it says it is the incorrect format.当我尝试将其设置为 RGBA 浮点四联体(它应该是什么)时,它说它的格式不正确。 I tried to print the actual default value of
GL_SPECULAR
using print(str(int(GL_SPECULAR)))
it returns the float 4611.0, and I can not find any information on this type of color format.我尝试使用
print(str(int(GL_SPECULAR)))
GL_SPECULAR
的实际默认值,它返回浮点数 4611.0,但我找不到关于这种颜色格式的任何信息。 Here is my code:这是我的代码:
from OpenGL.GLU import *
from OpenGL.GL import *
glutInit()
GL_SPECULAR=(0.0,0.0,1.0,1.0)
def display():
glClearColor(1,1,1,1)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT1)
glEnable(GL_DEPTH_TEST)
glLight(GL_LIGHT1,GL_SPECULAR,GL_POSITION)
glutSolidTorus(0.3,0.5,10,10)
glRotatef(1,1,1,0)
glutSwapBuffers()
glutPostRedisplay()
def main():
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA)
glutCreateWindow('window')
glutDisplayFunc(display)
glutMainLoop()
if __name__=='__main__':
main()
Error:错误:
Traceback (most recent call last):
File "C:\Users\trian\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\OpenGL\GLUT\special.py", line 130, in safeCall
return function( *args, **named )
File "c:\Users\trian\python\glut.py", line 15, in display
glLight(GL_LIGHT1,GL_SPECULAR,GL_POSITION)
File "src\latebind.pyx", line 39, in OpenGL_accelerate.latebind.LateBind.__call__
File "src\wrapper.pyx", line 314, in OpenGL_accelerate.wrapper.Wrapper.__call__
File "src\wrapper.pyx", line 311, in OpenGL_accelerate.wrapper.Wrapper.__call__
File "C:\Users\trian\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\OpenGL\platform\baseplatform.py", line 415, in __call__
return self( *args, **named )
ctypes.ArgumentError: ("argument 2: <class 'TypeError'>: wrong type", (GL_LIGHT1, (0.0, 0.0, 1.0, 1.0), c_float(4611.0)))
GLUT Display callback <function display at 0x000001EBCB08E820> with (),{} failed: returning None ("argument 2: <class 'TypeError'>: wrong type", (GL_LIGHT1, (0.0, 0.0, 1.0, 1.0), c_float(4611.0)))
PS C:\Users\trian\python>
When lighting ( GL_LIGHTING
) is enabled, then the color which is associated, is taken from the material parameters ( glMaterial
).启用照明 (
GL_LIGHTING
) 时,关联的颜色取自材质参数 ( glMaterial
)。
If you still want to use the current color attribute (which is set by glColor
), then you have to enable GL_COLOR_MATERIAL
and to set the color material paramters ( glColorMaterial
):如果您仍想使用当前颜色属性(由
glColor
设置),则必须启用GL_COLOR_MATERIAL
并设置颜色材料参数( glColorMaterial
):
glEnable(GL_COLOR_MATERIAL)
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
See also Basic OpenGL Lighting .另请参阅基本 OpenGL 照明。
The instruction glLight(GL_LIGHT1,GL_SPECULAR,GL_POSITION)
doesn't make any sense at all.指令
glLight(GL_LIGHT1,GL_SPECULAR,GL_POSITION)
根本没有任何意义。 Read glLight
.阅读
glLight
。 eg:例如:
glLightfv(GL_LIGHT1, GL_POSITION, [0, 100, 0, 0])
glLightfv(GL_LIGHT1, GL_DIFFUSE, [1, 0, 0, 1]) # red
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.