Пример #1
0
 def __init__(self,contrast=1.0,*args,**kwargs):
     super(ShaderTexture, self).__init__(*args,**kwargs)
     """
     This contrast program comes from atduskgreg's shader example.
     See https://github.com/atduskgreg/Processing-Shader-Examples/
     """
     self.contrast_program = compileProgram(
         compileShader('''
             uniform sampler2D src_tex_unit0;
             uniform float contrast;
             void main() {
                 vec3 color = vec3(texture2D(src_tex_unit0, gl_TexCoord[0].st));
                 const vec3 LumCoeff = vec3(0.2125, 0.7154, 0.0721);
         
                 vec3 AvgLumin = vec3(0.5, 0.5, 0.5);
         
                 vec3 intensity = vec3(dot(color, LumCoeff));
         
                 // could substitute a uniform for this 1. and have variable saturation
                 vec3 satColor = mix(intensity, color, 1.);
                 vec3 conColor = mix(AvgLumin, satColor, contrast);
         
                 gl_FragColor = vec4(conColor, 1);
             }
         ''',gl.GL_FRAGMENT_SHADER))
     self.texture_loc = gl.glGetUniformLocation(self.contrast_program, "src_tex_unit0")
     self.contrast_loc = gl.glGetUniformLocation(self.contrast_program, "contrast")
     self.contrast = contrast
Пример #2
0
def draw_dots(xs,ys,zs,colors=None):
    """Python method for drawing dots.  May be replaced by a faster C version."""
    if not (len(xs) == len(ys) == len(zs)):
        raise ValueError("All input arguments must be same length")
    gl.glBegin(gl.GL_POINTS)
    for i in xrange(len(xs)):
        if colors is not None:
            gl.glColor4f( *colors[i] )
        gl.glVertex3f(xs[i],ys[i],zs[i])
    gl.glEnd()
Пример #3
0
    def calculate_bit_depth_dependencies(self):
        """Calculate a number of parameters dependent on bit depth."""
        bit_depth_warning = False
        p = self.parameters # shorthand

        red_bits = gl.glGetIntegerv( gl.GL_RED_BITS )
        green_bits = gl.glGetIntegerv( gl.GL_GREEN_BITS )
        blue_bits = gl.glGetIntegerv( gl.GL_BLUE_BITS )
        min_bits = min( (red_bits,green_bits,blue_bits) )
        if min_bits < p.bit_depth:
            logger = logging.getLogger('VisionEgg.Gratings')
            logger.warning("Requested bit depth of %d in "
                           "LuminanceGratingCommon, which is "
                           "greater than your current OpenGL context "
                           "supports (%d)."% (p.bit_depth,min_bits))
        self.gl_internal_format = gl.GL_LUMINANCE
        self.format = gl.GL_LUMINANCE
        self.gl_type, self.numpy_dtype, self.max_int_val = _get_type_info( p.bit_depth )
        self.cached_bit_depth = p.bit_depth
Пример #4
0
    def calculate_bit_depth_dependencies(self):
        """Calculate a number of parameters dependent on bit depth."""
        bit_depth_warning = False
        p = self.parameters  # shorthand

        red_bits = gl.glGetIntegerv(gl.GL_RED_BITS)
        green_bits = gl.glGetIntegerv(gl.GL_GREEN_BITS)
        blue_bits = gl.glGetIntegerv(gl.GL_BLUE_BITS)
        min_bits = min((red_bits, green_bits, blue_bits))
        if min_bits < p.bit_depth:
            logger = logging.getLogger("VisionEgg.Gratings")
            logger.warning(
                "Requested bit depth of %d in "
                "LuminanceGratingCommon, which is "
                "greater than your current OpenGL context "
                "supports (%d)." % (p.bit_depth, min_bits)
            )
        self.gl_internal_format = gl.GL_LUMINANCE
        self.format = gl.GL_LUMINANCE
        self.gl_type, self.numpy_dtype, self.max_int_val = _get_type_info(p.bit_depth)
        self.cached_bit_depth = p.bit_depth
Пример #5
0
 def calculate_bit_depth_dependencies(self):
     """Calculate a number of parameters dependent on bit depth."""
     p = self.parameters # shorthand
     alpha_bit_depth = gl.glGetIntegerv( gl.GL_ALPHA_BITS )
     if alpha_bit_depth < p.bit_depth:
         logger = logging.getLogger('VisionEgg.Gratings')
         logger.warning("Requested bit depth of %d, which is "
                        "greater than your current OpenGL context "
                        "supports (%d)."% (p.bit_depth,min_bits))
     self.gl_internal_format = gl.GL_ALPHA
     self.format = gl.GL_ALPHA
     self.gl_type, self.numpy_dtype, self.max_int_val = _get_type_info( p.bit_depth )
     self.cached_bit_depth = p.bit_depth
Пример #6
0
 def calculate_bit_depth_dependencies(self):
     """Calculate a number of parameters dependent on bit depth."""
     p = self.parameters  # shorthand
     alpha_bit_depth = gl.glGetIntegerv(gl.GL_ALPHA_BITS)
     if alpha_bit_depth < p.bit_depth:
         logger = logging.getLogger("VisionEgg.Gratings")
         logger.warning(
             "Requested bit depth of %d, which is "
             "greater than your current OpenGL context "
             "supports (%d)." % (p.bit_depth, min_bits)
         )
     self.gl_internal_format = gl.GL_ALPHA
     self.format = gl.GL_ALPHA
     self.gl_type, self.numpy_dtype, self.max_int_val = _get_type_info(p.bit_depth)
     self.cached_bit_depth = p.bit_depth
Пример #7
0
    def draw(self):
        p = self.parameters # shorthand
        if p.center is not None:
            if not hasattr(VisionEgg.config,"_GAVE_CENTER_DEPRECATION"):
                logger = logging.getLogger('VisionEgg.MoreStimuli')
                logger.warning("Specifying Target2D by deprecated "
                               "'center' parameter deprecated.  Use "
                               "'position' parameter instead.  (Allows "
                               "use of 'anchor' parameter to set to "
                               "other values.)")
                VisionEgg.config._GAVE_CENTER_DEPRECATION = 1
            p.anchor = 'center'
            p.position = p.center[0], p.center[1] # copy values (don't copy ref to tuple)
        if p.on:
            # calculate center
            center = VisionEgg._get_center(p.position,p.anchor,p.size)
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glPushMatrix()
            gl.glTranslate(center[0],center[1],0.0)
            gl.glRotate(p.orientation,0.0,0.0,1.0)

            if len(p.color)==3:
                gl.glColor3f(*p.color)
            elif len(p.color)==4:
                gl.glColor4f(*p.color)
            gl.glDisable(gl.GL_DEPTH_TEST)
            gl.glDisable(gl.GL_TEXTURE_2D)
            gl.glBlendFunc(gl.GL_SRC_ALPHA,gl.GL_ONE_MINUS_SRC_ALPHA)
            gl.glEnable(gl.GL_BLEND)

            w = p.size[0]/2.0
            h = p.size[1]/2.0

            gl.glBegin(gl.GL_QUADS)
            gl.glVertex3f(-w,-h, 0.0)
            gl.glVertex3f( w,-h, 0.0)
            gl.glVertex3f( w, h, 0.0)
            gl.glVertex3f(-w, h, 0.0)
            gl.glEnd() # GL_QUADS

            if p.anti_aliasing:
                if not self._gave_alpha_warning:
                    if len(p.color) > 3 and p.color[3] != 1.0:
                        logger = logging.getLogger('VisionEgg.MoreStimuli')
                        logger.warning("The parameter anti_aliasing is "
                                       "set to true in the Target2D "
                                       "stimulus class, but the color "
                                       "parameter specifies an alpha "
                                       "value other than 1.0.  To "
                                       "acheive anti-aliasing, ensure "
                                       "that the alpha value for the "
                                       "color parameter is 1.0.")
                        self._gave_alpha_warning = 1

                # We've already drawn a filled polygon (aliased), now
                # redraw the outline of the polygon (with
                # anti-aliasing).  (Using GL_POLYGON_SMOOTH results in
                # artifactual lines where triangles were joined to
                # create quad, at least on some OpenGL
                # implementations.)

                # Calculate coverage value for each pixel of outline
                # and store as alpha
                gl.glEnable(gl.GL_LINE_SMOOTH)
                # Now specify how to use the alpha value
                gl.glBlendFunc(gl.GL_SRC_ALPHA,gl.GL_ONE_MINUS_SRC_ALPHA)
                gl.glEnable(gl.GL_BLEND)

                # Draw a second polygon in line mode, so the edges are anti-aliased
                gl.glPolygonMode(gl.GL_FRONT_AND_BACK,gl.GL_LINE)
                gl.glBegin(gl.GL_QUADS)
                gl.glVertex3f(-w,-h, 0.0);
                gl.glVertex3f( w,-h, 0.0);
                gl.glVertex3f( w, h, 0.0);
                gl.glVertex3f(-w, h, 0.0);
                gl.glEnd() # GL_QUADS

                # Set the polygon mode back to fill mode
                gl.glPolygonMode(gl.GL_FRONT_AND_BACK,gl.GL_FILL)
                gl.glDisable(gl.GL_LINE_SMOOTH)
            gl.glPopMatrix()
Пример #8
0
    def draw(self):
        p = self.parameters # Shorthand
        if p.on:
            # Calculate center
            center = VisionEgg._get_center(p.position,p.anchor,p.size)
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glPushMatrix()
            gl.glTranslate(center[0],center[1],0.0)
            gl.glRotate(-p.orientation,0.0,0.0,1.0)

            if len(p.color)==3:
                gl.glColor3f(*p.color)
            elif len(p.color)==4:
                gl.glColor4f(*p.color)
            gl.glDisable(gl.GL_DEPTH_TEST)
            gl.glDisable(gl.GL_TEXTURE_2D)
            gl.glBlendFunc(gl.GL_SRC_ALPHA,gl.GL_ONE_MINUS_SRC_ALPHA)
            gl.glEnable(gl.GL_BLEND)

            w = p.size[0]/2.0
            h = p.size[1]/2.0

            gl.glBegin(gl.GL_QUADS) # Draw Rectangle
            gl.glVertex3f( 0.25*w, h, 0.0)
            gl.glVertex3f(-w, h, 0.0)
            gl.glVertex3f(-w,-h, 0.0)
            gl.glVertex3f( 0.25*w, -h, 0.0)
            gl.glEnd() # GL_QUADS

            gl.glBegin(gl.GL_TRIANGLES) # Draw Triangle
            gl.glVertex3f( 1.00*w, 0.0*h, 0.0) # Top
            gl.glVertex3f( 0.25*w,-3.0*h, 0.0)
            gl.glVertex3f( 0.25*w, 3.0*h, 0.0)
            gl.glEnd() # GL_QUADS

            if p.anti_aliasing:
                if not self._gave_alpha_warning:
                    if len(p.color) > 3 and p.color[3] != 1.0:
                        logger = logging.getLogger('VisionEgg.Arrow')
                        logger.warning("The parameter anti_aliasing is "
                                       "set to true in the Arrow "
                                       "stimulus class, but the color "
                                       "parameter specifies an alpha "
                                       "value other than 1.0.  To "
                                       "acheive anti-aliasing, ensure "
                                       "that the alpha value for the "
                                       "color parameter is 1.0.")
                        self._gave_alpha_warning = 1

                # We've already drawn a filled polygon (aliased), now redraw
                # the outline of the polygon (with anti-aliasing). (Using
                # GL_POLYGON_SMOOTH results in artifactual lines where
                # triangles were joined to create quad, at least on some OpenGL
                # implementations.)

                # Calculate coverage value for each pixel of outline
                # and store as alpha
                gl.glEnable(gl.GL_LINE_SMOOTH)
                # Now specify how to use the alpha value
                gl.glBlendFunc(gl.GL_SRC_ALPHA,gl.GL_ONE_MINUS_SRC_ALPHA)
                gl.glEnable(gl.GL_BLEND)

                # Draw a second polygon in line mode, so the edges are anti-aliased
                gl.glPolygonMode(gl.GL_FRONT_AND_BACK,gl.GL_LINE)
                gl.glBegin(gl.GL_QUADS)

                gl.glVertex3f( 0.25*w, h, 0.0) # Draw Rectangle
                gl.glVertex3f(-w, h, 0.0)
                gl.glVertex3f(-w,-h, 0.0)
                gl.glVertex3f( 0.25*w, -h, 0.0)
                gl.glVertex3f( 1.00*w, 0.0*h, 0.0) # Draw Triangle
                gl.glVertex3f( 0.25*w,-3.0*h, 0.0)
                gl.glVertex3f( 0.25*w, 3.0*h, 0.0)
                gl.glEnd() # GL_QUADS

                # Set the polygon mode back to fill mode
                gl.glPolygonMode(gl.GL_FRONT_AND_BACK,gl.GL_FILL)
                gl.glDisable(gl.GL_LINE_SMOOTH)
            gl.glPopMatrix()
