def get_input(get_what): textInput = '' gl.glClearColor(0,0,0,1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) stim_display.refresh() simple_wait(0.500) my_text = get_what+textInput drawText( my_text , instruction_font , stim_display_res[0] , xLoc=stim_display_res[0]/2 , yLoc=stim_display_res[1]/2 , fg=[200,200,200,255] ) stim_display.refresh() done = False while not done: if not stamper_child.qFrom.empty(): event = stamper_child.qFrom.get() if event['type'] == 'key' : response = event['value'] if response=='q': exit_safely() elif response == 'backspace': if textInput!='': textInput = textInput[0:(len(textInput)-1)] my_text = get_what+textInput drawText( my_text , instruction_font , stim_display_res[0] , xLoc=stim_display_res[0]/2 , yLoc=stim_display_res[1]/2 , fg=[200,200,200,255] ) stim_display.refresh() elif response == 'return': done = True else: textInput = textInput + response my_text = get_what+textInput drawText( my_text , instruction_font , stim_display_res[0] , xLoc=stim_display_res[0]/2 , yLoc=stim_display_res[1]/2 , fg=[200,200,200,255] ) stim_display.refresh() stim_display.refresh() return textInput
def expose_cb(self,w,ev): style=self.get_style() gc=style.bg_gc[gtk.STATE_NORMAL] left,top,width,height=self.get_allocation() gldrawable = self.get_gl_drawable() glcontext = self.get_gl_context() gldrawable.gl_begin(glcontext) GL.glClearColor(1, 1, 1, 0) GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) GL.glViewport(0,0,width,height) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluPerspective(23, width/height, 5, 20) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity() self.drawit() if gldrawable.is_double_buffered(): gldrawable.swap_buffers() else: glFlush() gldrawable.gl_end()
def render(): while True: gl.glClearColor(0, 0.3, 0, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glLoadIdentity() renderer.draw(step, layout) yield None
def on_display( ): global shader gl.glClearColor(1,1,1,1) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glActiveTexture(gl.GL_TEXTURE0) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glEnable(gl.GL_BLEND) gl.glColor(0,0,0,1) shader.bind() radius = 255.0 theta, dtheta = 0, 5.5/180.0*math.pi support = 0.75 thickness = 1.0 for i in range(500): x = 256+radius*math.cos(theta); y = 32+256+radius*math.sin(theta); r = 10.1-i*0.02 circle( (x,y,r), thickness=thickness, support=support ) radius -= 0.45 theta += dtheta for i in range(0,39): r = 4 thickness = (i+1)/10.0 x = 20+i*12.5 - r y = 16 circle( (x,y,r), thickness=thickness, support=support ) glut.glutSwapBuffers( )
def render(self): viewport = GL.glGetIntegerv(GL.GL_VIEWPORT) width = viewport[2] height = viewport[3] # Render the widget using a separate viewport side = min(width, height) GL.glViewport((width - side) / 2, (height - side) / 2, side, side) GL.glClearColor(*self.trolltechPurple.darker().getRgbF()) GL.glShadeModel(GL.GL_FLAT) GL.glEnable(GL.GL_DEPTH_TEST) #GL.glEnable(GL.GL_CULL_FACE) GL.glTranslatef(0.0, 0.0, -10.0) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GL.glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) GL.glLoadIdentity() GL.glTranslated(0.0, 0.0, -10.0) GL.glRotated(self.xRot / 16.0, 1.0, 0.0, 0.0) GL.glRotated(self.yRot / 16.0, 0.0, 1.0, 0.0) GL.glRotated(self.zRot / 16.0, 0.0, 0.0, 1.0) self.threed_object.render() # reset the viewport GL.glViewport(*viewport)
def gl_init( width, height ): global __legocaptex,__quadratic setviewport(width, height) __legocaptex = layer_manager.load_2d_texture(pygame.image.tostring(__image, "RGBA"), LEGO_CAP_WIDTH, LEGO_CAP_HEIGHT) __quadratic = GLU.gluNewQuadric() GLU.gluQuadricTexture(__quadratic, GLU.GLU_TRUE) GLU.gluQuadricDrawStyle(__quadratic,GLU.GLU_FILL) GLU.gluQuadricOrientation(__quadratic, GLU.GLU_OUTSIDE) GLU.gluQuadricNormals(__quadratic, GLU.GLU_SMOOTH) GL.glClearColor( 0.0, 0.2, 0.5, 1.0 ) GL.glEnable(GL.GL_POINT_SMOOTH) GL.glEnable(GL.GL_LINE_SMOOTH) GL.glEnable(GL.GL_TEXTURE_2D) GL.glEnable(GL.GL_ALPHA_TEST) GL.glEnable(GL.GL_COLOR_MATERIAL) GL.glDisable(GL.GL_CULL_FACE) GL.glAlphaFunc(GL.GL_GREATER,0.1) GL.glClearAccum(0.0, 0.0, 0.0, 1.0) GL.glClear(GL.GL_ACCUM_BUFFER_BIT) #GL.glGenLists(1) draw_mode_3d()
def __init__(self, lnkpath=None): self.logger = logging.getLogger(logger.name + "." + type(self).__name__) self.zoom = -7.0 # distance to camera (zoom) self.textures = [] self.rd = [1.9, 0.0, -0.5] # right delta self.ld = [-1.9, 0.0, -0.5] # left delta self.t = 0 # for transitions between images self.s = 0 # for transitions between images self.ndx = 0 # start by showing the first image self._lastgame = None self.lnkpath = lnkpath self.lastgamepath = os.path.join(self.lnkpath, ".lastgame") self.gamelist = self.get_gamelist() self.logger.debug("Init CoverFlow with %d games" % self.gamecount()) # opengl stuff gl.glEnable(gl.GL_TEXTURE_2D) self.load_textures() gl.glShadeModel(gl.GL_SMOOTH) gl.glClearColor(0.0, 0.0, 0.0, 0.0) gl.glClearDepth(1.0) gl.glEnable(gl.GL_DEPTH_TEST) gl.glDepthFunc(gl.GL_LEQUAL) gl.glHint(gl.GL_PERSPECTIVE_CORRECTION_HINT, gl.GL_NICEST) gl.glEnable(gl.GL_LIGHT1)
def InitialiseOpenGL( self, width, height ) : # Initialise the trackball self.trackball = mtk.Trackball() self.trackball.Initialise( width, height ) # Default background color gl.glClearColor( 1, 1, 1, 1 ) # Enable depth test gl.glEnable( gl.GL_DEPTH_TEST ) # Enable face culling gl.glEnable( gl.GL_CULL_FACE ) # Enable blending function gl.glEnable( gl.GL_BLEND ) gl.glBlendFunc( gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA ) # Enable multisampling (antialiasing) gl.glEnable( gl.GL_MULTISAMPLE ) # Initialise the projection transformation matrix self.SetProjectionMatrix( width, height ) # Initialise Model-View transformation matrix self.modelview_matrix = np.identity( 4, dtype=np.float32 ) # Position the scene (camera) self.modelview_matrix[3,2] = -30.0 # Load the shaders self.flat_shader = mtk.FlatShader() self.smooth_shader = mtk.SmoothShader() self.shader = self.smooth_shader # Initialise viewing parameters self.wireframe_mode = 0 self.element_number = 0 self.color_enabled = False self.antialiasing = True
def drawSelf(self): color = self.sceneNode.clearColor if color is None: GL.glClear(GL.GL_DEPTH_BUFFER_BIT) else: GL.glClearColor(*color) GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
def initializeGL(self): """Initialize OpenGL, VBOs, upload data on the GPU, etc.""" # First check for supported GL version gl_version = float(gl.glGetString(gl.GL_VERSION)[:3]) if gl_version < 3.3: return # background color gl.glClearColor(0, 0, 0, 0) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) self.globaldata = ndUBO() try: # Compile shaders and link color shader program self.color_shader = BlueSkyProgram('data/graphics/shaders/nd-normal.vert', 'data/graphics/shaders/nd-color.frag') self.color_shader.bind_uniform_buffer('global_data', self.globaldata) # Compile shaders and link text shader program self.text_shader = BlueSkyProgram('data/graphics/shaders/nd-text.vert', 'data/graphics/shaders/nd-text.frag') self.text_shader.bind_uniform_buffer('global_data', self.globaldata) except RuntimeError as e: qCritical('Error compiling shaders in radarwidget: ' + e.args[0]) return # Set initial zoom self.globaldata.set_zoom(4.0) self.create_objects()
def glinit(self,mode=None): if mode: self.rendermode = mode GL.glClearColor(*colors.RGBA(self.bgcolor))# Clear The Background Color GL.glClearDepth(1.0) # Enables Clearing Of The Depth Buffer GL.glDepthFunc(GL.GL_LESS) # The Type Of Depth Test To Do GL.glEnable(GL.GL_DEPTH_TEST) # Enables Depth Testing if self.rendermode == 'wireframe': GL.glShadeModel(GL.GL_FLAT) # Enables Flat Color Shading GL.glDisable(GL.GL_LIGHTING) elif self.rendermode == 'flat': GL.glShadeModel(GL.GL_FLAT) # Enables Flat Color Shading GL.glDisable(GL.GL_LIGHTING) elif self.rendermode == 'smooth': GL.glShadeModel(GL.GL_SMOOTH) # Enables Smooth Color Shading GL.glEnable(GL.GL_LIGHTING) for l,i in zip(['light0','light1'],[GL.GL_LIGHT0,GL.GL_LIGHT1]): key = 'render/%s' % l light = GD.cfg.get(key,self.default_light) GD.debug(" set up %s %s" % (l,light)) GL.glLightModel(GL.GL_LIGHT_MODEL_AMBIENT,rgba(GD.cfg['render/ambient'])) GL.glLightModel(GL.GL_LIGHT_MODEL_TWO_SIDE, GL.GL_TRUE) GL.glLightModel(GL.GL_LIGHT_MODEL_LOCAL_VIEWER, 0) GL.glLightfv(i,GL.GL_AMBIENT,rgba(light['ambient'])) GL.glLightfv(i,GL.GL_DIFFUSE,rgba(light['diffuse'])) GL.glLightfv(i,GL.GL_SPECULAR,rgba(light['specular'])) GL.glLightfv(i,GL.GL_POSITION,rgba(light['position'])) GL.glEnable(i) GL.glMaterialfv(GL.GL_FRONT_AND_BACK,GL.GL_SPECULAR,rgba(GD.cfg['render/specular'])) GL.glMaterialfv(GL.GL_FRONT_AND_BACK,GL.GL_EMISSION,rgba(GD.cfg['render/emission'])) GL.glMaterialfv(GL.GL_FRONT_AND_BACK,GL.GL_SHININESS,GD.cfg['render/shininess']) GL.glColorMaterial(GL.GL_FRONT_AND_BACK,GL.GL_AMBIENT_AND_DIFFUSE) GL.glEnable(GL.GL_COLOR_MATERIAL) else: raise RuntimeError,"Unknown rendering mode"
def __init__(self, wid): """Constructor for OpenGLRenderingArea""" xlib = cdll.LoadLibrary('libX11.so') xlib.XOpenDisplay.argtypes = [c_char_p] xlib.XOpenDisplay.restype = POINTER(struct__XDisplay) self.xdisplay = xlib.XOpenDisplay((ctypes.c_char * 1)(*[0])) display = Display() attrs = [ GLX.GLX_RGBA, True, GLX.GLX_RED_SIZE, 1, GLX.GLX_GREEN_SIZE, 1, GLX.GLX_BLUE_SIZE, 1, GLX.GLX_DOUBLEBUFFER, 0, 0, 0 ] width = 200 height = 200 cattrs = (c_int * len(attrs))(*attrs) xvinfo = GLX.glXChooseVisual(self.xdisplay, display.get_default_screen(), cattrs) configs = GLX.glXChooseFBConfig(self.xdisplay, 0, None, byref(c_int())) self.context = GLX.glXCreateContext(self.xdisplay, xvinfo, None, True) self.x_window_id = GdkX11.X11Window.get_xid(wid) if not GLX.glXMakeCurrent(self.xdisplay, self.x_window_id, self.context): print("failed") GL.glViewport(0, 0, width, height) # todo self.app = None GL.glClearColor(0.24, 0.24, 0.24, 0.0) self.profiler_window = None
def initializeGL(self): # , width=1, height=1 """ Initialization of the GL frame. """ # TODO: glOrtho should set to size of the frame which would allow using # TODO: absolute coordinates in range/domain of original frame GL.glClearColor(0.0, 0.0, 0.0, 1.0) GL.glClearDepth(1.0) GL.glOrtho(0, 1, 1, 0, -1, 1) #glOrtho(0, width, height, 0, -1, 1) # DOESN'T WORK!! GL.glMatrixMode(GL.GL_PROJECTION) # Enable rational alpha blending GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) if self.anti_aliasing: # Points GL.glEnable(GL.GL_POINT_SMOOTH) GL.glHint(GL.GL_POINT_SMOOTH_HINT, GL.GL_NICEST) # Lines GL.glEnable(GL.GL_LINE_SMOOTH) GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST) # Polygons, but NOT GL_TRIANGLE_FAN GL.glEnable(GL.GL_POLYGON_SMOOTH) GL.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST) # Not sure... GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST)
def __clear_screen(self): ''' Clear screen, setup viewport ''' gl.glClearColor(0.05, 0.05, 0.1, 1.0) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT | gl.GL_STENCIL_BUFFER_BIT) gl.glViewport(0, 0, self.gui.window_width, self.gui.window_height)
def render(): gl.glPixelStorei(gl.GL_PACK_ALIGNMENT, 1) for i in range(10): gl.glClearColor(0, 0, 0, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) yield try: song_time = 0 while song_time < length: gl.glClearColor(0, 0, 0, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() gl.glOrtho(0, 1, height / float(width), 0, -1, 1) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() if v: v.draw(song_time, display, length) renderer.draw(song_time + headstart, layout) gl.glFinish() gl.glReadBuffer(gl.GL_BACK) data = gl.glReadPixelsub(0, 0, width, height, gl.GL_RGB) print "\r%.02f%%" % (100 * song_time / length), sys.stdout.flush() x264.stdin.write(data.tostring()) song_time += 1/fps #yield except Exception as e: print e finally: x264.stdin.close() x264.wait() os._exit(0)
def render(self): gl.glClearColor(0, 0, 0, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) with self.shader_prog: # Activate array gl.glBindVertexArray(self.vao_id) # FIXME: Why does the following work? tex_uniform is 1, # palette_uniform is 0, but I have to set the uniform for # tex_uniform to 0 and the uniform for palette_uniform to 1. # Obviously I'm not understanding something. # # See: http://stackoverflow.com/questions/26622204 # https://www.opengl.org/discussion_boards/showthread.php/174926-when-to-use-glActiveTexture # Activate texture print(self.tex_uniform, self.palette_uniform, self.sample_texture, self.palette_id) gl.glActiveTexture(gl.GL_TEXTURE0 + self.tex_uniform) gl.glBindTexture(gl.GL_TEXTURE_2D, self.sample_texture) gl.glUniform1i(self.tex_uniform, 0) # Activate palette texture gl.glActiveTexture(gl.GL_TEXTURE0 + self.palette_uniform) gl.glBindTexture(gl.GL_TEXTURE_BUFFER, self.palette_texture) gl.glTexBuffer(gl.GL_TEXTURE_BUFFER, gl.GL_RGBA8, self.palette_id) gl.glUniform1i(self.palette_uniform, 1) # # Activate array # gl.glBindVertexArray(self.vao_id) # draw triangle gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
def _on_paint(self, event): """ Respond to paint events. Initialize GL if this is the first paint event. Resize the view port if the width or height changed. Redraw the screen, calling the draw functions. """ if not self.IsShownOnScreen(): # Cannot realise a GL context on OS X if window is not yet shown return # create device context (needed on Windows, noop on X) dc = None if event.GetEventObject(): # Only create DC if paint triggered by WM message (for OS X) dc = wx.PaintDC(self) self.lock() self.SetCurrent(self._gl_ctx) # Real the explicit GL context # check if gl was initialized if not self._gl_init_flag: GL.glClearColor(*BACKGROUND_COLOR_SPEC) for fcn in self._init_fcns: fcn() self._gl_init_flag = True # check for a change in window size if self._resized_flag: self.width, self.height = self.GetSize() GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GL.glOrtho(0, self.width, self.height, 0, 1, 0) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity() GL.glViewport(0, 0, self.width, self.height) for cache in self._gl_caches: cache.changed(True) self._resized_flag = False # clear buffer if needed if self.clear_accum or not self.use_persistence: GL.glClear(GL.GL_COLOR_BUFFER_BIT) self.clear_accum=False # apply fading if self.use_persistence: GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) GL.glBegin(GL.GL_QUADS) GL.glColor4f(1,1,1,self.persist_alpha) GL.glVertex2f(0, self.height) GL.glVertex2f(self.width, self.height) GL.glVertex2f(self.width, 0) GL.glVertex2f(0, 0) GL.glEnd() GL.glDisable(GL.GL_BLEND) # draw functions for fcn in self._draw_fcns: fcn[1]() # show result self.SwapBuffers() self.unlock()
def render(): global shaderProgram global VAO global EBO global indexData GL.glClearColor(0, 0, 0, 1) GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) # active shader program GL.glUseProgram(shaderProgram) try: GL.glBindVertexArray(VAO) # Draw a triangle # GL.glDrawArrays(GL.GL_TRIANGLES, 0, 3) # draw triangle, starting index of the vertex array, # of vertices (6 = indexData.size), GL.glDrawElements(GL.GL_TRIANGLES, indexData.size, GL.GL_UNSIGNED_INT, None) finally: # Unbind when we finish GL.glBindVertexArray(0) GL.glUseProgram(0)
def display(): global offsetUniform, theProgram GL.glClearColor(0.0, 0.0, 0.0, 0.0) GL.glClear(GL.GL_COLOR_BUFFER_BIT) GL.glUseProgram(theProgram) GL.glUniform2f(offsetUniform, 0.5, 0.5) colorData = sizeOfFloat*len(vertexData)/2 GL.glBindBuffer(GL.GL_ARRAY_BUFFER, vertexBufferObject) positionLocation = GL.glGetAttribLocation(theProgram, 'position') colorLocation = GL.glGetAttribLocation(theProgram, 'color') GL.glEnableVertexAttribArray(positionLocation) GL.glVertexAttribPointer(positionLocation, 4, GL.GL_FLOAT, False, 0, null) GL.glEnableVertexAttribArray(colorLocation) GL.glVertexAttribPointer(colorLocation, 4, GL.GL_FLOAT, False, 0, c_void_p(colorData)) GL.glDrawArrays(GL.GL_TRIANGLES, 0, 36) GL.glDisableVertexAttribArray(positionLocation) GL.glDisableVertexAttribArray(colorLocation) GL.glUseProgram(0)
def initializeGL(self): """ Create the graphic buffers and compile the shaders. """ # Create and bind a new VAO (Vertex Array Object). self.vertex_array_object = gl.glGenVertexArrays(1) gl.glBindVertexArray(self.vertex_array_object) # Upload color values (one for each triangle vertex) in RGB format. colBuf = gl.glGenBuffers(1) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, colBuf) col = np.array([1,0,0,0,1,0,0,0,1], dtype=np.float32) gl.glBufferData(gl.GL_ARRAY_BUFFER, col, gl.GL_STATIC_DRAW) gl.glVertexAttribPointer(0, 3, gl.GL_FLOAT, gl.GL_FALSE, 0, None) gl.glEnableVertexAttribArray(0) # Create and bind GPU buffer for vertex data. self.vertexBuffer = gl.glGenBuffers(1) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.vertexBuffer) # Associate the vertex buffer with the "Layout 0" shader variable (look # for "v_N" variable in vertex shader program). gl.glVertexAttribPointer(1, 4, gl.GL_FLOAT, gl.GL_FALSE, 0, None) gl.glEnableVertexAttribArray(1) # Enable depth-sorting. gl.glEnable(gl.GL_DEPTH_TEST) gl.glDepthFunc(gl.GL_LESS) # Background color. gl.glClearColor(0, 0, 0, 0) # Compile- and install shader programs. self.shaders = self.linkShaders('blog4.vs', 'blog4.fs') gl.glUseProgram(self.shaders)
def main(): glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH) glut.glutInitWindowSize(400,400) glut.glutCreateWindow("teapot") gl.glClearColor(0.,0.,0.,1.) gl.glShadeModel(gl.GL_SMOOTH) gl.glEnable(gl.GL_CULL_FACE) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_LIGHTING) lightZeroPosition = [10.,4.,10.,1.] lightZeroColor = [0.8,1.0,0.8,1.0] #green tinged gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, lightZeroPosition) gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, lightZeroColor) gl.glLightf(gl.GL_LIGHT0, gl.GL_CONSTANT_ATTENUATION, 0.1) gl.glLightf(gl.GL_LIGHT0, gl.GL_LINEAR_ATTENUATION, 0.05) gl.glEnable(gl.GL_LIGHT0) glut.glutDisplayFunc(display) gl.glMatrixMode(gl.GL_PROJECTION) glu.gluPerspective(40.,1.,1.,40.) gl.glMatrixMode(gl.GL_MODELVIEW) glu.gluLookAt(0,0,10, 0,0,0, 0,1,0) gl.glPushMatrix() glut.glutMainLoop() return
def initgl(self): """Initialize OpenGL for use in the window.""" import OpenGL.GL as gl import OpenGL.GLU as glu self.load_textures() gl.glEnable(gl.GL_TEXTURE_2D) gl.glClearColor(0.0, 0.0, 0.0, 0.0) # This Will Clear The Background Color To Black gl.glClearDepth( 1.0) # Enables Clearing Of The Depth Buffer gl.glDepthFunc( gl.GL_LESS) # The Type Of Depth Test To Do gl.glEnable(gl.GL_DEPTH_TEST) # Enables Depth Testing gl.glShadeModel( gl.GL_SMOOTH) # Enables Smooth Color Shading gl.glMatrixMode(gl.GL_PROJECTION) gl.glLoadIdentity() # Reset The Projection Matrix # Calculate The Aspect Ratio Of The Window (width, height) = self.canvas.GetClientSize() glu.gluPerspective(45.0, float(width) / float(height), 0.1, 100.0) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT, (0.5, 0.5, 0.5, 1.0)) # Setup The Ambient Light gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, (1.0, 1.0, 1.0, 1.0)) # Setup The Diffuse Light gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, (0.0, 0.0, 2.0, 1.0)) # Position The Light gl.glEnable(gl.GL_LIGHT0)
def main(self): self.location = np.array([0.0,0.0,1500.0]) self.focus = np.array([0.0,0.0,0.0]) self.up = np.array([1.0,0.0,0.0]) self.mousex = 0 self.mousey = 0 self.mouse_drag = gl.GL_FALSE # Wire up GL glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_RGB | glut.GLUT_DOUBLE | glut.GLUT_DEPTH) glut.glutInitWindowSize(500,500) glut.glutInitWindowPosition(10,10) glut.glutCreateWindow("Laspy+OpenGL Pointcloud") glut.glutDisplayFunc(self.display) glut.glutReshapeFunc(self.reshape) glut.glutMouseFunc(self.mouse) glut.glutMotionFunc(self.mouse_motion) glut.glutKeyboardFunc(self.keyboard) gl.glClearColor(0.0,0.0,0.0,1.0) glut.glutTimerFunc(10,self.timerEvent,1) glut.glutMainLoop() return 0
def drawBackground(self, painter, rect) : super(BlobViewScene, self).drawBackground(painter,rect) height = float(painter.device().height()) width = float(painter.device().width()) painter.beginNativePainting() self.setStates() GL.glClearColor(0.0, 0.0, 0.0, 0.0) GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) GL.glMatrixMode(GL.GL_PROJECTION) GLU.gluPerspective(60.0, width / height, 0.01, 450.0); GLU.gluLookAt(-self._distance,0,0,0,0,0,0,0,1); GL.glMatrixMode(GL.GL_MODELVIEW); view = QtGui.QMatrix4x4() view.rotate(self._trackballs[2].rotation()) # view = np.array(list(view.data())).reshape((4,4)) # view[2, 3] -= 2.0 * math.exp(self._distance / 1200.0) # view = QtGui.QMatrix4x4(*view.reshape((16,))) GL.glLoadMatrixf(view.data()) self.drawAxis() # self.drawPoints() self.drawSphere() self.setDefaultState() painter.endNativePainting() self._frame+=1
def drawBackground(self, painter, rect): if not painter.paintEngine().type() == QtGui.QPaintEngine.OpenGL2: print painter.paintEngine().type() QtCore.qWarning('OpenGLScene: drawBackground needs a QGLWidget '\ +'to be set as viewport on the '\ +'graphics view') return painter.beginNativePainting() GL.glMatrixMode(GL.GL_PROJECTION) GL.glPushMatrix() GL.glMatrixMode(GL.GL_MODELVIEW) GL.glPushMatrix() GL.glClearColor(1.0,1.0,1.0,1.0) GL.glClear(GL.GL_COLOR_BUFFER_BIT) # OpenGL stuff goes here... GL.glMatrixMode(GL.GL_MODELVIEW) GL.glPopMatrix() GL.glMatrixMode(GL.GL_PROJECTION) GL.glPopMatrix() painter.endNativePainting()
def initializeGL(self): """Initialize OpenGL, VBOs, upload data on the GPU, etc. """ # background color gl.glClearColor(0,0,0,0) # create a Vertex Buffer Object with the specified data self.vbo = glvbo.VBO(self.data)
def initializeGL(self): """Initialize OpenGL, VBOs, upload data on the GPU, etc.""" # First check for supported GL version gl_version = float(gl.glGetString(gl.GL_VERSION)[:3]) if gl_version < 3.3: return # background color gl.glClearColor(0, 0, 0, 0) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) # self.mcp_data = mcpUBO() self.globaldata = ndUBO() self.mcp_col_shader = BlueSkyProgram('mcp.vert', 'color.frag') self.mcp_tex_shader = BlueSkyProgram('mcp.vert', 'texture.frag') self.mcp_txt_shader = BlueSkyProgram('mcp_text.vert', 'mcp_text.frag') self.color_shader = BlueSkyProgram('normal.vert', 'color.frag') self.text_shader = BlueSkyProgram('text.vert', 'text.frag') self.text_shader.bind_uniform_buffer('global_data', self.globaldata) self.create_objects() self.update_lcd()
def glInit(): OGLUT.glutInit() # initialize the GLUT library. OGLUT.glutInitDisplayMode(OGLUT.GLUT_DOUBLE | OGLUT.GLUT_RGB |OGLUT.GLUT_DEPTH) # initial display mode OGL.glShadeModel(OGL.GL_SMOOTH) # Enable Smooth Shading OGL.glClearColor(0.0, 0.0, 0.0, 0.0) # Black Background OGL.glClearDepth(1.0) # Depth Buffer Setup OGL.glEnable(OGL.GL_DEPTH_TEST) # Enables Depth Testing OGL.glDepthFunc(OGL.GL_LEQUAL) # The Type Of Depth Testing To Do OGL.glHint(OGL.GL_PERSPECTIVE_CORRECTION_HINT, OGL.GL_NICEST) # Really Nice Perspective Calculations objCamera.Position_Camera(10, 4, 12, 9, 4, 12, 0, 1, 0) # Set Camera Position LoadVertices() OGL.glViewport(0,0,SCREEN_SIZE[0],SCREEN_SIZE[1]) # Reset The Current Viewport OGL.glMatrixMode(OGL.GL_PROJECTION) OGL.glLoadIdentity() # Calculate The Aspect Ratio Of The Window OGLU.gluPerspective(45.0, SCREEN_SIZE[0]/SCREEN_SIZE[1], 0.1, 100.0) OGL.glMatrixMode(OGL.GL_MODELVIEW) OGL.glCullFace(OGL.GL_BACK) # Don't draw the back sides of polygons OGL.glEnable(OGL.GL_CULL_FACE) # Turn on culling
def paintEvent(self, event): self.makeCurrent() GL.glMatrixMode(GL.GL_PROJECTION) GL.glPushMatrix() GL.glShadeModel(GL.GL_SMOOTH) # for gradient rendering # GL.glDepthFunc(GL.GL_LESS) # The Type Of Depth Test To Do GL.glDisable(GL.GL_DEPTH_TEST) # we do 2D, we need no depth test ! GL.glMatrixMode(GL.GL_PROJECTION) # GL.glEnable(GL.GL_CULL_FACE) # Clear The Screen And The Depth Buffer GL.glClearColor(1, 1, 1, 0) GL.glClear(GL.GL_COLOR_BUFFER_BIT) # | GL.GL_DEPTH_BUFFER_BIT) # Reset The View self.setupViewport(self.width(), self.height()) self.drawBackground() self.drawGrid() self.drawDataQuads() self.drawRuler() self.drawBorder() # revert our changes for cooperation with QPainter GL.glShadeModel(GL.GL_FLAT) GL.glEnable(GL.GL_DEPTH_TEST) GL.glMatrixMode(GL.GL_PROJECTION) GL.glPopMatrix() painter = QtGui.QPainter(self) self.drawTrackerText(painter) painter.end()
def main(): global vertices2 global vertices pygame.init() screen = pygame.display.set_mode((512, 512), pygame.OPENGL | pygame.DOUBLEBUF) GL.glClearColor(0.5, 0.5, 0.5, 1.0) GL.glEnable(GL.GL_DEPTH_TEST) shader = OpenGL.GL.shaders.compileProgram( OpenGL.GL.shaders.compileShader(vertex_shader, GL.GL_VERTEX_SHADER), OpenGL.GL.shaders.compileShader(fragment_shader, GL.GL_FRAGMENT_SHADER)) shader2 = OpenGL.GL.shaders.compileProgram( OpenGL.GL.shaders.compileShader(vertex_shader, GL.GL_VERTEX_SHADER), OpenGL.GL.shaders.compileShader(fragment_shader2, GL.GL_FRAGMENT_SHADER)) shaders = [] shaders.append(shader) shaders.append(shader2) clock = pygame.time.Clock() while True: vertex_array_object = [] vertex_array_object.append(create_object(shader, vertices)) vertex_array_object.append(create_object(shader2, vertices2)) for event in pygame.event.get(): if event.type == pygame.QUIT: return if event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE: return display(shaders, vertex_array_object) # vertices[0] += 0.001 # vertices2[4] -= 0.001 pygame.display.flip()
def init(self): r,g,b,a=self.clear_color gl.glClearColor (r,g,b,a) gl.glEnable(self.enab_depth) gl.glShadeModel (self.shade_model) near,far=self.depth_range gl.glDepthRange(near,far) #default z mapping gl.glEnable(self.enab_light) gl.glEnable(self.enab_light0) #gl.glLightModeli(self.light_model,self.light_model_value) #gl.glLightModelfv(self.light_model,self.light_model_value) gl.glLightfv(self.enab_light0,gl.GL_POSITION, self.light0_position) gl.glLightfv(self.enab_light0,gl.GL_AMBIENT, self.light0_ambient) gl.glLightfv(self.enab_light0,gl.GL_DIFFUSE, self.light0_diffuse) gl.glLightfv(self.enab_light0,gl.GL_SPECULAR,self.light0_specular) #Load objects #self.objects() #!global plot #!plot=plots.Plot() self.plot.init()
def __init__(self, width=1024, height=1024): from OpenGL import EGL self.EGL = EGL self.display = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY) major = np.zeros(1, "i4") minor = np.zeros(1, "i4") EGL.eglInitialize(self.display, major, minor) num_configs = np.zeros(1, "i4") config = EGL.EGLConfig() # Now we create our necessary bits. config_attribs = np.array([ EGL.EGL_SURFACE_TYPE, EGL.EGL_PBUFFER_BIT, EGL.EGL_BLUE_SIZE, 8, EGL.EGL_GREEN_SIZE, 8, EGL.EGL_RED_SIZE, 8, EGL.EGL_DEPTH_SIZE, 8, EGL.EGL_RENDERABLE_TYPE, EGL.EGL_OPENGL_BIT, EGL.EGL_NONE, ], dtype="i4") self.config = EGL.eglChooseConfig(self.display, config_attribs, config, 1, num_configs) pbuffer_attribs = np.array([ EGL.EGL_WIDTH, width, EGL.EGL_HEIGHT, height, EGL.EGL_NONE ], dtype="i4") self.surface = EGL.eglCreatePbufferSurface(self.display, self.config, pbuffer_attribs) EGL.eglBindAPI(EGL.EGL_OPENGL_API) self.context = EGL.eglCreateContext(self.display, self.config, EGL.EGL_NO_CONTEXT, None) EGL.eglMakeCurrent(self.display, self.surface, self.surface, self.context) GL.glClearColor(0.0, 0.0, 0.0, 0.0) GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
def imgDraw3d(list_obj, winsize=(400, 300)): """ draw the input object into Numpy uint8 array obj -- the object to draw winsize -- the size of the window """ #### #### initialize window window = WindowGLFW(1.0, winsize=winsize, isVisible=False) #### set camera aabb3 = AABB3() for obj in list_obj: aabb3.add_minmax_xyz(obj.minmax_xyz()) window.wm.camera.adjust_scale_trans(aabb3.list_xyz()) #### initialize opengl setSomeLighting() gl.glEnable(gl.GL_POLYGON_OFFSET_FILL) gl.glPolygonOffset(1.1, 4.0) #### draw gl.glClearColor(1, 1, 1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) window.wm.camera.set_gl_camera() for obj in list_obj: obj.draw() gl.glFlush() #### read pixel to img gl.glPixelStorei(gl.GL_PACK_ALIGNMENT, 1) (buff_w, buff_h) = gl.glGetIntegerv(gl.GL_VIEWPORT)[2:] bytes_img = gl.glReadPixels(0, 0, buff_w, buff_h, gl.GL_RGB, gl.GL_UNSIGNED_BYTE) img = numpy.frombuffer(bytes_img, dtype=numpy.uint8) #### terminate window glfw.destroy_window(window.win) glfw.terminate() #### reshape the img array img = numpy.reshape(img, (buff_h, buff_w, 3)) return img
def paintGL(self): GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) GL.glLoadIdentity() GL.glTranslated(0.0, 0.0, -10.0) GL.glRotated(self.xRot / 16.0, 1.0, 0.0, 0.0) GL.glRotated(self.yRot / 16.0, 0.0, 1.0, 0.0) GL.glRotated(self.zRot / 16.0, 0.0, 0.0, 1.0) # draw Objects GL.glPushMatrix() # Protect our matrix w = self.winfo_width() h = self.winfo_height() GL.glViewport(0, 0, w, h) # Clear the background and depth buffer. GL.glClearColor(self.r_back, self.g_back, self.b_back, 0.) GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluPerspective(self.fovy, float(w) / float(h), self.near, self.far) if 0: # Now translate the scene origin away from the world origin GL.glMatrixMode(GL.GL_MODELVIEW) mat = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX) GL.glLoadIdentity() GL.glTranslatef(-self.xcenter, -self.ycenter, -(self.zcenter + self.distance)) GL.glMultMatrixd(mat) else: GLU.gluLookAt(self.xcenter, self.ycenter, self.zcenter + self.distance, self.xcenter, self.ycenter, self.zcenter, 0., 1., 0.) GL.glMatrixMode(GL.GL_MODELVIEW) # Call objects redraw method. self.drawObjects() GL.glFlush() # Tidy up GL.glPopMatrix() # Restore the matrix
def initializeGL(self): glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) #glEnable(GL_LIGHT1) glEnable(GL_DEPTH_TEST) glLightfv(GL_LIGHT0, GL_AMBIENT, [0.0, 0.0, 0.0, 1.0]) glLightfv(GL_LIGHT0, GL_DIFFUSE, [1.0,1.0,1.0, 1.0]) glLightfv(GL_LIGHT0, GL_SPECULAR, [1.0, 1.0, 1.0, 1.0]) glLightfv(GL_LIGHT0, GL_POSITION, [0.1,.1,1.,0.]) glLightfv(GL_LIGHT1, GL_AMBIENT, [0.0, 0.0, 0.0, 1.0]) glLightfv(GL_LIGHT1, GL_DIFFUSE, [0.5,0.5,0.5, 1.0]) glLightfv(GL_LIGHT1, GL_SPECULAR, [0.0, 0.0, 0.0, 1.0]) glLightfv(GL_LIGHT1, GL_POSITION, [0,0,1,1]) # set the is self.radius when it's known glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, [0,0,-1]) glLightfv(GL_LIGHT1, GL_QUADRATIC_ATTENUATION,0.0037) glLightfv(GL_LIGHT2, GL_AMBIENT, [0.0, 0.0, 0.0, 1.0]) glLightfv(GL_LIGHT2, GL_DIFFUSE, [0.5,0.5,0.5, 1.0]) glLightfv(GL_LIGHT2, GL_SPECULAR, [0.0, 1.0, 0.0, 1.0]) glLightfv(GL_LIGHT2, GL_POSITION, [0.1,.1,1.,0.]) glLightfv(GL_LIGHT3, GL_AMBIENT, [0.0, 0.0, 0.0, 1.0]) glLightfv(GL_LIGHT3, GL_DIFFUSE, [0.5,0.5,0.5, 1.0]) glLightfv(GL_LIGHT3, GL_SPECULAR, [0.0, 1.0, 0.0, 1.0]) glLightfv(GL_LIGHT3, GL_POSITION, [0.1,.1,1.,0.]) #GL_SPOT_DIRECTION,GL_SPOT_CUTOFF,GL_QUADRATIC_ATTENUATION GL.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE) glShadeModel(GL_SMOOTH) #glLightModelfv(GL_LIGHT_MODEL_AMBIENT, [0.1,0.1,0.1,1.0]); glClearStencil(0) glEnable(GL_STENCIL_TEST) GL.glClearColor(0,0,0,0) glEnable(GL_NORMALIZE)
def main(): pygame.init() screen = pygame.display.set_mode(res, pygame.OPENGL|pygame.DOUBLEBUF) pygame.display.set_caption("data renderer") print(GL.glGetString(GL.GL_VERSION)) GL.glClearColor(0.5, 0.5, 0.5, 1.0) GL.glEnable(GL.GL_DEPTH_TEST) shader = OpenGL.GL.shaders.compileProgram( OpenGL.GL.shaders.compileShader(vertex_shader, GL.GL_VERTEX_SHADER), OpenGL.GL.shaders.compileShader(fragment_shader, GL.GL_FRAGMENT_SHADER) ) vertex_array_object = create_vertex_array_object(gVertices, gColors) line_vbos = create_axes_vbo(Vector3.from_floats(-3.0, -3.0, -3.0), Vector3.from_floats(3.0, 3.0, 3.0)) clock = pygame.time.Clock() global view view = Matrix44().translation(0.0, 0.0, -5.0) global proj proj = Matrix44.perspective_projection_fov(math.pi / 2, res[0] / float(res[1]), 0.1, 100.0) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: return if event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE: return clock.tick() simtime = pygame.time.get_ticks() * 0.001 handle_arcball() GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) display(shader, vertex_array_object, simtime, GL.GL_POINTS, int(len(gVertices) / 3)) display(shader, line_vbos[0], simtime, GL.GL_LINES, 2) display(shader, line_vbos[1], simtime, GL.GL_LINES, 2) display(shader, line_vbos[2], simtime, GL.GL_LINES, 2) pygame.display.flip()
def on_display( ): global shader gl.glClearColor(1,1,1,1) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glEnable(gl.GL_BLEND) radius = 255.0 theta, dtheta = 0, 5.5/180.0*math.pi support = 0.75 thickness = 1.0 shader.bind() shader.uniformf('support', support) shader.uniformf('thickness', thickness) for i in range(500): xc = 256+radius*math.cos(theta); yc = 32+256+radius*math.sin(theta); r = 10.1 + thickness/2.0 + 1.25*support - i*0.02 P = [(xc+cos(t+theta)*r, yc+sin(t+theta)*r) for t in np.linspace(0,2*np.pi,6,endpoint=False)] polygon(np.array(P).reshape(6,2), thickness, support) radius -= 0.45 theta += dtheta for i in range(0,39): thickness = (i+1)/10.0 shader.uniformf('thickness', thickness) r = 4 + max(thickness,1.0)/2 + 1.25*support xc = 20+i*12.5 - r yc = 16 P = [(xc+cos(t)*r, yc+sin(t)*r) for t in np.linspace(0,2*np.pi,6,endpoint=False)] polygon(np.array(P).reshape(6,2), thickness, support) shader.unbind() glut.glutSwapBuffers()
def initializeGL(self): # background color gl.glClearColor(0, 0, 0, 0) # setup textures (walls background without points/meat and with points/meat self.texture_0 = self.read_texture("Resources/pacman1.jpg") self.texture_1 = self.read_texture("Resources/pacman2.jpg") self.texture_ghost = [] texId = self.read_texture("Resources/ghost_red.jpg") self.texture_ghost.append(texId) texId = self.read_texture("Resources/ghost_pink.jpg") self.texture_ghost.append(texId) texId = self.read_texture("Resources/ghost_green.jpg") self.texture_ghost.append(texId) texId = self.read_texture("Resources/ghost_orange.jpg") self.texture_ghost.append(texId) texId = self.read_texture("Resources/ghost_blue.jpg") self.texture_ghost.append(texId) self.gpos_x0 = [-1.02, 0.98, -1.2, 1.2, 0.0] self.gpos_y0 = [3.26, 3.26, 1.0, 1.0, 1.0] self.gpos_x = list(self.gpos_x0) self.gpos_y = list(self.gpos_y0) self.pos_x = self.pos_x0 self.pos_y = self.pos_y0 self.prevKeyGhost.append(QtCore.Qt.Key_Left) self.prevKeyGhost.append(QtCore.Qt.Key_Right) self.prevKeyGhost.append(QtCore.Qt.Key_Left) self.prevKeyGhost.append(QtCore.Qt.Key_Right) self.prevKeyGhost.append(QtCore.Qt.Key_Left) # create a Vertex Buffer Object with the specified data self.vbo = [] for i in range(0, self.nums): self.vbo.append(glvbo.VBO(self.data[i])) self.drawScore() self.drawLives() self.drawTitle()
def cloud_for_vis(img,depth): index_matrix_2[:,2] = np.reshape(depth,(480*640)) points_in_cam_frame = index_matrix_2 #point_in_cam_frame = np.transpose(depth*index_matrix_2) # 3x480*640 points_in_world = np.matmul(camera_matrix_inv,points_in_cam_frame.T) # 3x480*640 points_in_world = np.transpose(points_in_world) # 480*640x3 points_colours = np.reshape(img,(480*640,3)) # RGB values for each point """fig = plt.figure() ax = Axes3D(fig) #ax.scatter([2,4,5,2],[3,4,2,1],[6,3,4,1]) ax.scatter(points_in_world[:,0],points_in_world[:,1],points_in_world[:,2]) plt.show()""" pangolin.CreateWindowAndBind('Main', 640, 480) gl.glEnable(gl.GL_DEPTH_TEST) # Define Projection and initial ModelView matrix scam = pangolin.OpenGlRenderState(pangolin.ProjectionMatrix(640, 480, 420, 420, 320, 240, 0.2, 100),pangolin.ModelViewLookAt(-2, 2, -2, 0, 0, 0, pangolin.AxisDirection.AxisY)) handler = pangolin.Handler3D(scam) # Create Interactive View in window dcam = pangolin.CreateDisplay() dcam.SetBounds(0.0, 1.0, 0.0, 1.0, -640.0/480.0) dcam.SetHandler(handler) while not pangolin.ShouldQuit(): gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(1.0, 1.0, 1.0, 1.0) dcam.Activate(scam) # Render OpenGL Cube #pangolin.glDrawColouredCube() # Draw Point Cloud points = points_in_world#np.random.random((100000, 3)) * 10 gl.glPointSize(2) gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawPoints(points) pangolin.FinishFrame()
def __init__(self, width=640, height=480): # version hints: create GL window with >= OpenGL 3.3 and core profile glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3) glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3) glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, GL.GL_TRUE) glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE) glfw.window_hint(glfw.RESIZABLE, False) self.win = glfw.create_window(width, height, 'Viewer', None, None) # make win's OpenGL context current; no OpenGL calls can happen before glfw.make_context_current(self.win) # register event handlers glfw.set_key_callback(self.win, self.on_key) # useful message to check OpenGL renderer characteristics print( 'OpenGL', GL.glGetString(GL.GL_VERSION).decode() + ', GLSL', GL.glGetString(GL.GL_SHADING_LANGUAGE_VERSION).decode() + ', Renderer', GL.glGetString(GL.GL_RENDERER).decode()) # initialize GL by setting viewport and default render characteristics GL.glClearColor(0.1, 0.1, 0.1, 0.1) GL.glEnable(GL.GL_DEPTH_TEST) # depth test now enabled (TP2) GL.glEnable(GL.GL_CULL_FACE) # backface culling enabled (TP2) # compile and initialize shader programs once globally self.color_shader = Shader(COLOR_VERT, COLOR_FRAG) # initially empty list of object to draw self.drawables = [] # initialize trackball self.trackball = GLFWTrackball(self.win) # cyclic iterator to easily toggle polygon rendering modes self.fill_modes = cycle([GL.GL_LINE, GL.GL_POINT, GL.GL_FILL])
def main(): imgui.create_context() window = impl_glfw_init() impl = GlfwRenderer(window) while not glfw.window_should_close(window): glfw.poll_events() impl.process_inputs() imgui.new_frame() if imgui.begin_main_menu_bar(): if imgui.begin_menu("File", True): clicked_quit, selected_quit = imgui.menu_item( "Quit", 'Cmd+Q', False, True ) if clicked_quit: exit(1) imgui.end_menu() imgui.end_main_menu_bar() imgui.show_test_window() imgui.begin("Custom window", True) imgui.text("Bar") imgui.text_colored("Eggs", 0.2, 1., 0.) imgui.end() gl.glClearColor(1., 1., 1., 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() impl.render(imgui.get_draw_data()) glfw.swap_buffers(window) impl.shutdown() glfw.terminate()
def _pass_ssaa(self, tex, w, h, scale): # Select Lanczos kernel based on scale. aakernel = [ None, None, [ 0.44031130485056913, 0.29880437751590694, 0.04535643028360444, -0.06431646022479595 ], [ 0.2797564513818748, 0.2310717037833796, 0.11797652759318597, 0.01107354293249700 ], ][scale] # Prepare for drawing texture to screen gl.glClearColor(1, 1, 1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) self.setup_scene(0, 0, W, H) tex.Enable(0) shader = Shader(None, self._shader_code[0]) shader.bind() shader.uniformf('shape', w, h) # resolution of previous pass shader.uniformi('texture', 0) if aakernel: shader.uniformf('aakernel', *aakernel) # Draw texture to screen gl.glBegin(gl.GL_QUADS) gl.glTexCoord(0, 0) gl.glVertex(0, 0) gl.glTexCoord(0, 1) gl.glVertex(0, 1) gl.glTexCoord(1, 1) gl.glVertex(1, 1) gl.glTexCoord(1, 0) gl.glVertex(1, 0) gl.glEnd() shader.unbind() tex.Disable()
def paintGL(self): if self.quad_shader is None: return # not yet initiliazed self.clearErrors() # Clear The Screen And The Depth Buffer GL.glClearColor(1, 1, 1, 0) GL.glClear(GL.GL_COLOR_BUFFER_BIT) # | GL.GL_DEPTH_BUFFER_BIT) shaders.glUseProgram(self.quad_shader) if self.is_core: # on OpenGL 3 core, create and bind a vertex array object (on non-core, there is one default VAO) GL.glBindVertexArray(self.vao) try: self.setupViewport(self.width(), self.height()) self.drawBackground() self.drawGrid() self.drawGlData() self.drawRuler() self.drawBorder() finally: if self.is_core: GL.glBindVertexArray(0) shaders.glUseProgram(0) painter = QtGui.QPainter(self) self.drawTrackerText(painter) self.drawFreqMaxText(painter) painter.end() if not self.paused: # schedule a repaint ! self.update()
def main(): GLUT.glutInit(sys.argv) GLUT.glutInitDisplayMode(GLUT.GLUT_SINGLE | GLUT.GLUT_RGBA | GLUT.GLUT_DEPTH) GLUT.glutInitWindowSize(400, 400) GLUT.glutInitWindowPosition(200, 200) GLUT.glutCreateWindow("Grafica 2") GL.glDepthFunc(GL.GL_LEQUAL) GL.glEnable(GL.GL_DEPTH_TEST) GL.glClearDepth(1.0) GL.glClearColor(0.650, 0.780, 0.8, 0) GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() #GL.glOrtho(-20, 20, -20, 20, -20, 20) GL.glMatrixMode(GL.GL_MODELVIEW) GLU.gluPerspective(100, 1.0, 1.0, 100.0) GL.glTranslatef(0.0, 0.0, 0.0) GLU.gluLookAt(10, 10, 10, 0, 0, 0, 0, 1, 0) grid = GR.grid_gen() grid.show() GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) grid.plot() ######################################## head.plot() ######################################## GL.glFlush() GLUT.glutPostRedisplay() GLUT.glutMainLoop()
def gtkgl_refresh_wrapper(self, *args, **kwargs): prev_mode = GL.glGetIntegerv(GL.GL_MATRIX_MODE) GL.glMatrixMode(GL.GL_MODELVIEW) # clear the background with the configured color bg_col = self.core.get("color_background") GL.glClearColor(bg_col["red"], bg_col["green"], bg_col["blue"], 0.0) GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) result = func(self, *args, **kwargs) self.camera.position_camera() # adjust Light #2 v = self.camera.view lightpos = (v["center"][0] + v["distance"][0], v["center"][1] + v["distance"][1], v["center"][2] + v["distance"][2]) GL.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, lightpos) # trigger the visualization of all items self.core.emit_event("visualize-items") GL.glMatrixMode(prev_mode) GL.glFlush() self.area.get_gl_drawable().swap_buffers() return result
def render(self, context): self.shader.bind() gl.glDisable(gl.GL_BLEND) gl.glEnable(gl.GL_DEPTH_TEST) gl.glClearDepth(1.0) gl.glClearColor(*self.clearColor) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) view, projection = createDefaultMatrices(self.width, self.height, context) self.shader.uniformMatrix4f(shader.VIEW_MATRIX, view) self.shader.uniformMatrix4f(shader.PROJ_MATRIX, projection) self.setUniforms(self.shader, context.uniforms) for tag, entry in self.models.items(): mesh = entry.mesh entry.textureMap.bindTextures(self.shader) self.shader.uniformMatrix4f(shader.WORLD_MATRIX, entry.matrix) self.bindAttributeArray(self.shader, "inPosition", mesh.vertices, 3) self.bindAttributeArray(self.shader, "inNormal", mesh.normals, 3) self.bindAttributeArray(self.shader, "inUv", mesh.uvs, 2) gl.glDrawArrays(gl.GL_TRIANGLES, 0, len(mesh.vertices) // 3) self.unbindAttributeArray(self.shader, "inPosition") self.unbindAttributeArray(self.shader, "inNormal") self.unbindAttributeArray(self.shader, "inUv") entry.textureMap.unbindTextures() gl.glEnable(gl.GL_BLEND) gl.glDisable(gl.GL_DEPTH_TEST) self.shader.unbind()
def main(): pygame.init() size = 800, 600 pygame.display.set_mode(size, pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE) imgui.create_context() impl = PygameRenderer() io = imgui.get_io() io.display_size = size while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() impl.process_event(event) imgui.new_frame() if imgui.begin_main_menu_bar(): if imgui.begin_menu("File", True): clicked_quit, selected_quit = imgui.menu_item("Quit", 'Alt+F4', False, True) clicked_save, selected_save = imgui.menu_item("Save", "", False, True) if clicked_save: print("Saved...") if clicked_quit: exit(1) imgui.end_menu() imgui.end_main_menu_bar() gl.glClearColor(1, 1, 1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() impl.render(imgui.get_draw_data()) pygame.display.flip()
def initializeGL(self): self.worldJoint = Joint(name='WorldJoint', showAxis=True, axisScale=0.7) GL.glClearColor(0.0, 0.0, 0.0, 1.0) # GL.glClearColor(1.0,1.0,1.0,1.0) GL.glClearDepth(1) GL.glClear(GL.GL_COLOR_BUFFER_BIT) GL.glEnable(GL.GL_BLEND) # enable blending GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) # set blend function GL.glEnable(GL.GL_DEPTH_TEST) GL.glEnable(GL.GL_LIGHTING) # enable the lighting # GL.glEnable(GL.GL_LIGHT0) #enable LIGHT0, our Diffuse Light for light in self.lights: light.updateOpenGl() GL.glShadeModel(GL.GL_SMOOTH) # set the shader to smooth shader GL.glEnable(GL.GL_NORMALIZE) GL.glEnable(GL.GL_TEXTURE_2D) vMin, vMax = self.getBoundingBox() self.camera.setView(vMin, vMax, view='ortho1')
def viewer_refresh(self): if self.state == None: return # turn state into points ppts = np.array([d[:3, 3] for d in self.state[0]]) spts = np.array(self.state[1]) print(ppts) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(1.0, 1.0, 1.0, 1.0) self.dcam.Activate(self.scam) gl.glPointSize(10) gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawPoints(ppts) gl.glPointSize(2) gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawPoints(spts) pangolin.FinishFrame()
def on_display(): global shader gl.glClearColor(1, 1, 1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glActiveTexture(gl.GL_TEXTURE0) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glEnable(gl.GL_BLEND) gl.glColor(0, 0, 0, 1) radius = 255.0 theta, dtheta = 0, 5.5 / 180.0 * math.pi thickness = 1.0 support = .75 for i in range(500): xc, yc = 256, 256 + 32 r = 10.1 - i * 0.02 x0 = xc + np.cos(theta + dtheta / 3) * radius * .925 y0 = yc + np.sin(theta + dtheta / 3) * radius * .925 x1 = xc + np.cos(theta - dtheta / 3) * radius * .925 y1 = yc + np.sin(theta - dtheta / 3) * radius * .925 x2 = xc + np.cos(theta) * radius * 1.00 y2 = yc + np.sin(theta) * radius * 1.00 triangle((x0, y0), (x1, y1), (x2, y2), thickness, support) radius -= 0.45 theta += dtheta for i in range(0, 39): thickness = (i + 1) / 20.0 xc, yc = 20 + i * 12.5, 16 x0, y0 = xc - 5, yc - 5 x1, y1 = xc + 5, yc - 5 x2, y2 = xc, yc + 5 triangle((x0, y0), (x1, y1), (x2, y2), thickness, support) glut.glutSwapBuffers()
def render(): global sampleTexture global shaderProgram global texUnitUniform global VAO global idxCnt global rot global projection global translation global view global lightVec GL.glClearColor(1, 1, 1, 1) GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT) GL.glUseProgram(shaderProgram) try: rotUniform = GL.glGetUniformLocation(shaderProgram, 'rot') GL.glUniformMatrix4fv(rotUniform, 1, False, glm.value_ptr(rot)) projectionLoc = GL.glGetUniformLocation(shaderProgram, 'projection') GL.glUniformMatrix4fv(projectionLoc, 1, False, glm.value_ptr(projection)) translationLoc = GL.glGetUniformLocation(shaderProgram, 'translation') GL.glUniformMatrix4fv(translationLoc, 1, False, glm.value_ptr(translation)) viewLoc = GL.glGetUniformLocation(shaderProgram, 'view') GL.glUniformMatrix4fv(viewLoc, 1, False, glm.value_ptr(view)) lightLoc = GL.glGetUniformLocation(shaderProgram, 'lightPos') GL.glUniform3fv(lightLoc, 1, glm.value_ptr(lightVec)) # Activate texture GL.glActiveTexture(GL.GL_TEXTURE0) GL.glBindTexture(GL.GL_TEXTURE_3D, sampleTexture) GL.glUniform1i(texUnitUniform, 0) # Activate array GL.glBindVertexArray(VAO) GL.glDrawElements(GL.GL_TRIANGLES, idxCnt, GL.GL_UNSIGNED_INT, None) finally: GL.glBindVertexArray(0) GL.glUseProgram(0)
def render(self, context): self.shader.bind() flipY = -1 projection = utils.createPerspectiveOrtho(-1.0, 1.0, 1.0 * flipY, -1.0 * flipY, -1.0, 1.0) self.shader.uniformMatrix4f(shader.PROJECTION, projection) self.shader.uniformf("imageSize", *self.getSize()) self.setUniforms(self.shader, context.uniforms) self.textureMap.bindTextures(self.shader) gl.glClearColor(*self.clearColor) gl.glClear(gl.GL_COLOR_BUFFER_BIT) self.bindAttributeArray(self.shader, "inVertex", self.verts, 4) gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, len(self.verts) // 4); self.unbindAttributeArray(self.shader, "inVertex") self.textureMap.unbindTextures() self.shader.unbind()
def create_main_window(): if not glfw.init(): sys.exit(1) try: glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3) glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3) glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, True) glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE) title = 'Tutorial 2: First Triangle' window = glfw.create_window(500, 400, title, None, None) if not window: sys.exit(2) glfw.make_context_current(window) glfw.set_input_mode(window, glfw.STICKY_KEYS, True) gl.glClearColor(0, 0, 0.4, 0) yield window finally: glfw.terminate()
def main(): GLUT.glutInit(argv) GLUT.glutInitDisplayMode( GLUT.GLUT_DOUBLE | GLUT.GLUT_RGBA | GLUT.GLUT_DEPTH | GLUT.GLUT_MULTISAMPLE ) screen_width = GLUT.glutGet(GLUT.GLUT_SCREEN_WIDTH) screen_height = GLUT.glutGet(GLUT.GLUT_SCREEN_HEIGHT) window_width = round(2 * screen_width / 3) window_height = round(2 * screen_height / 3) GLUT.glutInitWindowSize(window_width, window_height) GLUT.glutInitWindowPosition( round((screen_width - window_width) / 2), round((screen_height - window_height) / 2) ) GLUT.glutCreateWindow(window_name) GLUT.glutDisplayFunc(draw) GLUT.glutSpecialFunc(special_key_pressed) GLUT.glutKeyboardFunc(key_pressed) GLUT.glutMouseFunc(mouse_click) GLUT.glutMotionFunc(mouse_move) GL.glEnable(GL.GL_MULTISAMPLE) GL.glEnable(GL.GL_DEPTH_TEST) GL.glClearColor(*background_color) GLU.gluPerspective(-45, window_width / window_height, 0.1, 100.0) GL.glTranslatef(0.0, 0.0, -10) GLUT.glutTimerFunc(10, timer, 1) GLUT.glutMainLoop()
def initializeGL(self): glut.glutInit([]) gl.glEnable(gl.GL_DEPTH_TEST) gl.glDepthMask(True) gl.glDepthFunc(gl.GL_LEQUAL) gl.glDepthRange(0.0, 1.0) gl.glClearColor(0, 0, 0, 0) gl.glClearDepth(1.0) gl.glShadeModel(gl.GL_SMOOTH) if self._light: gl.glLight(gl.GL_LIGHT0, gl.GL_AMBIENT, [0.9, 0.9, 0.9, 1]) gl.glLight(gl.GL_LIGHT0, gl.GL_DIFFUSE, [1, 1, 1, 1]) gl.glLight(gl.GL_LIGHT0, gl.GL_SPECULAR, [1, 1, 1, 1]) gl.glLight(gl.GL_LIGHT0, gl.GL_POSITION, [1, 1, 0, 0]) gl.glEnable(gl.GL_NORMALIZE) gl.glEnable(gl.GL_LIGHTING) gl.glEnable(gl.GL_LIGHT0) gl.glEnable(gl.GL_COLOR_MATERIAL) gl.glColorMaterial(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE) gl.glMaterial(gl.GL_FRONT_AND_BACK, gl.GL_SPECULAR, [1, 1, 1, 1]) gl.glMaterial(gl.GL_FRONT_AND_BACK, gl.GL_EMISSION, [0, 0, 0, 1]) gl.glMaterial(gl.GL_FRONT_AND_BACK, gl.GL_SHININESS, 10) gl.glLineWidth(self._linew) if self._multisample: gl.glEnable(gl.GL_MULTISAMPLE) if self._smooth == 1: gl.glEnable(gl.GL_POINT_SMOOTH) gl.glEnable(gl.GL_LINE_SMOOTH) gl.glEnable(gl.GL_POLYGON_SMOOTH) gl.glHint(gl.GL_POINT_SMOOTH_HINT, gl.GL_FASTEST) gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_FASTEST) gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_FASTEST) if self._smooth == 2: gl.glEnable(gl.GL_POINT_SMOOTH) gl.glEnable(gl.GL_LINE_SMOOTH) gl.glEnable(gl.GL_POLYGON_SMOOTH) gl.glHint(gl.GL_POINT_SMOOTH_HINT, gl.GL_NICEST) gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST) gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST)
def viewer_refresh(self, q): if self.state is None or not q.empty(): self.state = q.get() # turn state into points #ppts = np.array([d[:3, 3] for d in self.state[0]]) spts = np.array(self.state[1]) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(1.0, 1.0, 1.0, 1.0) self.dcam.Activate(self.scam) # draw poses gl.glColor3f(0.0, 1.0, 0.0) pangolin.DrawCameras(self.state[0]) #draw keypoints gl.glPointSize(2) gl.glColor3f(1.0, 0.0, 0.0) pangolin.DrawPoints(spts) pangolin.FinishFrame()
def main(): # glfwの初期化 if not glfw.init(): raise RuntimeError('Could not initialize GLFW3') # OpenGLのバージョンを指定(この授業では古いOpenGLを使います) glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 2) glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 1) glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_ANY_PROFILE) # 窓を作る window = glfw.create_window(300, 300, 'Program', None, None) # 窓を作る(幅と高さ,タイトルを指定) if not window: # 窓が作れなかった時の処理 glfw.terminate() raise RuntimeError('Could not create an window') glfw.make_context_current(window) # OpenGLの情報を表示 print('Vendor :', gl.glGetString(gl.GL_VENDOR)) print('GPU :', gl.glGetString(gl.GL_RENDERER)) print('OpenGL version :', gl.glGetString(gl.GL_VERSION)) gl.glClearColor(1.0, 1.0, 1.0, 1.0) # 初期化した時のバッファの色(背景色)の設定 gl.glEnable(gl.GL_DEPTH_TEST) # Z-バッファ法による隠面消去を有効にする time = 0.0 while not glfw.window_should_close(window): # main loop time += 0.01 gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) # 描画用のバッファを背景色で塗りつぶす display(time) # 描画用のバッファに描画する glfw.swap_buffers(window) # 描画用のバッファと,表示用のバッファを入れ替えて画面を更新 glfw.poll_events() # イベントの受けつけ glfw.terminate()
def displayfunc_gles2(display, surface, ctx): from OpenGL import GLES2 as GL from OpenGL.GLES2 import shaders eglMakeCurrent( display, surface, surface, ctx ) GL.glClearColor( 1,0,0, 0 ) GL.glClear( GL.GL_COLOR_BUFFER_BIT|GL.GL_DEPTH_BUFFER_BIT ) global shader,vbo,position_location,stride if shader is None: shader = shaders.compileProgram( shaders.compileShader( '''#version 130 attribute vec3 position; void main() { gl_Position = vec4( position, 0 ); }''', type=GL_VERTEX_SHADER), shaders.compileShader( '''#version 130 void main() { gl_FragColor = vec4( 1,0,0,0 ); }''', type=GL_FRAGMENT_SHADER), ) vbo = VBO( array([ (0,1,0), (1,-1,0), (-1,-1,0), ],dtype='f')) position_location = GL.glGetAttribLocation( self.shader, 'position' ) stride = 3*4 with vbo: with shader: GL.glEnableVertexAttribArray( position_location ) stride = 3*4 GL.glVertexAttribPointer( position_location, 3, GL_FLOAT,False, stride, self.vbo ) GL.glDrawArrays( GL.GL_TRIANGLES, 0, 3 ) eglSwapBuffers( display, surface )
def draw(self): q = self.q self.draw_init() while not pangolin.ShouldQuit(): try: while not q.empty(): state = q.get() if state is not None: self.cams.append(state[0]) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glClearColor(1.0, 1.0, 1.0, 1.0) self.dcam.Activate(self.scam) # Draw cam gl.glLineWidth(2) gl.glColor3f(0.0, 1.0, 0.0) # pangolin.DrawCamera(state[0], 0.5, 0.75, 0.8) pangolin.DrawCameras(self.cams) pangolin.FinishFrame() except: continue
def initializeGL(self): """Initialize OpenGL, VBOs, upload data on the GPU, etc.""" # background color gl.glClearColor(0.8, 0.8, 0.8, 0) # Make initial data array. # compile the vertex shader vs = compile_shader(VERTEX, gl.GL_VERTEX_SHADER) # compile the geometry shader gs = compile_shader(GEOMETRY, gl.GL_GEOMETRY_SHADER) # compile the fragment shader fs = compile_shader(FRAGMENT, gl.GL_FRAGMENT_SHADER) # Link the programs. self.render_program = link_shaders(vs, gs, fs) # Compile the compute shader cs = compile_shader(COMPUTE, gl.GL_COMPUTE_SHADER) # Create the compute shader buffers. self.makeBuffers() #self.vbo = glvbo.VBO(self.attributes) self.vbo = gl.glGenBuffers(1) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self.vbo) gl.glBufferData(gl.GL_ARRAY_BUFFER, self.attributes.nbytes, self.attributes, gl.GL_DYNAMIC_COPY) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0) self.ssbo = gl.glGenBuffers(1) gl.glBindBufferBase(gl.GL_SHADER_STORAGE_BUFFER, 1, self.ssbo) gl.glBufferData(gl.GL_SHADER_STORAGE_BUFFER, self.velocities.nbytes, self.velocities, gl.GL_DYNAMIC_COPY) self.compute_program = link_shaders(cs)