I am attempting to make a 3D rotating torus with lighting. The rotating torus works fine. The lighting is the problem; if I leave GL_SPECULAR
to its default, the light works fine. When I try to set it to a RGBA float quadruplet (what it is supposed to be) it says it is the incorrect format. 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. 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
).
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
):
glEnable(GL_COLOR_MATERIAL)
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
See also Basic OpenGL Lighting .
The instruction glLight(GL_LIGHT1,GL_SPECULAR,GL_POSITION)
doesn't make any sense at all. Read glLight
. eg:
glLightfv(GL_LIGHT1, GL_POSITION, [0, 100, 0, 0])
glLightfv(GL_LIGHT1, GL_DIFFUSE, [1, 0, 0, 1]) # red
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.