Пример #9
0
    def draw(self):
        # XXX This method is not speed-optimized. I just wrote it to
        # get the job done. (Nonetheless, it seems faster than the C
        # version commented out above.)

        p = self.parameters  # shorthand
        if p.center is not None:
            if not hasattr(VisionEgg.config, "_GAVE_CENTER_DEPRECATION"):
                logger = logging.getLogger('VisionEgg.Dots')
                logger.warning("Specifying DotArea2D by deprecated "
                               "'center' parameter deprecated.  Use "
                               "'position' parameter instead.  (Allows "
                               "use of 'anchor' parameter to set to "
                               "other values.)")
                VisionEgg.config._GAVE_CENTER_DEPRECATION = 1
            p.anchor = 'center'
            p.position = p.center[0], p.center[
                1]  # copy values (don't copy ref to tuple)
        if p.on:
            # calculate center
            center = VisionEgg._get_center(p.position, p.anchor, p.size)

            if p.anti_aliasing:
                if len(p.color) == 4 and not self._gave_alpha_warning:
                    if p.color[3] != 1.0:
                        logger = logging.getLogger('VisionEgg.Dots')
                        logger.warning("The parameter anti_aliasing is "
                                       "set to true in the DotArea2D "
                                       "stimulus class, but the color "
                                       "parameter specifies an alpha "
                                       "value other than 1.0.  To "
                                       "acheive the best anti-aliasing, "
                                       "ensure that the alpha value for "
                                       "the color parameter is 1.0.")
                        self._gave_alpha_warning = 1
                gl.glEnable(gl.GL_POINT_SMOOTH)
                # allow max_alpha value to control blending
                gl.glEnable(gl.GL_BLEND)
                gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
            else:
                gl.glDisable(gl.GL_BLEND)

            now_sec = VisionEgg.time_func()
            if self.start_times_sec is not None:
                # compute extinct dots and generate new positions
                replace_indices = Numeric.nonzero(
                    Numeric.greater(now_sec - self.start_times_sec,
                                    p.dot_lifespan_sec))
                Numeric.put(self.start_times_sec, replace_indices, now_sec)

                new_x_positions = RandomArray.uniform(0.0, 1.0,
                                                      (len(replace_indices), ))
                Numeric.put(self.x_positions, replace_indices, new_x_positions)

                new_y_positions = RandomArray.uniform(0.0, 1.0,
                                                      (len(replace_indices), ))
                Numeric.put(self.y_positions, replace_indices, new_y_positions)

                new_random_directions_radians = RandomArray.uniform(
                    0.0, 2 * math.pi, (len(replace_indices), ))
                Numeric.put(self.random_directions_radians, replace_indices,
                            new_random_directions_radians)
            else:
                # initialize dot extinction values to random (uniform) distribution
                self.start_times_sec = RandomArray.uniform(
                    now_sec - p.dot_lifespan_sec, now_sec,
                    (self.constant_parameters.num_dots, ))

            signal_num_dots = int(
                round(p.signal_fraction * self.constant_parameters.num_dots))
            time_delta_sec = now_sec - self.last_time_sec
            self.last_time_sec = now_sec  # reset for next loop
            x_increment_normalized = math.cos(
                p.signal_direction_deg / 180.0 * math.pi
            ) * p.velocity_pixels_per_sec / p.size[0] * time_delta_sec
            y_increment_normalized = -math.sin(
                p.signal_direction_deg / 180.0 * math.pi
            ) * p.velocity_pixels_per_sec / p.size[1] * time_delta_sec
            self.x_positions[:signal_num_dots] += x_increment_normalized
            self.y_positions[:signal_num_dots] += y_increment_normalized

            num_random_dots = self.constant_parameters.num_dots - signal_num_dots
            random_x_increment_normalized = Numeric.cos(
                self.random_directions_radians[signal_num_dots:]
            ) * p.velocity_pixels_per_sec / p.size[0] * time_delta_sec
            random_y_increment_normalized = -Numeric.sin(
                self.random_directions_radians[signal_num_dots:]
            ) * p.velocity_pixels_per_sec / p.size[1] * time_delta_sec
            self.x_positions[signal_num_dots:] += random_x_increment_normalized
            self.y_positions[signal_num_dots:] += random_y_increment_normalized

            self.x_positions = Numeric.fmod(self.x_positions, 1.0)  # wrap
            self.y_positions = Numeric.fmod(self.y_positions, 1.0)

            self.x_positions = Numeric.fmod(self.x_positions + 1,
                                            1.0)  # wrap again for values < 1
            self.y_positions = Numeric.fmod(self.y_positions + 1, 1.0)

            xs = (self.x_positions - 0.5) * p.size[0] + center[0]
            ys = (self.y_positions - 0.5) * p.size[1] + center[1]

            if len(p.color) == 3:
                gl.glColor3f(*p.color)
            elif len(p.color) == 4:
                gl.glColor4f(*p.color)
            gl.glPointSize(p.dot_size)

            # Clear the modeview matrix
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glPushMatrix()

            gl.glDisable(gl.GL_TEXTURE_2D)

            if p.depth is None:
                depth = 0.0
            else:
                gl.glEnable(gl.GL_DEPTH_TEST)
                depth = p.depth
            zs = (depth, ) * len(xs)  # make N tuple with repeat value of depth
            draw_dots(xs, ys, zs)
            if p.anti_aliasing:
                gl.glDisable(gl.GL_POINT_SMOOTH)  # turn off
            gl.glPopMatrix()
Пример #10
0
 def update(self):
     # install pixel shader for adjusting texture contrast
     gl.glUseProgram(self.contrast_program)
     gl.glUniform1i(self.texture_loc, 0)
     gl.glUniform1f(self.contrast_loc, self.contrast)
Пример #11
0
    def draw(self):
        p = self.parameters # shorthand
        if p.on:
            if p.mask:
                gl.glActiveTextureARB(gl.GL_TEXTURE0_ARB)
            if p.depth_test:
                gl.glEnable(gl.GL_DEPTH_TEST)
            else:
                gl.glDisable(gl.GL_DEPTH_TEST)
            if p.polygon_offset_enabled:
                gl.glEnable(gl.GL_POLYGON_OFFSET_EXT)
                gl.glPolygonOffset(p.polygon_offset_factor, p.polygon_offset_units)
            gl.glBindTexture(gl.GL_TEXTURE_1D,self._texture_object_id)
            gl.glEnable(gl.GL_TEXTURE_1D)
            gl.glDisable(gl.GL_TEXTURE_2D)
            if p.bit_depth != self.cached_bit_depth:
                self.calculate_bit_depth_dependencies()

            # allow max_alpha value to control blending
            gl.glEnable( gl.GL_BLEND )
            gl.glBlendFunc( gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA )

            if p.color2:
                gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_BLEND)
                gl.glTexEnvfv(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_COLOR, p.color2)
                ## alpha is ignored because the texture base internal format is luminance
            else:
                gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_MODULATE)

            if p.t0_time_sec_absolute is None and not p.ignore_time:
                p.t0_time_sec_absolute = VisionEgg.time_func()

            w = p.size[0]
            inc = w/float(p.num_samples)
            if p.ignore_time:
                phase = p.phase_at_t0
            else:
                t_var = VisionEgg.time_func() - p.t0_time_sec_absolute
                phase = t_var*p.temporal_freq_hz*-360.0 + p.phase_at_t0
            if p.recalculate_phase_tolerance is None or abs(self._last_phase - phase) > p.recalculate_phase_tolerance:
                self._last_phase = phase # we're re-drawing the phase at this angle
                floating_point_sin = numpy.sin(2.0*math.pi*p.spatial_freq*numpy.arange(0.0,w,inc,dtype=numpy.float)+(phase/180.0*math.pi))*0.5*p.contrast+p.pedestal
                floating_point_sin = numpy.clip(floating_point_sin,0.0,1.0) # allow square wave generation if contrast > 1
                texel_data = (floating_point_sin*self.max_int_val).astype(self.numpy_dtype).tostring()

                gl.glTexSubImage1D(gl.GL_TEXTURE_1D, # target
                                   0,                # level
                                   0,                # x offset
                                   p.num_samples,    # width
                                   self.format,      # format of new texel data
                                   self.gl_type,     # type of new texel data
                                   texel_data)       # new texel data

            # in the case of only color1,
            # the texel data multiplies color1 to produce a color

            # with color2,
            # the texel data linearly interpolates between color1 and color2

            gl.glColor4f(p.color1[0],p.color1[1],p.color1[2],p.max_alpha)

            if p.mask:
                p.mask.draw_masked_quad_3d(0.0,1.0,0.0,1.0, # for texture coordinates
                                           p.lowerleft,p.lowerright,p.upperright,p.upperleft)
            else:
                # draw unmasked quad
                gl.glBegin(gl.GL_QUADS)

                gl.glTexCoord2f(0.0,0.0)
                gl.glVertex(*p.lowerleft)

                gl.glTexCoord2f(1.0,0.0)
                gl.glVertex(*p.lowerright)

                gl.glTexCoord2f(1.0,1.0)
                gl.glVertex(*p.upperright)

                gl.glTexCoord2f(0.0,1.0)
                gl.glVertex(*p.upperleft)
                gl.glEnd() # GL_QUADS

            gl.glDisable(gl.GL_TEXTURE_1D)
            if p.polygon_offset_enabled:
                gl.glDisable(gl.GL_POLYGON_OFFSET_EXT)
