Pyopengl Blackscreen - PullRequest
       130

Pyopengl Blackscreen

0 голосов
/ 29 апреля 2020

При запуске этого примера кода на графическом процессоре с поддержкой OpenGL 3.1 в окне Pyopengl 3.1.5 (Python 3.8 & Windows10 Pro-64bit) отображается Черный экран .

В примере кода не хватает нескольких вещей.
1. Цвет не задан для fragcolor.
2. Целочисленные значения предоставляются в качестве входных данных для glVetex2f() вместо чисел с плавающей запятой.
После устранения вышеуказанных проблем и запуска кода, экран все еще черный.

# Script
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

1 Ответ

0 голосов
/ 30 апреля 2020

В примере кода код для матрицы Mvp (Model-View-Projection) отсутствовал. При добавлении его в функцию ShowScreen () вызов рисования (в данном случае квадратный) выполняет рендеринг в окно просмотра.

Screen rendering with Immediate Mode glsl script

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*
...