Menu

#43 HANDLE type definition in WGL makes it incompatible with other GL modules

v3.0
open
nobody
wgl (1)
5
2017-09-02
2017-09-02
No

HANDLE type definition in WGL makes it incompatible with other GL modules

HANDLE = POINTER(None)
HANDLE.final = True

In particular glReadPixels starts to crash with "wrong argument type" after just importing OpenGL.WGL (below there is app to reproduce the bug)
so propose to chage definition of HANDLE type to fixed integer type depending on platform
on Win64 just type

HANDLE = UINT64

PyOpenGL package is
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl
PyOpenGL‑3.1.1‑cp27‑cp27m‑win_amd64.whl

OpenGL.version
3.1.1

# -*- coding: utf-8 -*-

# Just uncomment following line to reproduce the bug!
#import OpenGL.WGL

from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *

from PIL import Image
import sys

width, height = 300, 300

def init():
    glClearColor(0.5, 0.5, 0.5, 1.0)
    glColor(0.0, 1.0, 0.0)
    gluOrtho2D(-1.0, 1.0, -1.0, 1.0)
    glViewport(0, 0, width, height)

def render():

    glClear(GL_COLOR_BUFFER_BIT)

    glBegin(GL_LINES)
    glVertex2d(-0.5, -0.5)
    glVertex2d(0.5, 0.5)
    glEnd()

    glFlush()

def draw():
    render()
    glutSwapBuffers()

def main():
    glutInit(sys.argv)

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
    glutInitWindowSize(300, 300)
    glutCreateWindow(b"OpenGL vs WGL")

    init()
    render()

    glPixelStorei(GL_PACK_ALIGNMENT, 1)
    data = glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE)
    image = Image.frombytes("RGBA", (width, height), data)
    image.save('output.png', 'PNG')

    glutDisplayFunc(draw)
    glutMainLoop()

main()

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.