Пример #12
0
    def draw(self):
        p = self.parameters  # shorthand
        if p.on:
            # calculate center
            center = VisionEgg._get_center(p.position, p.anchor, p.size)
            if p.mask:
                gl.glActiveTextureARB(gl.GL_TEXTURE0_ARB)
            gl.glBindTexture(gl.GL_TEXTURE_1D, self._texture_object_id)

            gl.glEnable(gl.GL_TEXTURE_1D)
            gl.glDisable(gl.GL_TEXTURE_2D)
            if p.bit_depth != self.cached_bit_depth:
                self.calculate_bit_depth_dependencies()

            # Clear the modeview matrix
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glPushMatrix()

            # Rotate about the center of the texture
            gl.glTranslate(center[0], center[1], 0)
            gl.glRotate(p.orientation, 0, 0, 1)

            if p.depth is None:
                gl.glDisable(gl.GL_DEPTH_TEST)
                depth = 0.0
            else:
                gl.glEnable(gl.GL_DEPTH_TEST)
                depth = p.depth

            # allow max_alpha value to control blending
            gl.glEnable(gl.GL_BLEND)
            gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

            if p.color2:
                gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_BLEND)
                gl.glTexEnvfv(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_COLOR, p.color2)
                ## alpha is ignored because the texture base internal format is luminance
            else:
                gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_MODULATE)

            if p.t0_time_sec_absolute is None and not p.ignore_time:
                p.t0_time_sec_absolute = VisionEgg.time_func()

            w = p.size[0]
            inc = w / float(p.num_samples)
            if p.ignore_time:
                phase = p.phase_at_t0
            else:
                t_var = VisionEgg.time_func() - p.t0_time_sec_absolute
                phase = t_var * p.temporal_freq_hz * -360.0 + p.phase_at_t0
            if p.recalculate_phase_tolerance is None or abs(self._last_phase - phase) > p.recalculate_phase_tolerance:
                self._last_phase = phase  # we're re-drawing the phase at this angle
                floating_point_sin = (
                    numpy.sin(
                        2.0 * math.pi * p.spatial_freq * numpy.arange(0.0, w, inc, dtype=numpy.float)
                        + (phase / 180.0 * math.pi)
                    )
                    * 0.5
                    * p.contrast
                    + p.pedestal
                )
                floating_point_sin = numpy.clip(
                    floating_point_sin, 0.0, 1.0
                )  # allow square wave generation if contrast > 1
                texel_data = (floating_point_sin * self.max_int_val).astype(self.numpy_dtype)
                # PyOpenGL 2.0.1.09 has a bug, so use our own wrapper
                _vegl.veglTexSubImage1D(
                    gl.GL_TEXTURE_1D,  # target
                    0,  # level
                    0,  # x offset
                    p.num_samples,  # width
                    self.format,  # format of new texel data
                    self.gl_type,  # type of new texel data
                    texel_data,
                )  # new texel data
                if 0:
                    compare_array = numpy.empty(texel_data.shape, dtype=texel_data.dtype)
                    pixels = _vegl.veglGetTexImage(
                        gl.GL_TEXTURE_1D,  # target
                        0,  # level
                        self.format,  # format
                        self.gl_type,  # type
                        compare_array,
                    )
                    assert numpy.allclose(compare_array, texel_data)

            h_w = p.size[0] / 2.0
            h_h = p.size[1] / 2.0

            l = -h_w
            r = h_w
            b = -h_h
            t = h_h

            # in the case of only color1,
            # the texel data multiplies color1 to produce a color

            # with color2,
            # the texel data linearly interpolates between color1 and color2

            gl.glColor4f(p.color1[0], p.color1[1], p.color1[2], p.max_alpha)

            if p.mask:
                p.mask.draw_masked_quad(
                    0.0,
                    1.0,
                    0.0,
                    1.0,  # l,r,b,t for texture coordinates
                    l,
                    r,
                    b,
                    t,  # l,r,b,t in eye coordinates
                    depth,
                )  # also in eye coordinates
            else:
                # draw unmasked quad
                gl.glBegin(gl.GL_QUADS)

                gl.glTexCoord2f(0.0, 0.0)
                gl.glVertex3f(l, b, depth)

                gl.glTexCoord2f(1.0, 0.0)
                gl.glVertex3f(r, b, depth)

                gl.glTexCoord2f(1.0, 1.0)
                gl.glVertex3f(r, t, depth)

                gl.glTexCoord2f(0.0, 1.0)
                gl.glVertex3f(l, t, depth)
                gl.glEnd()  # GL_QUADS

            gl.glDisable(gl.GL_TEXTURE_1D)
            gl.glPopMatrix()
Пример #13
0
    def draw(self):
        # XXX This method is not speed-optimized. I just wrote it to
        # get the job done. (Nonetheless, it seems faster than the C
        # version commented out above.)

        p = self.parameters # shorthand

        now_sec = VisionEgg.time_func()
        if self.start_times_sec is not None:
            # compute extinct dots and generate new positions
            replace_indices = Numeric.nonzero( Numeric.greater( now_sec - self.start_times_sec, p.dot_lifespan_sec) )
            Numeric.put( self.start_times_sec, replace_indices, now_sec )

            new_centers = np.random.standard_normal((3,len(replace_indices)))
            for i in range(3):
                Numeric.put( self.centers[i,:], replace_indices, new_centers[i,:] )
        else:
            # initialize dot extinction values to random (uniform) distribution
            self.start_times_sec = RandomArray.uniform( now_sec - p.dot_lifespan_sec, now_sec,
                                                        (self.constant_parameters.num_dots,))

        time_delta_sec = now_sec - self.last_time_sec
        self.last_time_sec = now_sec # reset for next loop
        self.centers = self.centers + np.array(p.signal_vec)[:,np.newaxis]*time_delta_sec

        xyz = self.centers*p.start_position_variance + np.array(p.start_position_mean)[:,np.newaxis]
        xs = xyz[0,:]
        ys = xyz[1,:]
        zs = xyz[2,:]

        if p.on:
            gl.glEnable( gl.GL_POINT_SMOOTH )
            # allow max_alpha value to control blending
            gl.glEnable( gl.GL_BLEND )
            gl.glBlendFunc( gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA )

            gl.glPointSize(p.dot_size)

            # Clear the modeview matrix
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glPushMatrix()

            gl.glDisable(gl.GL_TEXTURE_2D)

            draw_dots(xs,ys,zs,self.colors)
            gl.glDisable( gl.GL_POINT_SMOOTH ) # turn off
            gl.glPopMatrix()
Пример #14
0
    def draw(self):
        # XXX This method is not speed-optimized. I just wrote it to
        # get the job done. (Nonetheless, it seems faster than the C
        # version commented out above.)

        p = self.parameters # shorthand
        if p.center is not None:
            if not hasattr(VisionEgg.config,"_GAVE_CENTER_DEPRECATION"):
                logger = logging.getLogger('VisionEgg.Dots')
                logger.warning("Specifying DotArea2D by deprecated "
                               "'center' parameter deprecated.  Use "
                               "'position' parameter instead.  (Allows "
                               "use of 'anchor' parameter to set to "
                               "other values.)")
                VisionEgg.config._GAVE_CENTER_DEPRECATION = 1
            p.anchor = 'center'
            p.position = p.center[0], p.center[1] # copy values (don't copy ref to tuple)
        if p.on:
            # calculate center
            center = VisionEgg._get_center(p.position,p.anchor,p.size)

            if p.anti_aliasing:
                if len(p.color) == 4 and not self._gave_alpha_warning:
                    if p.color[3] != 1.0:
                        logger = logging.getLogger('VisionEgg.Dots')
                        logger.warning("The parameter anti_aliasing is "
                                       "set to true in the DotArea2D "
                                       "stimulus class, but the color "
                                       "parameter specifies an alpha "
                                       "value other than 1.0.  To "
                                       "acheive the best anti-aliasing, "
                                       "ensure that the alpha value for "
                                       "the color parameter is 1.0.")
                        self._gave_alpha_warning = 1
                gl.glEnable( gl.GL_POINT_SMOOTH )
                # allow max_alpha value to control blending
                gl.glEnable( gl.GL_BLEND )
                gl.glBlendFunc( gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA )
            else:
                gl.glDisable( gl.GL_BLEND )

            now_sec = VisionEgg.time_func()
            if self.start_times_sec is not None:
                # compute extinct dots and generate new positions
                replace_indices = Numeric.nonzero( Numeric.greater( now_sec - self.start_times_sec, p.dot_lifespan_sec) )
                Numeric.put( self.start_times_sec, replace_indices, now_sec )

                new_x_positions = RandomArray.uniform(0.0,1.0,
                                                      (len(replace_indices),))
                Numeric.put( self.x_positions, replace_indices, new_x_positions )

                new_y_positions = RandomArray.uniform(0.0,1.0,
                                                      (len(replace_indices),))
                Numeric.put( self.y_positions, replace_indices, new_y_positions )

                new_random_directions_radians = RandomArray.uniform(0.0,2*math.pi,
                                                                    (len(replace_indices),))
                Numeric.put( self.random_directions_radians, replace_indices, new_random_directions_radians )
            else:
                # initialize dot extinction values to random (uniform) distribution
                self.start_times_sec = RandomArray.uniform( now_sec - p.dot_lifespan_sec, now_sec,
                                                            (self.constant_parameters.num_dots,))

            signal_num_dots = int(round(p.signal_fraction * self.constant_parameters.num_dots))
            time_delta_sec = now_sec - self.last_time_sec
            self.last_time_sec = now_sec # reset for next loop
            x_increment_normalized =  math.cos(p.signal_direction_deg/180.0*math.pi) * p.velocity_pixels_per_sec / p.size[0] * time_delta_sec
            y_increment_normalized = -math.sin(p.signal_direction_deg/180.0*math.pi) * p.velocity_pixels_per_sec / p.size[1] * time_delta_sec
            self.x_positions[:signal_num_dots] += x_increment_normalized
            self.y_positions[:signal_num_dots] += y_increment_normalized

            num_random_dots = self.constant_parameters.num_dots - signal_num_dots
            random_x_increment_normalized =  Numeric.cos(self.random_directions_radians[signal_num_dots:]) * p.velocity_pixels_per_sec / p.size[0] * time_delta_sec
            random_y_increment_normalized = -Numeric.sin(self.random_directions_radians[signal_num_dots:]) * p.velocity_pixels_per_sec / p.size[1] * time_delta_sec
            self.x_positions[signal_num_dots:] += random_x_increment_normalized
            self.y_positions[signal_num_dots:] += random_y_increment_normalized

            self.x_positions = Numeric.fmod( self.x_positions, 1.0 ) # wrap
            self.y_positions = Numeric.fmod( self.y_positions, 1.0 )

            self.x_positions = Numeric.fmod( self.x_positions+1, 1.0 ) # wrap again for values < 1
            self.y_positions = Numeric.fmod( self.y_positions+1, 1.0 )

            xs = (self.x_positions - 0.5) * p.size[0] + center[0]
            ys = (self.y_positions - 0.5) * p.size[1] + center[1]

            if len(p.color)==3:
                gl.glColor3f(*p.color)
            elif len(p.color)==4:
                gl.glColor4f(*p.color)
            gl.glPointSize(p.dot_size)

            # Clear the modeview matrix
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glPushMatrix()

            gl.glDisable(gl.GL_TEXTURE_2D)

            if p.depth is None:
                depth = 0.0
            else:
                gl.glEnable(gl.GL_DEPTH_TEST)
                depth = p.depth
            zs = (depth,)*len(xs) # make N tuple with repeat value of depth
            draw_dots(xs,ys,zs)
            if p.anti_aliasing:
                gl.glDisable( gl.GL_POINT_SMOOTH ) # turn off
            gl.glPopMatrix()
