[PyOpenGL-Users] WGL.wglGetCurrentDC() crash
Brought to you by:
mcfletch
|
From: Prashant S. <ani...@ya...> - 2016-03-20 14:37:04
|
Hi,
Windows 7 x64Python 2.7.11 x64PyOpenGL 3.1.1b1
In a simple program attached here, I am getting crash while getting wglGetCurrentDC(). How ever it's working fine in an another simple program whereI'm drawing a simple glutSphere. It's printing a long but then program is getting crashed.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
from OpenGL.arrays import vbo
from OpenGL import platform as gl_platform
import numpy
import sys
width = 800
height = 600
num_particles = 10000
time_step = .005
mouse_down = False
mouse_old = {'x': 0., 'y': 0.}
rotate = {'x': 0., 'y': 0., 'z': 0.}
translate = {'x': 0., 'y': 0., 'z': 0.}
initial_translate = {'x': 0., 'y': 0., 'z': -2.5}
def glut_window():
glutInit(sys.argv)
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
glutInitWindowSize(width, height)
glutInitWindowPosition(0, 0)
window = glutCreateWindow("Particle Simulation")
glutDisplayFunc(on_display) # Called by GLUT every frame
glutKeyboardFunc(on_key)
glutMouseFunc(on_click)
glutMotionFunc(on_mouse_move)
glutTimerFunc(10, on_timer, 10) # Call draw every 30 ms
glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(60., width / float(height), .1, 1000.)
return(window)
def initial_buffers(num_particles):
np_position = numpy.ndarray((num_particles, 4), dtype=numpy.float32)
np_color = numpy.ndarray((num_particles, 4), dtype=numpy.float32)
np_velocity = numpy.ndarray((num_particles, 4), dtype=numpy.float32)
np_position[:,0] = numpy.sin(numpy.arange(0., num_particles) * 2.001 * numpy.pi / num_particles)
np_position[:,0] *= numpy.random.random_sample((num_particles,)) / 3. + .2
np_position[:,1] = numpy.cos(numpy.arange(0., num_particles) * 2.001 * numpy.pi / num_particles)
np_position[:,1] *= numpy.random.random_sample((num_particles,)) / 3. + .2
np_position[:,2] = 0.
np_position[:,3] = 1.
np_color[:,:] = [1.,1.,1.,1.] # White particles
np_velocity[:,0] = np_position[:,0] * 2.
np_velocity[:,1] = np_position[:,1] * 2.
np_velocity[:,2] = 3.
np_velocity[:,3] = numpy.random.random_sample((num_particles, ))
gl_position = vbo.VBO(data=np_position, usage=GL_DYNAMIC_DRAW, target=GL_ARRAY_BUFFER)
gl_position.bind()
gl_color = vbo.VBO(data=np_color, usage=GL_DYNAMIC_DRAW, target=GL_ARRAY_BUFFER)
gl_color.bind()
return (np_position, np_velocity, gl_position, gl_color)
def on_timer(t):
glutTimerFunc(t, on_timer, t)
glutPostRedisplay()
def on_key(*args):
if args[0] == '\033' or args[0] == 'q':
sys.exit()
def on_click(button, state, x, y):
mouse_old['x'] = x
mouse_old['y'] = y
def on_mouse_move(x, y):
rotate['x'] += (y - mouse_old['y']) * .2
rotate['y'] += (x - mouse_old['x']) * .2
mouse_old['x'] = x
mouse_old['y'] = y
def on_display():
"""Render the particles"""
glFlush()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
# Handle mouse transformations
glTranslatef(initial_translate['x'], initial_translate['y'], initial_translate['z'])
glRotatef(rotate['x'], 1, 0, 0)
glRotatef(rotate['y'], 0, 1, 0) #we switched around the axis so make this rotate_z
glTranslatef(translate['x'], translate['y'], translate['z'])
# Render the particles
glEnable(GL_POINT_SMOOTH)
glPointSize(1)
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
# Set up the VBOs
gl_color.bind()
glColorPointer(4, GL_FLOAT, 0, gl_color)
gl_position.bind()
glVertexPointer(4, GL_FLOAT, 0, gl_position)
glEnableClientState(GL_VERTEX_ARRAY)
glEnableClientState(GL_COLOR_ARRAY)
# Draw the VBOs
glDrawArrays(GL_POINTS, 0, num_particles)
glDisableClientState(GL_COLOR_ARRAY)
glDisableClientState(GL_VERTEX_ARRAY)
glDisable(GL_BLEND)
glutSwapBuffers()
window = glut_window()
(np_position, np_velocity, gl_position, gl_color) = initial_buffers(num_particles)
print gl_platform.GetCurrentContext()
from OpenGL import WGL
print WGL.wglGetCurrentDC()
glutMainLoop()
CheersPrashant
|