Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pyopengl黑屏_Python_Opengl_Pyopengl_Opengl Compat - Fatal编程技术网

Python Pyopengl黑屏

Python Pyopengl黑屏,python,opengl,pyopengl,opengl-compat,Python,Opengl,Pyopengl,Opengl Compat,在支持OpenGL 3.1的GPU上运行时,Pyopengl 3.1.5(Python 3.8和Windows10 Pro-64位)窗口显示一个黑屏 示例代码中缺少一些内容。 1.没有为fragcolor指定颜色。 2.整数值作为输入提供给glVetex2f(),而不是浮点数。 在纠正上述问题并运行代码时,屏幕仍为黑色。 #剧本 在中,缺少Mvp(模型视图投影)矩阵的代码。将其添加到ShowScreen()函数下时,绘制调用(本例中为方形)将在视口中渲染 import OpenGL from

在支持OpenGL 3.1的GPU上运行时,Pyopengl 3.1.5(Python 3.8和Windows10 Pro-64位)窗口显示一个黑屏

示例代码中缺少一些内容。
1.没有为fragcolor指定颜色。
2.整数值作为输入提供给
glVetex2f()
,而不是浮点数。
在纠正上述问题并运行代码时,屏幕仍为黑色。

#剧本 在中,缺少Mvp(模型视图投影)矩阵的代码。将其添加到ShowScreen()函数下时,绘制调用(本例中为方形)将在视口中渲染

import OpenGL
from OpenGL.GL import *
from  OpenGL.GLUT import * 
from OpenGL.GLU import * 
import io
print("Imports successful!")

w, h = 500,500

def poly_shape():     
    glBegin(GL_QUADS) 
    glColor4f(1.0,0.0,0.0,1.0)
    glVertex2f(100.0, 100.0)
    glVertex2f(200.0, 100.0) 
    glVertex2f(200.0, 200.0) 
    glVertex2f(100.0, 200.0) 
    glEnd()

def showScreen():
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Remove everything from screen (i.e. displays all white)
    glLoadIdentity() # Reset all graphic/shape's position
    poly_shape() # Draw function call
    glutSwapBuffers()

#------
glutInit()
glutInitDisplayMode(GLUT_RGBA) # Set the display mode to be colored
glutInitWindowSize(500, 500)   # Set the w and h of your window
glutInitWindowPosition(0, 0)   # Set the position at which this windows should appear
wind = glutCreateWindow("OpenGL Coding Practice") # Set a window title
glutDisplayFunc(showScreen)
glutIdleFunc(showScreen) # Keeps the window open
glutMainLoop()  # Keeps the above created window displaying/running in a loop
import OpenGL
from OpenGL.GL import *
from  OpenGL.GLUT import * 
from OpenGL.GLU import * 
import io
print("Imports successful!")


w, h = 500,500


def draw_shape():
    glBegin(GL_QUADS) 
    glColor4f(1.0,0.0,0.0,1.0)
    glVertex2f(100.0, 100.0)
    glVertex2f(200.0, 100.0) 
    glVertex2f(200.0, 200.0) 
    glVertex2f(100.0, 200.0) 
    glEnd() 
    glFlush()

def showScreen():
    glViewport(0, 0, 500, 500)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    glOrtho(0, 500, 500, 0, -1, 1)
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Remove everything from screen (i.e. displays all white)
    glLoadIdentity() # Reset all graphic/shape's position

    draw_shape() # Draw function

    glutSwapBuffers()

#---Section 3---
glutInit()
glutInitDisplayMode(GLUT_RGBA) # Set the display mode to be colored
glutInitWindowSize(500, 500)   # Set the w and h of your window
glutInitWindowPosition(0, 0)   # Set the position at which this windows should appear
wind = glutCreateWindow("OpenGL Coding Practice") # Set a window title


glutDisplayFunc(showScreen)
glutIdleFunc(showScreen) # Keeps the window open
glutMainLoop()  # Keeps the above created window displaying/running in a loop*