Пример #15
0
    def draw(self):
        p = self.parameters # shorthand

        width = self.size[0]
        height = self.size[1]

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glPushMatrix()
        gl.glLoadIdentity()
        gl.glOrtho(-width, width, -height, height, -200, 200)
        gl.glScalef(2, -2, 2)
        gl.glMatrixMode(gl.GL_MODELVIEW)

        if len(p.color)==3:
            gl.glColor3f(*p.color)
        elif len(p.color)==4:
            gl.glColor4f(*p.color)

        # this is necessary for the antialiasing
        gl.glDisable(gl.GL_DEPTH_TEST)
        gl.glDisable(gl.GL_TEXTURE_2D)
        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glBlendFunc(gl.GL_SRC_ALPHA,gl.GL_ONE_MINUS_SRC_ALPHA)
        gl.glEnable(gl.GL_BLEND)
        gl.glLineWidth(p.line_width)

        # draw the polygon
        gl.glBegin(gl.GL_POLYGON)
        for point in p.points:
            gl.glVertex3f(point[0], point[1], 0.0)
        gl.glVertex3f(p.points[0][0], p.points[0][1], 0.0)
        gl.glEnd() # GL_LINE_STRIP

        gl.glDisable(gl.GL_LINE_SMOOTH)
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glPopMatrix()
Пример #16
0
    def draw(self):
        p = self.parameters  # shorthand
        if p.on:
            if p.mask:
                gl.glActiveTextureARB(gl.GL_TEXTURE0_ARB)
            if p.depth_test:
                gl.glEnable(gl.GL_DEPTH_TEST)
            else:
                gl.glDisable(gl.GL_DEPTH_TEST)
            if p.polygon_offset_enabled:
                gl.glEnable(gl.GL_POLYGON_OFFSET_EXT)
                gl.glPolygonOffset(p.polygon_offset_factor, p.polygon_offset_units)
            gl.glBindTexture(gl.GL_TEXTURE_1D, self._texture_object_id)
            gl.glEnable(gl.GL_TEXTURE_1D)
            gl.glDisable(gl.GL_TEXTURE_2D)
            if p.bit_depth != self.cached_bit_depth:
                self.calculate_bit_depth_dependencies()

            # allow max_alpha value to control blending
            gl.glEnable(gl.GL_BLEND)
            gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

            if p.color2:
                gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_BLEND)
                gl.glTexEnvfv(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_COLOR, p.color2)
                ## alpha is ignored because the texture base internal format is luminance
            else:
                gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_MODULATE)

            if p.t0_time_sec_absolute is None and not p.ignore_time:
                p.t0_time_sec_absolute = VisionEgg.time_func()

            w = p.size[0]
            inc = w / float(p.num_samples)
            if p.ignore_time:
                phase = p.phase_at_t0
            else:
                t_var = VisionEgg.time_func() - p.t0_time_sec_absolute
                phase = t_var * p.temporal_freq_hz * -360.0 + p.phase_at_t0
            if p.recalculate_phase_tolerance is None or abs(self._last_phase - phase) > p.recalculate_phase_tolerance:
                self._last_phase = phase  # we're re-drawing the phase at this angle
                floating_point_sin = (
                    numpy.sin(
                        2.0 * math.pi * p.spatial_freq * numpy.arange(0.0, w, inc, dtype=numpy.float)
                        + (phase / 180.0 * math.pi)
                    )
                    * 0.5
                    * p.contrast
                    + p.pedestal
                )
                floating_point_sin = numpy.clip(
                    floating_point_sin, 0.0, 1.0
                )  # allow square wave generation if contrast > 1
                texel_data = (floating_point_sin * self.max_int_val).astype(self.numpy_dtype).tostring()

                gl.glTexSubImage1D(
                    gl.GL_TEXTURE_1D,  # target
                    0,  # level
                    0,  # x offset
                    p.num_samples,  # width
                    self.format,  # format of new texel data
                    self.gl_type,  # type of new texel data
                    texel_data,
                )  # new texel data

            # in the case of only color1,
            # the texel data multiplies color1 to produce a color

            # with color2,
            # the texel data linearly interpolates between color1 and color2

            gl.glColor4f(p.color1[0], p.color1[1], p.color1[2], p.max_alpha)

            if p.mask:
                p.mask.draw_masked_quad_3d(
                    0.0, 1.0, 0.0, 1.0, p.lowerleft, p.lowerright, p.upperright, p.upperleft  # for texture coordinates
                )
            else:
                # draw unmasked quad
                gl.glBegin(gl.GL_QUADS)

                gl.glTexCoord2f(0.0, 0.0)
                gl.glVertex(*p.lowerleft)

                gl.glTexCoord2f(1.0, 0.0)
                gl.glVertex(*p.lowerright)

                gl.glTexCoord2f(1.0, 1.0)
                gl.glVertex(*p.upperright)

                gl.glTexCoord2f(0.0, 1.0)
                gl.glVertex(*p.upperleft)
                gl.glEnd()  # GL_QUADS

            gl.glDisable(gl.GL_TEXTURE_1D)
            if p.polygon_offset_enabled:
                gl.glDisable(gl.GL_POLYGON_OFFSET_EXT)
Пример #17
0
 def __del__(self):
     gl.glDeleteTextures([self._texture_object_id])
Пример #18
0
        def draw(self):
            if self.parameters.on:
                gl.glDisable(gl.GL_TEXTURE_2D)
                gl.glDisable(gl.GL_DEPTH_TEST)

                gl.glMatrixMode(gl.GL_MODELVIEW)
                gl.glPushMatrix()
                gl.glTranslate(self.parameters.lowerleft[0],
                               self.parameters.lowerleft[1], 0.0)
                gl.glRotate(self.parameters.orientation, 0.0, 0.0, 1.0)

                c = self.parameters.color
                if len(c) == 3:
                    gl.glColor3f(*c)
                elif len(c) == 4:
                    gl.glColor4f(*c)

                gl.glLineWidth(self.parameters.linewidth)

                if self.parameters.anti_aliasing:
                    gl.glEnable(gl.GL_BLEND)
                    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
                    gl.glEnable(gl.GL_LINE_SMOOTH)
                else:
                    gl.glDisable(gl.GL_BLEND)

    ##            # This code successfully draws a box...
    ##            gl.glBegin(gl.GL_QUADS)
    ##            gl.glVertex2f(0.0,0.0)
    ##            gl.glVertex2f(0.0,0.1)
    ##            gl.glVertex2f(0.1,0.1)
    ##            gl.glVertex2f(0.1,0.0)
    ##            gl.glEnd()

    # But this code does not draw the string!?!
                for char in self.parameters.text:
                    glut.glutStrokeCharacter(self.parameters.font, ord(char))
                gl.glPopMatrix()
Пример #19
0
 def draw(self):
     p = self.parameters
     if p.on:
         self._gl_color(*self._color)
         gl.glDisable(gl.GL_TEXTURE_2D)
         if p.depth_test:
             gl.glEnable(gl.GL_DEPTH_TEST)
         else:
             gl.glDisable(gl.GL_DEPTH_TEST)
         if p.blending_enabled:
             gl.glEnable(gl.GL_BLEND)
         else:
             gl.glDisable(gl.GL_BLEND)
         gl.glLineWidth(self._line_width)
         gl.glBegin(gl.GL_LINE_LOOP)
         for vertex in self._vertices:
             gl.glVertex(*vertex)
         gl.glEnd()
Пример #20
0
    def draw(self):
        p = self.parameters  # shorthand
        if p.center is not None:
            p.anchor = 'center'
            p.position = p.center[0], p.center[
                1]  # copy values (don't copy ref to tuple)
        if p.on:
            # calculate center
            center = VisionEgg._get_center(p.position, p.anchor, p.size)
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glPushMatrix()
            gl.glTranslate(center[0], center[1], 0.0)
            gl.glRotate(p.orientation, 0.0, 0.0, 1.0)

            if len(p.bgcolor) == 3:
                gl.glColor3f(*p.bgcolor)
            elif len(p.bgcolor) == 4:
                gl.glColor4f(*p.bgcolor)
            gl.glDisable(gl.GL_DEPTH_TEST)
            gl.glDisable(gl.GL_TEXTURE_2D)
            gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
            gl.glEnable(gl.GL_BLEND)

            w = p.size[0] / 2.0  #grid half-size
            h = p.size[1] / 2.0
            m = p.size[0] / p.grid[0]  #cell size
            n = p.size[1] / p.grid[1]
            i = range(p.grid[0])  #grid index
            j = range(p.grid[1])
            #draw colorful cell
            #           vertices_list = [((-w+column*m, h-(row+1)*n, 0.0),(-w+column*m, h-row*n, 0.0),\
            #                         (-w+(column+1)*m, h-row*n, 0.0),(-w+(column+1)*m, h-row*n, 0.0))\
            #                         for column in j for row in i]
            vertices_list = [((-w+column*m, h-(row+1)*n, 0.0),(-w+column*m, h-row*n, 0.0),\
                              (-w+(column+1)*m, h-row*n, 0.0),(-w+(column+1)*m, h-(row+1)*n, 0.0))\
                         for column in j for row in i]
            colors_list = [
                colormap(p.colorindex[row, column], color=p.cellcolor) * 4
                for column in j for row in i
            ]
            #flattening the vertices and colors
            vertices_flat = [
                num for tuple in vertices_list for vertex in tuple
                for num in vertex
            ]
            colors_flat = [num for tuple in colors_list for num in tuple]
            vertices = np.array(vertices_flat)
            colors = np.array(colors_flat)
            vertices.shape = (-1, 3)
            colors.shape = (-1, 3)
            gl.glVertexPointerd(vertices)
            gl.glColorPointerd(colors)
            gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
            gl.glEnableClientState(gl.GL_COLOR_ARRAY)
            gl.glDisable(gl.GL_LIGHTING)
            gl.glDrawArrays(gl.GL_QUADS, 0, p.grid[0] * p.grid[1] * 4)

            #draw grid lines
            if p.drawline:
                if len(p.linecolor) == 3:
                    gl.glColor3f(*p.linecolor)
                elif len(p.linecolor) == 4:
                    gl.glColor4f(*p.linecolor)

                row_list = [((-w, h - i * n), (w, h - i * n))
                            for i in range(p.grid[1] + 1)]
                col_list = [((-w + i * m, h), (-w + i * m, -h))
                            for i in range(p.grid[0] + 1)]
                ver_row_flat = [
                    num for tuple in row_list for vertex in tuple
                    for num in vertex
                ]
                ver_col_flat = [
                    num for tuple in col_list for vertex in tuple
                    for num in vertex
                ]
                vertices_row = np.array(ver_row_flat)
                vertices_col = np.array(ver_col_flat)
                vertices_row.shape = (-1, 2)
                vertices_col.shape = (-1, 2)

                gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
                gl.glDisableClientState(gl.GL_COLOR_ARRAY)
                gl.glVertexPointerd(vertices_row)
                gl.glDrawArrays(gl.GL_LINES, 0, (p.grid[1] + 1) * 2)
                gl.glVertexPointerd(vertices_col)
                gl.glDrawArrays(gl.GL_LINES, 0, (p.grid[0] + 1) * 2)

#                gl.glBegin(gl.GL_LINES);
#                for i in range(p.grid[1] + 1):
#                    gl.glVertex2f(-w, h - i * n)
#                    gl.glVertex2f(w, h - i * n)
#                for i in range(p.grid[0] + 1):
#                    gl.glVertex2f(-w + i * m, h)
#                    gl.glVertex2f(-w + i * m, -h)
#                gl.glEnd();
            gl.glPopMatrix()
Пример #21
0
    def __init__(self,**kw):
        LuminanceGratingCommon.__init__(self,**kw)

        p = self.parameters # shorthand

        self._texture_object_id = gl.glGenTextures(1)
        if p.mask:
            gl.glActiveTextureARB(gl.GL_TEXTURE0_ARB)
        gl.glBindTexture(gl.GL_TEXTURE_1D,self._texture_object_id)

        # Do error-checking on texture to make sure it will load
        max_dim = gl.glGetIntegerv(gl.GL_MAX_TEXTURE_SIZE)
        if p.num_samples > max_dim:
            raise NumSamplesTooLargeError("Grating num_samples too large for video system.\nOpenGL reports maximum size of %d"%(max_dim,))

        self.calculate_bit_depth_dependencies()

        w = p.size[0]
        inc = w/float(p.num_samples)
        phase = 0.0 # this data won't get used - don't care about phase
        self._last_phase = phase
        floating_point_sin = numpy.sin(2.0*math.pi*p.spatial_freq*numpy.arange(0.0,w,inc,dtype=numpy.float)+(phase/180.0*math.pi))*0.5*p.contrast+p.pedestal
        floating_point_sin = numpy.clip(floating_point_sin,0.0,1.0) # allow square wave generation if contrast > 1
        texel_data = (floating_point_sin*self.max_int_val).astype(self.numpy_dtype).tostring()

        # Because the MAX_TEXTURE_SIZE method is insensitive to the current
        # state of the video system, another check must be done using
        # "proxy textures".
        gl.glTexImage1D(gl.GL_PROXY_TEXTURE_1D,            # target
                        0,                                 # level
                        self.gl_internal_format,           # video RAM internal format
                        p.num_samples,                     # width
                        0,                                 # border
                        self.format,                       # format of texel data
                        self.gl_type,                      # type of texel data
                        texel_data)                        # texel data (irrelevant for proxy)
        if gl.glGetTexLevelParameteriv(gl.GL_PROXY_TEXTURE_1D, # Need PyOpenGL >= 2.0
                                       0,
                                       gl.GL_TEXTURE_WIDTH) == 0:
            raise NumSamplesTooLargeError("Grating num_samples is too wide for your video system!")

        # If we got here, it worked and we can load the texture for real.
        gl.glTexImage1D(gl.GL_TEXTURE_1D,                  # target
                        0,                                 # level
                        self.gl_internal_format,           # video RAM internal format
                        p.num_samples,                     # width
                        0,                                 # border
                        self.format,                       # format of texel data
                        self.gl_type,                      # type of texel data
                        texel_data)                        # texel data

        # Set texture object defaults
        gl.glTexParameteri(gl.GL_TEXTURE_1D,gl.GL_TEXTURE_WRAP_S,gl.GL_CLAMP_TO_EDGE)
        gl.glTexParameteri(gl.GL_TEXTURE_1D,gl.GL_TEXTURE_WRAP_T,gl.GL_CLAMP_TO_EDGE)
        gl.glTexParameteri(gl.GL_TEXTURE_1D,gl.GL_TEXTURE_MAG_FILTER,gl.GL_LINEAR)
        gl.glTexParameteri(gl.GL_TEXTURE_1D,gl.GL_TEXTURE_MIN_FILTER,gl.GL_LINEAR)

        if p.color2 is not None:
            if VisionEgg.Core.gl_renderer == 'ATi Rage 128 Pro OpenGL Engine' and VisionEgg.Core.gl_version == '1.1 ATI-1.2.22':
                logger = logging.getLogger('VisionEgg.Gratings')
                logger.warning("Your video card and driver have known "
                               "bugs which prevent them from rendering "
                               "color gratings properly.")
