Created
March 26, 2016 15:07
-
-
Save seanlynch/f85846283fc712fd91ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from OpenGL.arrays import vbo | |
from OpenGL.GL import * | |
from OpenGL.GLU import * | |
from OpenGL.GLUT import * | |
import pyopencl as cl | |
from pyopencl.tools import get_gl_sharing_context_properties | |
import numpy | |
MF = cl.mem_flags | |
def draw(): | |
glClear(GL_COLOR_BUFFER_BIT) | |
glLoadIdentity() | |
glBegin(GL_TRIANGLES) | |
glVertex2f(0, 0) | |
glVertex2f(window.width, 0) | |
glVertex2f(window.width, window.height) | |
glEnd() | |
def main(): | |
width = height = 256 | |
glutInit(sys.argv) | |
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) | |
glutInitWindowSize(width, height) | |
glutInitWindowPosition(0, 0) | |
win = glutCreateWindow("Foo") | |
#gets called by GLUT every frame | |
glutDisplayFunc(draw) | |
# #handle user input | |
# glutKeyboardFunc(self.on_key) | |
# glutMouseFunc(self.on_click) | |
# glutMotionFunc(self.on_mouse_motion) | |
# #this will call draw every 30 ms | |
# glutTimerFunc(30, self.timer, 30) | |
glViewport(0, 0, width, height) | |
glMatrixMode(GL_PROJECTION) | |
glLoadIdentity() | |
gluPerspective(60., width / float(height), .1, 1000.) | |
glMatrixMode(GL_MODELVIEW) | |
noise = numpy.zeros((width, height), numpy.uint8) | |
noise_vbo = vbo.VBO(data=noise, usage=GL_DYNAMIC_DRAW, target=GL_ARRAY_BUFFER) | |
noise_vbo.bind() | |
plats = cl.get_platforms() | |
ctx = cl.Context(properties=[ | |
(cl.context_properties.PLATFORM, plats[0])] | |
+ get_gl_sharing_context_properties()) | |
queue = cl.CommandQueue(ctx) | |
noise_cl = cl.GLBuffer(ctx, MF.READ_WRITE, int(noise_vbo.buffers[0])) | |
#print(noise_cl) | |
#glutMainLoop() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment