def _test_setting_parameters(): # Set some parameters and get result clr = 1.0, 0.1, 0.2, 0.7 gl.glClearColor(*clr) assert_almost_equal(gl.glGetParameter(gl.GL_COLOR_CLEAR_VALUE), clr) # gl.glCullFace(gl.GL_FRONT) assert_equal(gl.glGetParameter(gl.GL_CULL_FACE_MODE), gl.GL_FRONT) gl.glCullFace(gl.GL_BACK) assert_equal(gl.glGetParameter(gl.GL_CULL_FACE_MODE), gl.GL_BACK) # gl.glDepthFunc(gl.GL_NOTEQUAL) assert_equal(gl.glGetParameter(gl.GL_DEPTH_FUNC), gl.GL_NOTEQUAL) # val = 0.2, 0.3 gl.glDepthRange(*val) assert_almost_equal(gl.glGetParameter(gl.GL_DEPTH_RANGE), val) gl.check_error()
def __init__(self, size): app.Canvas.__init__(self, title='Hello OpenGL', keys='interactive', size=size) # vispy wrapper of glfw dont have the wrapper of this function yet, I am opening a PR for this # by the time we can use this self._app.native.glfwSetInputMode( self.native._id, self._app.native.GLFW_CURSOR, self._app.native.GLFW_CURSOR_DISABLED) builtins.width, builtins.height = size # camera instance self.camera = Camera(position=glm.vec3(0, 0, 3), sensitivity=0.2) self.startTime = time() self.first_mouse = True self.lightPos = [0, 0, 0] self.lightColor = glm.vec3(1) self.program = gloo.Program(vertex, fragment) self.programLightSource = gloo.Program(lightSourceVertex, lightSourceFragment) self.vertices = np.array([[-0.5, -0.5, -0.5], [0.5, -0.5, -0.5], [0.5, 0.5, -0.5], [0.5, 0.5, -0.5], [-0.5, 0.5, -0.5], [-0.5, -0.5, -0.5], [-0.5, -0.5, 0.5], [0.5, -0.5, 0.5], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [-0.5, 0.5, 0.5], [-0.5, -0.5, 0.5], [-0.5, 0.5, 0.5], [-0.5, 0.5, -0.5], [-0.5, -0.5, -0.5], [-0.5, -0.5, -0.5], [-0.5, -0.5, 0.5], [-0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [0.5, 0.5, -0.5], [0.5, -0.5, -0.5], [0.5, -0.5, -0.5], [0.5, -0.5, 0.5], [0.5, 0.5, 0.5], [-0.5, -0.5, -0.5], [0.5, -0.5, -0.5], [0.5, -0.5, 0.5], [0.5, -0.5, 0.5], [-0.5, -0.5, 0.5], [-0.5, -0.5, -0.5], [-0.5, 0.5, -0.5], [0.5, 0.5, -0.5], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [-0.5, 0.5, 0.5], [-0.5, 0.5, -0.5]]).astype(np.float32) self.aNormal = np.array([ [0, 0, -1], [0, 0, -1], [0, 0, -1], [0, 0, -1], [0, 0, -1], [0, 0, -1], [0, 0, 1], [0, 0, 1], [0, 0, 1], [0, 0, 1], [0, 0, 1], [0, 0, 1], [-1, 0, 0], [-1, 0, 0], [-1, 0, 0], [-1, 0, 0], [-1, 0, 0], [-1, 0, 0], [1, 0, 0], [1, 0, 0], [1, 0, 0], [1, 0, 0], [1, 0, 0], [1, 0, 0], [0, -1, 0], [0, -1, 0], [0, -1, 0], [0, -1, 0], [0, -1, 0], [0, -1, 0], [0, 1, 0], [0, 1, 0], [0, 1, 0], [0, 1, 0], [0, 1, 0], [0, 1, 0], ]).astype(np.float32) self.texCoord = np.array( [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [1.0, 1.0], [0.0, 1.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [1.0, 1.0], [0.0, 1.0], [0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0], [0.0, 1.0], [0.0, 0.0], [1.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0], [0.0, 1.0], [0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 1.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 1.0]]).astype(np.float32) self.diffuse_map = gloo.Texture2D( data=np.flip(io.imread('Assets/container2.png'), 0)) self.specular_map = gloo.Texture2D( data=np.flip(io.imread('Assets/container2_specular.png'), 0)) self.model = None self.projection = None self.view = None # delta time self.delta_time = 0 self.last_frame = 0 # mouse variables self.last_x = None self.last_y = None self.timer = app.Timer('auto', self.on_timer, start=True) gloo.set_state(depth_test=True) gl.glDepthFunc(gl.GL_LESS) gl.glEnable(gl.GL_STENCIL_TEST) self.show()