Пример #22
0
 def _draw(self):
     p = self.parameters
     center = VisionEgg._get_center(p.position, p.anchor,
                                    (p.radius, p.radius))
     gl.glDisable(gl.GL_DEPTH_TEST)
     gl.glDisable(gl.GL_TEXTURE_2D)
     gl.glDisable(gl.GL_BLEND)
     gl.glColor(p.color)
     start, end = p.start, p.end
     if end < start:
         start -= 360.
     start, end = map(numpy.deg2rad, (start, end))
     frac = (end - start) / (2 * numpy.pi)
     num_triangles = float(p.num_triangles) * frac
     angles = numpy.linspace(start, end, num_triangles)
     verts = numpy.zeros((num_triangles, 2))
     verts[:, 0] = center[0] + p.radius * numpy.cos(angles)
     verts[:, 1] = center[1] + p.radius * numpy.sin(angles)
     if p.disk:
         gl.glBegin(gl.GL_TRIANGLE_FAN)
         gl.glVertex(center)
         self._draw_vertices(*verts)
         gl.glEnd()
         if p.anti_aliasing:
             gl.glEnable(gl.GL_LINE_SMOOTH)
             gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
             gl.glEnable(gl.GL_BLEND)
             # Draw a second polygon in line mode, so the edges are anti-aliased
             gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE)
             gl.glBegin(gl.GL_TRIANGLE_FAN)
             gl.glVertex(center)
             self._draw_vertices(*verts)
             gl.glEnd()
             gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL)
             gl.glDisable(gl.GL_LINE_SMOOTH)
     if p.circle:
         if p.anti_aliasing:
             gl.glEnable(gl.GL_LINE_SMOOTH)
         gl.glColor(p.color_edge)
         gl.glLineWidth(p.circle_width)
         gl.glBegin(gl.GL_LINES)
         for i in range(verts.shape[0] - 1):
             self._draw_vertices(verts[i], verts[i + 1])
         gl.glEnd()
         gl.glDisable(gl.GL_LINE_SMOOTH)
Пример #23
0
 def _draw(self):
     p = self.parameters
     gl.glDisable(gl.GL_DEPTH_TEST)
     gl.glDisable(gl.GL_TEXTURE_2D)
     gl.glDisable(gl.GL_BLEND)
     gl.glColor(p.color)
     if p.anti_aliasing:
         gl.glEnable(gl.GL_LINE_SMOOTH)
     gl.glLineWidth(p.width)
     gl.glBegin(gl.GL_LINES)
     gl.glVertex(p.position)
     gl.glVertex(p.end)
     gl.glEnd()
     gl.glDisable(gl.GL_LINE_SMOOTH)
Пример #24
0
 def _draw(self):
     p = self.parameters
     side = p.side
     height = side * numpy.sqrt(3) / 2.
     center = VisionEgg._get_center(p.position, p.anchor, (side, height))
     position = numpy.array(center)
     hh = height / 2
     ll = position - (hh, hh)
     lr = position - (-hh, hh)
     u = position + (0., hh)
     gl.glDisable(gl.GL_DEPTH_TEST)
     gl.glDisable(gl.GL_TEXTURE_2D)
     gl.glDisable(gl.GL_BLEND)
     gl.glColor(p.color)
     gl.glBegin(gl.GL_TRIANGLES)
     self._draw_vertices(ll, lr, u)
     gl.glEnd()
     gl.glColor(p.color_edge)
     if p.anti_aliasing:
         gl.glEnable(gl.GL_LINE_SMOOTH)
     gl.glLineWidth(p.width)
     gl.glBegin(gl.GL_LINE_STRIP)
     self._draw_vertices(ll, lr, u, ll)
     gl.glEnd()
     gl.glDisable(gl.GL_LINE_SMOOTH)
Пример #25
0
        def draw(self):
            if self.parameters.on:
                gl.glDisable(gl.GL_TEXTURE_2D)
                gl.glDisable(gl.GL_BLEND)
                gl.glDisable(gl.GL_DEPTH_TEST)

                gl.glMatrixMode(gl.GL_MODELVIEW)
                gl.glPushMatrix()
                gl.glTranslate(self.parameters.lowerleft[0],self.parameters.lowerleft[1],0.0)

                c = self.parameters.color

                if len(c)==3:
                    gl.glColor3f(*c)
                elif len(c)==4:
                    gl.glColor4f(*c)
                gl.glDisable(gl.GL_TEXTURE_2D)

                gl.glRasterPos3f(0.0,0.0,0.0)
                for char in self.parameters.text:
                    glut.glutBitmapCharacter(self.parameters.font,ord(char))
                gl.glPopMatrix()
Пример #26
0
 def draw(self):
     if self._display_list is None:
         self._display_list = gl.glGenLists(1)
         self._generate_list()
     if self.parameters.on:
         gl.glCallList(self._display_list)
Пример #27
0
 def _draw_vertices(self, *vertices):
     for vertex in vertices:
         gl.glVertex(vertex)
Пример #28
0
 def _generate_list(self):
     gl.glNewList(self._display_list, gl.GL_COMPILE)
     self._draw()
     gl.glEndList()
Пример #29
0
    def draw(self):
        p = self.parameters # shorthand
        if p.on:
            if len(p.color)==3:
                gl.glColor3f(*p.color)
            elif len(p.color)==4:
                gl.glColor4f(*p.color)

            gl.glDisable(gl.GL_TEXTURE_2D)
            if p.depth_test:
                gl.glEnable(gl.GL_DEPTH_TEST)
            else:
                gl.glDisable(gl.GL_DEPTH_TEST)
            if p.blending_enabled:
                gl.glEnable(gl.GL_BLEND)
            else:
                gl.glDisable(gl.GL_BLEND)

            gl.glBegin(gl.GL_QUADS)
            gl.glVertex(*p.vertex1)
            gl.glVertex(*p.vertex2)
            gl.glVertex(*p.vertex3)
            gl.glVertex(*p.vertex4)
            gl.glEnd() # GL_QUADS
Пример #30
0
 def _draw_vertices(self, *vertices):
     for vertex in vertices:
         gl.glVertex(vertex)
Пример #31
0
    def draw(self):
        p = self.parameters # shorthand
        if p.on:
            # calculate center
            center = VisionEgg._get_center(p.position,p.anchor,(p.radius, p.radius))
            gl.glDisable(gl.GL_DEPTH_TEST)
            gl.glDisable(gl.GL_TEXTURE_2D)
            gl.glDisable(gl.GL_BLEND)

            if len(p.color)==3:
                gl.glColor3f(*p.color)
            elif len(p.color)==4:
                gl.glColor4f(*p.color)

          # Build filled circle from points
#           gl.glBegin(gl.GL_POINTS)
#           radius = int(math.ceil(p.radius))
#           for i in range(-radius, radius):
#               for j in range(-radius, radius):
#                   if(i * i + j * j < radius * radius):
#                       gl.glVertex3f(p.position[0] + i, p.position[1] + j, 0.0)
#           gl.glEnd() # GL_POINTS

            # Build filled circle from triangles (this is typically faster
            # then the commented code above with the points)
            gl.glBegin(gl.GL_TRIANGLE_FAN)
            gl.glVertex3f(p.position[0], p.position[1], 0.0)
            angles = Numeric.arange(p.num_triangles)/float(p.num_triangles)*2.0*math.pi
            verts = Numeric.zeros( (p.num_triangles,2), Numeric.Float )
            verts[:,0] = p.position[0] + p.radius * Numeric.cos(angles)
            verts[:,1] = p.position[1] + p.radius * Numeric.sin(angles)
            for i in range(verts.shape[0]):
                gl.glVertex2fv(verts[i])
            gl.glVertex2fv(verts[0])

            gl.glEnd() # GL_TRIANGLE_FAN
            if p.anti_aliasing:
                if not self._gave_alpha_warning:
                    if len(p.color) > 3 and p.color[3] != 1.0:
                        logger = logging.getLogger('VisionEgg.Arrow')
                        logger.warning("The parameter anti_aliasing is "
                                       "set to true in the Arrow "
                                       "stimulus class, but the color "
                                       "parameter specifies an alpha "
                                       "value other than 1.0.  To "
                                       "acheive anti-aliasing, ensure "
                                       "that the alpha value for the "
                                       "color parameter is 1.0.")
                        self._gave_alpha_warning = 1

                        # We've already drawn a filled polygon (aliased), now redraw
                        # the outline of the polygon (with anti-aliasing). (Using
                        # GL_POLYGON_SMOOTH results in artifactual lines where
                        # triangles were joined to create quad, at least on some OpenGL
                        # implementations.)

                # Calculate coverage value for each pixel of outline
                # and store as alpha
                gl.glEnable(gl.GL_LINE_SMOOTH)
                # Now specify how to use the alpha value
                gl.glBlendFunc(gl.GL_SRC_ALPHA,gl.GL_ONE_MINUS_SRC_ALPHA)
                gl.glEnable(gl.GL_BLEND)

                # Draw a second polygon in line mode, so the edges are anti-aliased
                gl.glPolygonMode(gl.GL_FRONT_AND_BACK,gl.GL_LINE)
                gl.glBegin(gl.GL_TRIANGLE_FAN)
                gl.glVertex3f(p.position[0], p.position[1], 0.0)
                angles = Numeric.arange(p.num_triangles)/float(p.num_triangles)*2.0*math.pi
                verts = Numeric.zeros( (p.num_triangles,2), Numeric.Float )
                verts[:,0] = p.position[0] + p.radius * Numeric.cos(angles)
                verts[:,1] = p.position[1] + p.radius * Numeric.sin(angles)
                for i in range(verts.shape[0]):
                    gl.glVertex2fv(verts[i])
                gl.glVertex2fv(verts[0])
                gl.glEnd() # GL_TRIANGLE_FAN

                # Set the polygon mode back to fill mode
                gl.glPolygonMode(gl.GL_FRONT_AND_BACK,gl.GL_FILL)
                gl.glDisable(gl.GL_LINE_SMOOTH)
