def _ChangeMotionMode_(self, drag, spin, auto ): new_drag = drag new_auto = auto if not new_drag else False new_spin = spin if new_auto else False change = self.__mouse_drag != new_drag or self.__auto_rotate != new_auto or self.__auto_spin != new_spin if not change: return if new_drag and not self.__mouse_drag: self.__dragStartTime = time() self.__mouse_drag_angle = 0 self.__mouse_drag_time = 0 if new_auto and not self.__auto_rotate: self.__rotateStartTime = time() self.__mouse_drag = new_drag self.__auto_rotate = new_auto self.__auto_spin = new_spin self.__orbit_mat = mat.Multiply(self.__current_orbit_mat, self.__orbit_mat) self.__current_orbit_mat = mat.IdentityMat44() self.__model_mat = mat.Multiply(self.__current_model_mat, self.__model_mat) self.__current_model_mat = mat.IdentityMat44() return
def __Draw__(self): self.__currentTime = time() self.__vpsize = (glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT)) self.__current_model_mat = mat.IdentityMat44() if self.__mouse_drag: self.__current_orbit_mat = mat.Rotate(mat.IdentityMat44(), self.__mouse_drag_angle, self.__mouse_drag_axis) elif self.__auto_rotate: if self.__auto_spin: if self.__mouse_drag_time > 0: angle = self.__mouse_drag_angle * ( self.__currentTime - self.__rotateStartTime) / self.__mouse_drag_time self.__current_orbit_mat = mat.Rotate( mat.IdentityMat44(), angle, self.__mouse_drag_axis) else: auto_angle_x = self.Fract( (self.__currentTime - self.__rotateStartTime) / 13.0) * 2.0 * math.pi auto_angle_y = self.Fract( (self.__currentTime - self.__rotateStartTime) / 17.0) * 2.0 * math.pi self.__current_model_mat = mat.RotateX( self.__current_model_mat, auto_angle_x) self.__current_model_mat = mat.RotateY( self.__current_model_mat, auto_angle_y) self._StartDraw_() self.OnDraw() self._EndDraw_() glutSwapBuffers()
def OnDraw(self): # set up projection matrix prjMat = self.Perspective() # set up view matrix viewMat = self.LookAt() # set up attributes and shader program glEnable(GL_DEPTH_TEST) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) progDraw.Use() modelMat = mat.IdentityMat44() modelMat = self.AutoModelMatrix() #modelMat = mat.RotateX( modelMat, self.CalcAng( 13.0 ) ) #modelMat = mat.RotateY( modelMat, self.CalcAng( 17.0 ) ) progDraw.SetUniforms({ b"u_projectionMat44": self.Perspective(), b"u_viewMat44": self.LookAt(), b"u_modelMat44": modelMat, b"u_lightDir": [-1.0, -0.5, -2.0], b"u_ambient": 0.2, b"u_diffuse": 0.8, b"u_specular": 0.8, b"u_shininess": 10.0 }) # draw object torusVAO.Draw()
def OnDraw(self): # set up projection matrix prjMat = self.Perspective() # set up view matrix viewMat = self.LookAt() # set up attributes and shader program glEnable(GL_DEPTH_TEST) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) progDraw.Use() modelMat = mat.IdentityMat44() modelMat = self.AutoModelMatrix() #modelMat = mat.RotateX( modelMat, 60.0*math.pi/180.0 ) #modelMat = mat.RotateY( modelMat, -10.0*math.pi/180.0 ) clip = 0.4 progDraw.SetUniforms({ b"u_projectionMat44": self.Perspective(), b"u_viewMat44": self.LookAt(), b"u_modelMat44": modelMat, b"u_lightDir": [-1.0, -0.5, -2.0], b"u_ambient": 0.2, b"u_diffuse": 0.8, b"u_specular": 0.8, b"u_shininess": 10.0, b"u_texture": 0, b"u_displacement_map": 1, b"u_normal_map": 2, b"u_displacement_scale": 0.2, b"u_parallax_quality": [2.0, 1.0], b"u_clipPlane": [-1.0, 1.0, -0.2, clip * 1.7321] }) # draw object cubeVAO.DrawIB(GL_TRIANGLES)
def OnDraw(self): # set up projection matrix prjMat = self.Perspective() # set up view matrix viewMat = self.LookAt() ########## # 1. stage ########## # set up attributes and shader program renderProcess.PrepareStage( "geometry" ) progDraw.Use() modelMat = mat.IdentityMat44() modelMat = self.AutoModelMatrix() #modelMat = mat.RotateX( modelMat, self.CalcAng( 13.0 ) ) #modelMat = mat.RotateY( modelMat, self.CalcAng( 17.0 ) ) progDraw.SetUniforms( { b"u_projectionMat44" : self.Perspective(), b"u_viewMat44" : self.LookAt(), b"u_modelMat44" : modelMat, b"u_lightDir" : [-1.0, -0.5, -2.0], b"u_ambient" : 0.2, b"u_diffuse" : 0.8, b"u_specular" : 0.8, b"u_shininess" : 10.0 } ) # draw objects cubeVAO.DrawAllElements( GL_TRIANGLES ) torusVAO.DrawAllElements( GL_TRIANGLES ) ########## # 2. stage ########## renderProcess.PrepareStage( "ssao" ) progSSAO.Use() progSSAO.SetUniforms( { b"u_viewportsize" : vp, b"u_radius" : 0.3 } ) # draw screen sapce quadVAO.DrawArray( GL_TRIANGLE_STRIP, 0, 4 ) #quadVAO.Draw() ########## # 3. stage ########## renderProcess.PrepareStage( "blur" ) progBlur.Use() progBlur.SetUniforms( { b"u_viewportsize" : vp, b"u_color_mix" : 0.2 } ) # draw screen sapce quadVAO.DrawArray( GL_TRIANGLE_STRIP, 0, 4 )
def OnDraw(self): # set up projection matrix prjMat = self.Perspective() # set up view matrix viewMat = self.LookAt() # set up attributes and shader program glEnable(GL_DEPTH_TEST) glEnable(GL_CLIP_DISTANCE0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) progDraw.Use() modelMat = mat.IdentityMat44() modelMat = self.AutoModelMatrix() clip_dist = 0.0 progDraw.SetUniforms({ b"u_projectionMat44": self.Perspective(), b"u_viewMat44": self.LookAt(), b"u_modelMat44": modelMat, b"u_lightDir": [-1.0, -0.5, -2.0], b"u_ambient": 0.2, b"u_diffuse": 0.8, b"u_specular": 0.8, b"u_shininess": 10.0, b"u_clipPlane": [1.0, 1.0, 0.0, clip_dist] }) # draw object cubeVAO.Draw()
def OnDraw(self): # set up projection matrix prjMat = self.Perspective() # set up view matrix viewMat = self.LookAt() # set up light source lightSourceBuffer.BindDataFloat( b'u_lightSource.dir', mat.TransformVec4([-0.1, 1.0, -5.0, 0.0], viewMat)) # set up the model matrix modelMat = mat.IdentityMat44() modelMat = self.AutoModelMatrix() modelMat = mat.Scale(modelMat, numpy.repeat(4, 3)) # set up attributes and shader program glEnable(GL_DEPTH_TEST) glClearColor(1, 1, 1, 0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) progGeo.Use() progGeo.SetUniformM44(b"u_projectionMat44", prjMat) progGeo.SetUniformM44(b"u_viewMat44", viewMat) lightSourceBuffer.BindToTarget() # draw point progGeo.SetUniformM44(b"u_modelMat44", modelMat) materialBuffer.BindToTarget() pointVAObj.Draw()
def OnDraw(self): # set up projection matrix prjMat = self.Perspective() # set up view matrix viewMat = self.LookAt() # set up light source lightSourceBuffer.BindDataFloat( b'u_lightSource.dir', mat.TransformVec4([-1.0, -1.0, -5.0, 0.0], viewMat)) # set up icosahedron model matrix modelMat = mat.IdentityMat44() modelMat = self.AutoModelMatrix() #modelMat = mat.RotateX( modelMat, self.CalcAng( 13.0 ) ) #modelMat = mat.RotateY( modelMat, self.CalcAng( 17.0 ) ) # set up attributes and shader program glEnable(GL_DEPTH_TEST) glClearColor(1, 1, 1, 0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) progTess.Use() progTess.SetUniformM44(b"u_projectionMat44", prjMat) lightSourceBuffer.BindToTarget() # draw icosahedron icoMaterialBuffer.BindToTarget() modelViewMat = mat.Multiply(viewMat, modelMat) progTess.SetUniformM44(b"u_modelViewMat44", modelViewMat) progTess.SetUniformM33(b"u_normalMat33", mat.ToMat33(modelViewMat)) icoVAO.Draw()
def OnDraw(self): # set up attributes and shader program fbX.Bind() glEnable(GL_DEPTH_TEST) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) progDraw.Use() progDraw.SetUniform(b"u_projectionMat44", self.Perspective()) viewMat = self.LookAt() modelMat = mat.IdentityMat44() modelMat = self.AutoModelMatrix() #modelMat = mat.RotateX( modelMat, self.CalcAng( 13.0 ) ) #modelMat = mat.RotateY( modelMat, self.CalcAng( 17.0 ) ) progDraw.SetUniform(b"u_modelViewMat44", mat.Multiply(viewMat, modelMat)) progDraw.SetUniform(b"u_glow", 3.0) objVAO.Draw() sigma = 0.8 blurWidth = 20 # blur X fbX.UnBind() fbY.Bind() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) texUnitAttach0 = 1 fbX.BindTextures([texUnitAttach0]) progBlurX.Use() progBlurX.SetUniform(b"u_textureCol", texUnitAttach0) progBlurX.SetUniform(b"u_textureSize", self.VPSize()) progBlurX.SetUniform(b"u_sigma", sigma) progBlurX.SetUniform(b"u_width", blurWidth) # TODO SetUniforms( { } ) # draw screen sapce quadVAO.Draw() # blur Y fbY.UnBind() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) texUnitAttach0 = 2 fbY.BindTextures([texUnitAttach0]) progBlurY.Use() progBlurY.SetUniform(b"u_textureCol", texUnitAttach0) progBlurY.SetUniform(b"u_textureSize", self.VPSize()) progBlurY.SetUniform(b"u_sigma", sigma) progBlurY.SetUniform(b"u_width", blurWidth) # draw screen sapce quadVAO.Draw()
def __init__( self, cx, cy, multisample=False ): self.__vpsize = ( cx, cy ) self.__glut_param = GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH if multisample == True: self.__glut_param = self.__glut_param | GLUT_MULTISAMPLE self.__multisampllevel = 8 if multisample == True: glutSetOption( GLUT_MULTISAMPLE, self.__multisampllevel ) glutInitDisplayMode( self.__glut_param ) glutInitWindowPosition( 0, 0 ) glutInitWindowSize( self.__vpsize[0], self.__vpsize[1] ) self.__id = glutCreateWindow( b'OGL window' ) self.__multisample = multisample self.__vendor = glGetString( GL_VENDOR ) self.__renderer = glGetString( GL_RENDERER ) self.__version = glGetString( GL_VERSION ) self.__glsl_version = glGetString( GL_SHADING_LANGUAGE_VERSION ) self.__major = glGetInteger( GL_MAJOR_VERSION ) self.__minor = glGetInteger( GL_MINOR_VERSION ) self.__numOfExt = glGetInteger( GL_NUM_EXTENSIONS ) self.__extensions = [] for i in range(self.__numOfExt): self.__extensions.append( glGetStringi( GL_EXTENSIONS, i ) ) print( str(self.__vendor ) ) print( str(self.__renderer ) ) print( str(self.__vendor ) ) print( str(self.__glsl_version ) ) print('') print( 'OpenGL Version {}.{}'.format( self.__major, self.__minor ) ) print('') print( '{} extensions'.format( self.__numOfExt ) ) if printExtensions: for i in range(self.__numOfExt): print( ' {}'.format( str(self.__extensions[i]) ) ) print('') print( 'Mutisample: {0}'.format( 'on ({})'.format(self.__multisampllevel) if self.__multisample else 'off' ) ) print('') print('') self.__orbit_mat = mat.IdentityMat44() # persistent orbit orientation matrix self.__current_orbit_mat = mat.IdentityMat44() # additional orbit orientation while dragging self.__mouse_drag = False # draging on or off self.__mouse_drag_axis = (1, 0, 0) # current drag axis self.__mouse_drag_angle = 0 # current drag distance self.__mouse_drag_time = 0 # current drag time self.__mouse_start = (0, 0) # start of mouse dragging operation self.__auto_rotate = True # auto ratate on or of self.__auto_spin = False # auto spin self.__model_mat = mat.IdentityMat44() # persistent model matrix self.__current_model_mat = mat.IdentityMat44() # current model matrix glutMouseFunc( self.__MouseButton__ ) glutMotionFunc( self.__MouseMotion__ ) glutPassiveMotionFunc( self.__MousePassiveMotion__ ) glutDisplayFunc( self.__Draw__ ) glutIdleFunc( self.__Draw__ )