Пример #32
0
    def draw(self):
        p = self.parameters  # shorthand
        if p.on:
            if len(p.color) == 3:
                gl.glColor3f(*p.color)
            elif len(p.color) == 4:
                gl.glColor4f(*p.color)

            gl.glDisable(gl.GL_TEXTURE_2D)
            if p.depth_test:
                gl.glEnable(gl.GL_DEPTH_TEST)
            else:
                gl.glDisable(gl.GL_DEPTH_TEST)
            if p.blending_enabled:
                gl.glEnable(gl.GL_BLEND)
            else:
                gl.glDisable(gl.GL_BLEND)

            gl.glBegin(gl.GL_QUADS)
            gl.glVertex(*p.vertex1)
            gl.glVertex(*p.vertex2)
            gl.glVertex(*p.vertex3)
            gl.glVertex(*p.vertex4)
            gl.glEnd()  # GL_QUADS
Пример #33
0
        def draw(self):
            if self.parameters.on:
                gl.glDisable(gl.GL_TEXTURE_2D)
                gl.glDisable(gl.GL_BLEND)
                gl.glDisable(gl.GL_DEPTH_TEST)

                gl.glMatrixMode(gl.GL_MODELVIEW)
                gl.glPushMatrix()
                gl.glTranslate(self.parameters.lowerleft[0],
                               self.parameters.lowerleft[1], 0.0)

                c = self.parameters.color

                if len(c) == 3:
                    gl.glColor3f(*c)
                elif len(c) == 4:
                    gl.glColor4f(*c)
                gl.glDisable(gl.GL_TEXTURE_2D)

                gl.glRasterPos3f(0.0, 0.0, 0.0)
                for char in self.parameters.text:
                    glut.glutBitmapCharacter(self.parameters.font, ord(char))
                gl.glPopMatrix()
Пример #34
0
    def draw(self):
        p = self.parameters  # Shorthand
        if p.on:
            # Calculate center
            center = VisionEgg._get_center(p.position, p.anchor, p.size)
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glPushMatrix()
            gl.glTranslate(center[0], center[1], 0.0)
            gl.glRotate(-p.orientation, 0.0, 0.0, 1.0)

            if len(p.color) == 3:
                gl.glColor3f(*p.color)
            elif len(p.color) == 4:
                gl.glColor4f(*p.color)
            gl.glDisable(gl.GL_DEPTH_TEST)
            gl.glDisable(gl.GL_TEXTURE_2D)
            gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
            gl.glEnable(gl.GL_BLEND)

            w = p.size[0] / 2.0
            h = p.size[1] / 2.0

            gl.glBegin(gl.GL_QUADS)  # Draw Rectangle
            gl.glVertex3f(0.25 * w, h, 0.0)
            gl.glVertex3f(-w, h, 0.0)
            gl.glVertex3f(-w, -h, 0.0)
            gl.glVertex3f(0.25 * w, -h, 0.0)
            gl.glEnd()  # GL_QUADS

            gl.glBegin(gl.GL_TRIANGLES)  # Draw Triangle
            gl.glVertex3f(1.00 * w, 0.0 * h, 0.0)  # Top
            gl.glVertex3f(0.25 * w, -3.0 * h, 0.0)
            gl.glVertex3f(0.25 * w, 3.0 * h, 0.0)
            gl.glEnd()  # GL_QUADS

            if p.anti_aliasing:
                if not self._gave_alpha_warning:
                    if len(p.color) > 3 and p.color[3] != 1.0:
                        logger = logging.getLogger('VisionEgg.Arrow')
                        logger.warning("The parameter anti_aliasing is "
                                       "set to true in the Arrow "
                                       "stimulus class, but the color "
                                       "parameter specifies an alpha "
                                       "value other than 1.0.  To "
                                       "acheive anti-aliasing, ensure "
                                       "that the alpha value for the "
                                       "color parameter is 1.0.")
                        self._gave_alpha_warning = 1

                # We've already drawn a filled polygon (aliased), now redraw
                # the outline of the polygon (with anti-aliasing). (Using
                # GL_POLYGON_SMOOTH results in artifactual lines where
                # triangles were joined to create quad, at least on some OpenGL
                # implementations.)

                # Calculate coverage value for each pixel of outline
                # and store as alpha
                gl.glEnable(gl.GL_LINE_SMOOTH)
                # Now specify how to use the alpha value
                gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
                gl.glEnable(gl.GL_BLEND)

                # Draw a second polygon in line mode, so the edges are anti-aliased
                gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE)
                gl.glBegin(gl.GL_QUADS)

                gl.glVertex3f(0.25 * w, h, 0.0)  # Draw Rectangle
                gl.glVertex3f(-w, h, 0.0)
                gl.glVertex3f(-w, -h, 0.0)
                gl.glVertex3f(0.25 * w, -h, 0.0)
                gl.glVertex3f(1.00 * w, 0.0 * h, 0.0)  # Draw Triangle
                gl.glVertex3f(0.25 * w, -3.0 * h, 0.0)
                gl.glVertex3f(0.25 * w, 3.0 * h, 0.0)
                gl.glEnd()  # GL_QUADS

                # Set the polygon mode back to fill mode
                gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL)
                gl.glDisable(gl.GL_LINE_SMOOTH)
            gl.glPopMatrix()
Пример #35
0
 def __init__(self,viewport_with=800):
     gl.glMatrixMode(gl.GL_MODELVIEW) # Set OpenGL matrix state to modify the modelview matrix
     gl.glPushMatrix()
     gl.glLoadIdentity() # Clear the modelview matrix
     gl.glTranslate(viewport_with,0,0)
     gl.glRotate(180, 0, 1, 0)
     matrix = gl.glGetFloatv(gl.GL_MODELVIEW_MATRIX)
     gl.glPopMatrix()
     if matrix is None:
         # OpenGL wasn't started
         raise RuntimeError("OpenGL matrix operations can only take place once OpenGL context started.")
     matrix = np.asarray(matrix) # make sure it's numpy array
     VisionEgg.Core.ModelView.__init__(self,**{'matrix':matrix})
Пример #36
0
    def draw(self):
        p = self.parameters  # shorthand
        if p.on:
            # calculate center
            center = VisionEgg._get_center(p.position, p.anchor,
                                           (p.radius, p.radius))
            gl.glDisable(gl.GL_DEPTH_TEST)
            gl.glDisable(gl.GL_TEXTURE_2D)
            gl.glDisable(gl.GL_BLEND)

            if len(p.color) == 3:
                gl.glColor3f(*p.color)
            elif len(p.color) == 4:
                gl.glColor4f(*p.color)

        # Build filled circle from points
#           gl.glBegin(gl.GL_POINTS)
#           radius = int(math.ceil(p.radius))
#           for i in range(-radius, radius):
#               for j in range(-radius, radius):
#                   if(i * i + j * j < radius * radius):
#                       gl.glVertex3f(p.position[0] + i, p.position[1] + j, 0.0)
#           gl.glEnd() # GL_POINTS

# Build filled circle from triangles (this is typically faster
# then the commented code above with the points)
            gl.glBegin(gl.GL_TRIANGLE_FAN)
            gl.glVertex3f(p.position[0], p.position[1], 0.0)
            angles = Numeric.arange(p.num_triangles) / float(
                p.num_triangles) * 2.0 * math.pi
            verts = Numeric.zeros((p.num_triangles, 2), Numeric.Float)
            verts[:, 0] = p.position[0] + p.radius * Numeric.cos(angles)
            verts[:, 1] = p.position[1] + p.radius * Numeric.sin(angles)
            for i in range(verts.shape[0]):
                gl.glVertex2fv(verts[i])
            gl.glVertex2fv(verts[0])

            gl.glEnd()  # GL_TRIANGLE_FAN
            if p.anti_aliasing:
                if not self._gave_alpha_warning:
                    if len(p.color) > 3 and p.color[3] != 1.0:
                        logger = logging.getLogger('VisionEgg.Arrow')
                        logger.warning("The parameter anti_aliasing is "
                                       "set to true in the Arrow "
                                       "stimulus class, but the color "
                                       "parameter specifies an alpha "
                                       "value other than 1.0.  To "
                                       "acheive anti-aliasing, ensure "
                                       "that the alpha value for the "
                                       "color parameter is 1.0.")
                        self._gave_alpha_warning = 1

                        # We've already drawn a filled polygon (aliased), now redraw
                        # the outline of the polygon (with anti-aliasing). (Using
                        # GL_POLYGON_SMOOTH results in artifactual lines where
                        # triangles were joined to create quad, at least on some OpenGL
                        # implementations.)

                # Calculate coverage value for each pixel of outline
                # and store as alpha
                gl.glEnable(gl.GL_LINE_SMOOTH)
                # Now specify how to use the alpha value
                gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
                gl.glEnable(gl.GL_BLEND)

                # Draw a second polygon in line mode, so the edges are anti-aliased
                gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE)
                gl.glBegin(gl.GL_TRIANGLE_FAN)
                gl.glVertex3f(p.position[0], p.position[1], 0.0)
                angles = Numeric.arange(p.num_triangles) / float(
                    p.num_triangles) * 2.0 * math.pi
                verts = Numeric.zeros((p.num_triangles, 2), Numeric.Float)
                verts[:, 0] = p.position[0] + p.radius * Numeric.cos(angles)
                verts[:, 1] = p.position[1] + p.radius * Numeric.sin(angles)
                for i in range(verts.shape[0]):
                    gl.glVertex2fv(verts[i])
                gl.glVertex2fv(verts[0])
                gl.glEnd()  # GL_TRIANGLE_FAN

                # Set the polygon mode back to fill mode
                gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL)
                gl.glDisable(gl.GL_LINE_SMOOTH)
Пример #37
0
 def __init__(self, viewport_with=800):
     gl.glMatrixMode(
         gl.GL_MODELVIEW
     )  # Set OpenGL matrix state to modify the modelview matrix
     gl.glPushMatrix()
     gl.glLoadIdentity()  # Clear the modelview matrix
     gl.glTranslate(viewport_with, 0, 0)
     gl.glRotate(180, 0, 1, 0)
     matrix = gl.glGetFloatv(gl.GL_MODELVIEW_MATRIX)
     gl.glPopMatrix()
     if matrix is None:
         # OpenGL wasn't started
         raise RuntimeError(
             "OpenGL matrix operations can only take place once OpenGL context started."
         )
     matrix = np.asarray(matrix)  # make sure it's numpy array
     VisionEgg.Core.ModelView.__init__(self, **{'matrix': matrix})
Пример #38
0
    def draw(self):
        p = self.parameters  # shorthand
        if p.center is not None:
            if not hasattr(VisionEgg.config, "_GAVE_CENTER_DEPRECATION"):
                logger = logging.getLogger('VisionEgg.MoreStimuli')
                logger.warning("Specifying Target2D by deprecated "
                               "'center' parameter deprecated.  Use "
                               "'position' parameter instead.  (Allows "
                               "use of 'anchor' parameter to set to "
                               "other values.)")
                VisionEgg.config._GAVE_CENTER_DEPRECATION = 1
            p.anchor = 'center'
            p.position = p.center[0], p.center[
                1]  # copy values (don't copy ref to tuple)
        if p.on:
            # calculate center
            center = VisionEgg._get_center(p.position, p.anchor, p.size)
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glPushMatrix()
            gl.glTranslate(center[0], center[1], 0.0)
            gl.glRotate(p.orientation, 0.0, 0.0, 1.0)

            if len(p.color) == 3:
                gl.glColor3f(*p.color)
            elif len(p.color) == 4:
                gl.glColor4f(*p.color)
            gl.glDisable(gl.GL_DEPTH_TEST)
            gl.glDisable(gl.GL_TEXTURE_2D)
            gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
            gl.glEnable(gl.GL_BLEND)

            w = p.size[0] / 2.0
            h = p.size[1] / 2.0

            gl.glBegin(gl.GL_QUADS)
            gl.glVertex3f(-w, -h, 0.0)
            gl.glVertex3f(w, -h, 0.0)
            gl.glVertex3f(w, h, 0.0)
            gl.glVertex3f(-w, h, 0.0)
            gl.glEnd()  # GL_QUADS

            if p.anti_aliasing:
                if not self._gave_alpha_warning:
                    if len(p.color) > 3 and p.color[3] != 1.0:
                        logger = logging.getLogger('VisionEgg.MoreStimuli')
                        logger.warning("The parameter anti_aliasing is "
                                       "set to true in the Target2D "
                                       "stimulus class, but the color "
                                       "parameter specifies an alpha "
                                       "value other than 1.0.  To "
                                       "acheive anti-aliasing, ensure "
                                       "that the alpha value for the "
                                       "color parameter is 1.0.")
                        self._gave_alpha_warning = 1

                # We've already drawn a filled polygon (aliased), now
                # redraw the outline of the polygon (with
                # anti-aliasing).  (Using GL_POLYGON_SMOOTH results in
                # artifactual lines where triangles were joined to
                # create quad, at least on some OpenGL
                # implementations.)

                # Calculate coverage value for each pixel of outline
                # and store as alpha
                gl.glEnable(gl.GL_LINE_SMOOTH)
                # Now specify how to use the alpha value
                gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
                gl.glEnable(gl.GL_BLEND)

                # Draw a second polygon in line mode, so the edges are anti-aliased
                gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE)
                gl.glBegin(gl.GL_QUADS)
                gl.glVertex3f(-w, -h, 0.0)
                gl.glVertex3f(w, -h, 0.0)
                gl.glVertex3f(w, h, 0.0)
                gl.glVertex3f(-w, h, 0.0)
                gl.glEnd()  # GL_QUADS

                # Set the polygon mode back to fill mode
                gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL)
                gl.glDisable(gl.GL_LINE_SMOOTH)
            gl.glPopMatrix()
Пример #39
0
    def draw(self):
        p = self.parameters # shorthand
        if p.on:
            # calculate center
            center = VisionEgg._get_center(p.position,p.anchor,p.size)
            if p.mask:
                gl.glActiveTextureARB(gl.GL_TEXTURE0_ARB)
            gl.glBindTexture(gl.GL_TEXTURE_1D,self._texture_object_id)

            gl.glEnable(gl.GL_TEXTURE_1D)
            gl.glDisable(gl.GL_TEXTURE_2D)
            if p.bit_depth != self.cached_bit_depth:
                self.calculate_bit_depth_dependencies()

            # Clear the modeview matrix
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glPushMatrix()

            # Rotate about the center of the texture
            gl.glTranslate(center[0],
                           center[1],
                           0)
            gl.glRotate(p.orientation,0,0,1)

            if p.depth is None:
                gl.glDisable(gl.GL_DEPTH_TEST)
                depth = 0.0
            else:
                gl.glEnable(gl.GL_DEPTH_TEST)
                depth = p.depth

            # allow max_alpha value to control blending
            gl.glEnable( gl.GL_BLEND )
            gl.glBlendFunc( gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA )

            if p.color2:
                gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_BLEND)
                gl.glTexEnvfv(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_COLOR, p.color2)
                ## alpha is ignored because the texture base internal format is luminance
            else:
                gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_MODULATE)

            if p.t0_time_sec_absolute is None and not p.ignore_time:
                p.t0_time_sec_absolute = VisionEgg.time_func()

            w = p.size[0]
            inc = w/float(p.num_samples)
            if p.ignore_time:
                phase = p.phase_at_t0
            else:
                t_var = VisionEgg.time_func() - p.t0_time_sec_absolute
                phase = t_var*p.temporal_freq_hz*-360.0 + p.phase_at_t0
            if p.recalculate_phase_tolerance is None or abs(self._last_phase - phase) > p.recalculate_phase_tolerance:
                self._last_phase = phase # we're re-drawing the phase at this angle
                floating_point_sin = numpy.sin(2.0*math.pi*p.spatial_freq*numpy.arange(0.0,w,inc,dtype=numpy.float)+(phase/180.0*math.pi))*0.5*p.contrast+p.pedestal
                floating_point_sin = numpy.clip(floating_point_sin,0.0,1.0) # allow square wave generation if contrast > 1
                texel_data = (floating_point_sin*self.max_int_val).astype(self.numpy_dtype)
                # PyOpenGL 2.0.1.09 has a bug, so use our own wrapper
                _vegl.veglTexSubImage1D(gl.GL_TEXTURE_1D, # target
                                        0,                # level
                                        0,                # x offset
                                        p.num_samples,    # width
                                        self.format,      # format of new texel data
                                        self.gl_type,     # type of new texel data
                                        texel_data)       # new texel data
                if 0:
                    compare_array = numpy.empty(texel_data.shape,dtype=texel_data.dtype)
                    pixels = _vegl.veglGetTexImage(gl.GL_TEXTURE_1D, # target
                                                   0, # level
                                                   self.format, # format
                                                   self.gl_type, # type
                                                   compare_array)
                    assert numpy.allclose( compare_array, texel_data )

            h_w = p.size[0]/2.0
            h_h = p.size[1]/2.0

            l = -h_w
            r = h_w
            b = -h_h
            t = h_h

            # in the case of only color1,
            # the texel data multiplies color1 to produce a color

            # with color2,
            # the texel data linearly interpolates between color1 and color2

            gl.glColor4f(p.color1[0],p.color1[1],p.color1[2],p.max_alpha)

            if p.mask:
                p.mask.draw_masked_quad(0.0,1.0,0.0,1.0, # l,r,b,t for texture coordinates
                                        l,r,b,t, # l,r,b,t in eye coordinates
                                        depth ) # also in eye coordinates
            else:
                # draw unmasked quad
                gl.glBegin(gl.GL_QUADS)

                gl.glTexCoord2f(0.0,0.0)
                gl.glVertex3f(l,b,depth)

                gl.glTexCoord2f(1.0,0.0)
                gl.glVertex3f(r,b,depth)

                gl.glTexCoord2f(1.0,1.0)
                gl.glVertex3f(r,t,depth)

                gl.glTexCoord2f(0.0,1.0)
                gl.glVertex3f(l,t,depth)
                gl.glEnd() # GL_QUADS

            gl.glDisable(gl.GL_TEXTURE_1D)
            gl.glPopMatrix()
Пример #40
0
 def draw(self):
     p = self.parameters
     if p.on:
         self._gl_color(*self._color)
         gl.glDisable(gl.GL_TEXTURE_2D)
         if p.depth_test:
             gl.glEnable(gl.GL_DEPTH_TEST)
         else:
             gl.glDisable(gl.GL_DEPTH_TEST)
         if p.blending_enabled:
             gl.glEnable(gl.GL_BLEND)
         else:
             gl.glDisable(gl.GL_BLEND)
         gl.glLineWidth(self._line_width)
         gl.glBegin(gl.GL_LINE_LOOP)
         for vertex in self._vertices:
             gl.glVertex(*vertex)
         gl.glEnd()
Пример #41
0
 def __del__(self):
     gl.glDeleteTextures( [self._texture_object_id] )
Пример #42
0
 def draw(self):
     super(ShaderTextureStimulus, self).draw()
     # uninstall shader program
     gl.glUseProgram(0)
Пример #43
0
 def _draw(self):
     p = self.parameters
     center = VisionEgg._get_center(p.position, p.anchor, (p.radius, p.radius))
     gl.glDisable(gl.GL_DEPTH_TEST)
     gl.glDisable(gl.GL_TEXTURE_2D)
     gl.glDisable(gl.GL_BLEND)
     gl.glColor(p.color)
     start, end = p.start, p.end
     if end < start:
         start -= 360.
     start, end = map(numpy.deg2rad, (start, end))
     frac = (end - start) / (2 * numpy.pi)
     num_triangles = float(p.num_triangles) * frac
     angles = numpy.linspace(start, end, num_triangles)
     verts = numpy.zeros((num_triangles, 2))
     verts[:,0] = center[0] + p.radius * numpy.cos(angles)
     verts[:,1] = center[1] + p.radius * numpy.sin(angles)
     if p.disk:
         gl.glBegin(gl.GL_TRIANGLE_FAN)
         gl.glVertex(center)
         self._draw_vertices(*verts)
         gl.glEnd()
         if p.anti_aliasing:
             gl.glEnable(gl.GL_LINE_SMOOTH)
             gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
             gl.glEnable(gl.GL_BLEND)
             # Draw a second polygon in line mode, so the edges are anti-aliased
             gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE)
             gl.glBegin(gl.GL_TRIANGLE_FAN)
             gl.glVertex(center)
             self._draw_vertices(*verts)
             gl.glEnd()
             gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL)
             gl.glDisable(gl.GL_LINE_SMOOTH)
     if p.circle:
         if p.anti_aliasing:
             gl.glEnable(gl.GL_LINE_SMOOTH)
         gl.glColor(p.color_edge)
         gl.glLineWidth(p.circle_width)
         gl.glBegin(gl.GL_LINES)
         for i in range(verts.shape[0]-1):
             self._draw_vertices(verts[i], verts[i+1])
         gl.glEnd()
         gl.glDisable(gl.GL_LINE_SMOOTH)
Пример #44
0
    def __init__(self, **kw):
        LuminanceGratingCommon.__init__(self, **kw)

        p = self.parameters  # shorthand

        self._texture_object_id = gl.glGenTextures(1)
        if p.mask:
            gl.glActiveTextureARB(gl.GL_TEXTURE0_ARB)
        gl.glBindTexture(gl.GL_TEXTURE_1D, self._texture_object_id)

        # Do error-checking on texture to make sure it will load
        max_dim = gl.glGetIntegerv(gl.GL_MAX_TEXTURE_SIZE)
        if p.num_samples > max_dim:
            raise NumSamplesTooLargeError(
                "Grating num_samples too large for video system.\nOpenGL reports maximum size of %d" % (max_dim,)
            )

        self.calculate_bit_depth_dependencies()

        w = p.size[0]
        inc = w / float(p.num_samples)
        phase = 0.0  # this data won't get used - don't care about phase
        self._last_phase = phase
        floating_point_sin = (
            numpy.sin(
                2.0 * math.pi * p.spatial_freq * numpy.arange(0.0, w, inc, dtype=numpy.float)
                + (phase / 180.0 * math.pi)
            )
            * 0.5
            * p.contrast
            + p.pedestal
        )
        floating_point_sin = numpy.clip(floating_point_sin, 0.0, 1.0)  # allow square wave generation if contrast > 1
        texel_data = (floating_point_sin * self.max_int_val).astype(self.numpy_dtype).tostring()

        # Because the MAX_TEXTURE_SIZE method is insensitive to the current
        # state of the video system, another check must be done using
        # "proxy textures".
        gl.glTexImage1D(
            gl.GL_PROXY_TEXTURE_1D,  # target
            0,  # level
            self.gl_internal_format,  # video RAM internal format
            p.num_samples,  # width
            0,  # border
            self.format,  # format of texel data
            self.gl_type,  # type of texel data
            texel_data,
        )  # texel data (irrelevant for proxy)
        if gl.glGetTexLevelParameteriv(gl.GL_PROXY_TEXTURE_1D, 0, gl.GL_TEXTURE_WIDTH) == 0:  # Need PyOpenGL >= 2.0
            raise NumSamplesTooLargeError("Grating num_samples is too wide for your video system!")

        # If we got here, it worked and we can load the texture for real.
        gl.glTexImage1D(
            gl.GL_TEXTURE_1D,  # target
            0,  # level
            self.gl_internal_format,  # video RAM internal format
            p.num_samples,  # width
            0,  # border
            self.format,  # format of texel data
            self.gl_type,  # type of texel data
            texel_data,
        )  # texel data

        # Set texture object defaults
        gl.glTexParameteri(gl.GL_TEXTURE_1D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE)
        gl.glTexParameteri(gl.GL_TEXTURE_1D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE)
        gl.glTexParameteri(gl.GL_TEXTURE_1D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
        gl.glTexParameteri(gl.GL_TEXTURE_1D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR)

        if p.color2 is not None:
            if (
                VisionEgg.Core.gl_renderer == "ATi Rage 128 Pro OpenGL Engine"
                and VisionEgg.Core.gl_version == "1.1 ATI-1.2.22"
            ):
                logger = logging.getLogger("VisionEgg.Gratings")
                logger.warning(
                    "Your video card and driver have known "
                    "bugs which prevent them from rendering "
                    "color gratings properly."
                )
Пример #45
0
    def update_sub_surface( self,
                            texel_data,
                            transfer_pixels,
                            sub_surface_size, # updated region size
                            unpack_offset = None, # crop offset 
                            update_offset = None, # update offset
                            mipmap_level = 0,
                            data_format = None, # automatic guess unless set explicitly
                            data_type = None, # automatic guess unless set explicitly
                            ):
        # make myself the active texture
        gl.glBindTexture(self.target, self.gl_id)
        data_format = gl.GL_RGB
        data_type = gl.GL_UNSIGNED_BYTE
        target = gl.GL_TEXTURE_2D
        
        if unpack_offset is None:
            unpack_offset = (0, 0)
        if update_offset is None:
            update_offset = (0, 0)
            
        width, _height = texel_data.get_size()
        raw_data = np.frombuffer(self.buffer_data, 'B')

        gl.glPixelStorei( gl.GL_UNPACK_ROW_LENGTH, width)
        gl.glPixelStorei( gl.GL_UNPACK_SKIP_PIXELS, unpack_offset[0])
        gl.glPixelStorei( gl.GL_UNPACK_SKIP_ROWS, unpack_offset[1])
        gl.glTexSubImage2D(target,
                           mipmap_level,
                           update_offset[0],
                           update_offset[1],
                           sub_surface_size[0],
                           sub_surface_size[1],
                           data_format,
                           data_type,
                           raw_data)
        gl.glPixelStorei( gl.GL_UNPACK_ROW_LENGTH, 0)
        gl.glPixelStorei( gl.GL_UNPACK_SKIP_PIXELS, 0)
        gl.glPixelStorei( gl.GL_UNPACK_SKIP_ROWS, 0)
Пример #46
0
 def _draw(self):
     p = self.parameters
     gl.glDisable(gl.GL_DEPTH_TEST)
     gl.glDisable(gl.GL_TEXTURE_2D)
     gl.glDisable(gl.GL_BLEND)
     gl.glColor(p.color)
     if p.anti_aliasing:
         gl.glEnable(gl.GL_LINE_SMOOTH)
     gl.glLineWidth(p.width)
     gl.glBegin(gl.GL_LINES)
     gl.glVertex(p.position)
     gl.glVertex(p.end)
     gl.glEnd()
     gl.glDisable(gl.GL_LINE_SMOOTH)
Пример #47
0
 def _draw(self):
     p = self.parameters
     side = p.side
     height = side * numpy.sqrt(3) / 2.
     center = VisionEgg._get_center(p.position, p.anchor, (side, height))
     position = numpy.array(center)
     hh = height / 2
     ll = position - (hh, hh)
     lr = position - (-hh, hh)
     u = position + (0., hh)
     gl.glDisable(gl.GL_DEPTH_TEST)
     gl.glDisable(gl.GL_TEXTURE_2D)
     gl.glDisable(gl.GL_BLEND)
     gl.glColor(p.color)
     gl.glBegin(gl.GL_TRIANGLES)
     self._draw_vertices(ll, lr, u)
     gl.glEnd()
     gl.glColor(p.color_edge)
     if p.anti_aliasing:
         gl.glEnable(gl.GL_LINE_SMOOTH)
     gl.glLineWidth(p.width)
     gl.glBegin(gl.GL_LINE_STRIP)
     self._draw_vertices(ll, lr, u, ll)
     gl.glEnd()
     gl.glDisable(gl.GL_LINE_SMOOTH)
Пример #48
0
 def draw(self):
     if self._display_list is None:
         self._display_list = gl.glGenLists(1)
         self._generate_list()
     if self.parameters.on:
         gl.glCallList(self._display_list)
Пример #49
0
    def update_sub_surface( self,
                            texel_data,
                            transfer_pixels,
                            sub_surface_size, # updated region size
                            unpack_offset = None, # crop offset 
                            update_offset = None, # update offset
                            mipmap_level = 0,
                            data_format = None, # automatic guess unless set explicitly
                            data_type = None, # automatic guess unless set explicitly
                            ):
        # make myself the active texture
        gl.glBindTexture(self.target, self.gl_id)

        if data_format is None: # guess the format of the data
            if isinstance(texel_data,pygame.surface.Surface):
                if texel_data.get_alpha():
                    data_format = gl.GL_RGBA
                else:
                    data_format = gl.GL_RGB

        data_type = gl.GL_UNSIGNED_BYTE
        target = gl.GL_TEXTURE_2D
        
        if unpack_offset is None:
            unpack_offset = (0, 0)
        if update_offset is None:
            update_offset = (0, 0)
            
        width, _height = texel_data.get_size()
        if transfer_pixels or self.raw_data is None:
            if texel_data.get_alpha():
                self.raw_data = pygame.image.tostring(texel_data,'RGBA',1)
            else:
                self.raw_data = pygame.image.tostring(texel_data,'RGB',1)

        gl.glPixelStorei( gl.GL_UNPACK_ROW_LENGTH, width)
        gl.glPixelStorei( gl.GL_UNPACK_SKIP_PIXELS, unpack_offset[0])
        gl.glPixelStorei( gl.GL_UNPACK_SKIP_ROWS, unpack_offset[1])
        gl.glTexSubImage2D(target,
                           mipmap_level,
                           update_offset[0],
                           update_offset[1],
                           sub_surface_size[0],
                           sub_surface_size[1],
                           data_format,
                           data_type,
                           self.raw_data)
        gl.glPixelStorei( gl.GL_UNPACK_ROW_LENGTH, 0)
        gl.glPixelStorei( gl.GL_UNPACK_SKIP_PIXELS, 0)
        gl.glPixelStorei( gl.GL_UNPACK_SKIP_ROWS, 0)
Пример #50
0
 def _generate_list(self):
     gl.glNewList(self._display_list, gl.GL_COMPILE)
     self._draw()
     gl.glEndList()
Пример #51
0
        def draw(self):
            if self.parameters.on:
                gl.glDisable(gl.GL_TEXTURE_2D)
                gl.glDisable(gl.GL_DEPTH_TEST)

                gl.glMatrixMode(gl.GL_MODELVIEW)
                gl.glPushMatrix()
                gl.glTranslate(self.parameters.lowerleft[0],self.parameters.lowerleft[1],0.0)
                gl.glRotate(self.parameters.orientation,0.0,0.0,1.0)

                c = self.parameters.color
                if len(c)==3:
                    gl.glColor3f(*c)
                elif len(c)==4:
                    gl.glColor4f(*c)

                gl.glLineWidth(self.parameters.linewidth)

                if self.parameters.anti_aliasing:
                    gl.glEnable(gl.GL_BLEND)
                    gl.glBlendFunc(gl.GL_SRC_ALPHA,gl.GL_ONE_MINUS_SRC_ALPHA)
                    gl.glEnable(gl.GL_LINE_SMOOTH)
                else:
                    gl.glDisable(gl.GL_BLEND)

    ##            # This code successfully draws a box...
    ##            gl.glBegin(gl.GL_QUADS)
    ##            gl.glVertex2f(0.0,0.0)
    ##            gl.glVertex2f(0.0,0.1)
    ##            gl.glVertex2f(0.1,0.1)
    ##            gl.glVertex2f(0.1,0.0)
    ##            gl.glEnd()

                # But this code does not draw the string!?!
                for char in self.parameters.text:
                    glut.glutStrokeCharacter(self.parameters.font,ord(char))
                gl.glPopMatrix()
Пример #52
0
    def draw(self):
        p = self.parameters # shorthand
        if p.center is not None:
            p.anchor = 'center'
            p.position = p.center[0], p.center[1] # copy values (don't copy ref to tuple)
        if p.on:
            # calculate center
            center = VisionEgg._get_center(p.position,p.anchor,p.size)
            gl.glMatrixMode(gl.GL_MODELVIEW)
            gl.glPushMatrix()
            gl.glTranslate(center[0],center[1],0.0)
            gl.glRotate(p.orientation,0.0,0.0,1.0)

            if len(p.bgcolor)==3:
                gl.glColor3f(*p.bgcolor)
            elif len(p.bgcolor)==4:
                gl.glColor4f(*p.bgcolor)
            gl.glDisable(gl.GL_DEPTH_TEST)
            gl.glDisable(gl.GL_TEXTURE_2D)
            gl.glBlendFunc(gl.GL_SRC_ALPHA,gl.GL_ONE_MINUS_SRC_ALPHA)
            gl.glEnable(gl.GL_BLEND)

            w = p.size[0]/2.0 #grid half-size
            h = p.size[1]/2.0
            m = p.size[0]/p.grid[0] #cell size
            n = p.size[1]/p.grid[1]
            i = range(p.grid[0]) #grid index
            j = range(p.grid[1])
            #draw colorful cell
#           vertices_list = [((-w+column*m, h-(row+1)*n, 0.0),(-w+column*m, h-row*n, 0.0),\
#                         (-w+(column+1)*m, h-row*n, 0.0),(-w+(column+1)*m, h-row*n, 0.0))\
#                         for column in j for row in i]
            vertices_list = [((-w+column*m, h-(row+1)*n, 0.0),(-w+column*m, h-row*n, 0.0),\
                              (-w+(column+1)*m, h-row*n, 0.0),(-w+(column+1)*m, h-(row+1)*n, 0.0))\
                         for column in j for row in i]
            colors_list = [colormap(p.colorindex[row,column],color=p.cellcolor)*4 for column in j for row in i]
            #flattening the vertices and colors
            vertices_flat = [num for tuple in vertices_list for vertex in tuple for num in vertex]
            colors_flat = [num for tuple in colors_list for num in tuple]
            vertices = np.array(vertices_flat)
            colors = np.array(colors_flat)
            vertices.shape = (-1, 3)
            colors.shape   = (-1, 3)
            gl.glVertexPointerd(vertices)
            gl.glColorPointerd(colors)
            gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
            gl.glEnableClientState(gl.GL_COLOR_ARRAY)
            gl.glDisable(gl.GL_LIGHTING)
            gl.glDrawArrays(gl.GL_QUADS,0,p.grid[0]*p.grid[1]*4)
                        
            #draw grid lines
            if p.drawline:
                if len(p.linecolor) == 3:
                    gl.glColor3f(*p.linecolor)
                elif len(p.linecolor) == 4:
                    gl.glColor4f(*p.linecolor)
                
                row_list = [((-w, h - i * n),(w, h - i * n)) for i in range(p.grid[1] + 1)]
                col_list = [((-w + i * m, h),(-w + i * m, -h)) for i in range(p.grid[0] + 1)]
                ver_row_flat = [num for tuple in row_list for vertex in tuple for num in vertex]
                ver_col_flat = [num for tuple in col_list for vertex in tuple for num in vertex]
                vertices_row = np.array(ver_row_flat)
                vertices_col = np.array(ver_col_flat)
                vertices_row.shape = (-1,2)
                vertices_col.shape = (-1,2)
                
                gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
                gl.glDisableClientState(gl.GL_COLOR_ARRAY)
                gl.glVertexPointerd(vertices_row)
                gl.glDrawArrays(gl.GL_LINES,0,(p.grid[1] + 1)*2)
                gl.glVertexPointerd(vertices_col)
                gl.glDrawArrays(gl.GL_LINES,0,(p.grid[0] + 1)*2)
                
#                gl.glBegin(gl.GL_LINES);
#                for i in range(p.grid[1] + 1):
#                    gl.glVertex2f(-w, h - i * n)
#                    gl.glVertex2f(w, h - i * n)
#                for i in range(p.grid[0] + 1):
#                    gl.glVertex2f(-w + i * m, h)
#                    gl.glVertex2f(-w + i * m, -h)
#                gl.glEnd();
            gl.glPopMatrix()