예제 #1
0
    def fog_on_off(self):
        if self.has_gl:
            if not self.fogmode:
                self.has_fog = 1
                glEnable(GL_FOG)
                glFogf(GL_FOG_MODE, GL_LINEAR)
                glHint(GL_FOG_HINT, GL_NICEST)
                """
				glFogf(GL_FOG_DENSITY,0.2)
				c=self.camera.GetDistance()
				s=self.slab
				z=self.zpos
				glFogf(GL_FOG_START, c-z-s/2.)
				glFogf(GL_FOG_END, 2000)
				self.renwin.Render()
				"""
                self.update_fog_dist()
                self.update_fog_density()
                self.itf.dist.configure(state=tk.NORMAL)
                self.itf.density.configure(state=tk.NORMAL)
                self.fogmode = 1
            else:
                glDisable(GL_FOG)
                self.renwin.Render()
                self.itf.dist.configure(state=tk.DISABLED)
                self.itf.density.configure(state=tk.DISABLED)
                self.fogmode = 0
예제 #2
0
def init():
    glShadeModel(GL_SMOOTH)
    glClearColor(0.0, 0.0, 0.0, 0.0)
    glClearDepth(1.0)
    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LEQUAL)
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
예제 #3
0
파일: gfx.py 프로젝트: ggoret/VEDA
	def fog_on_off(self):
		if self.has_gl :
			if not self.fogmode:
				self.has_fog=1
				glEnable(GL_FOG)
				glFogf(GL_FOG_MODE, GL_LINEAR)
				glHint(GL_FOG_HINT, GL_NICEST)
				"""
				glFogf(GL_FOG_DENSITY,0.2)
				c=self.camera.GetDistance()
				s=self.slab
				z=self.zpos
				glFogf(GL_FOG_START, c-z-s/2.)
				glFogf(GL_FOG_END, 2000)
				self.renwin.Render()
				"""
				self.update_fog_dist()
				self.update_fog_density()
				self.itf.dist.configure(state=tk.NORMAL)
				self.itf.density.configure(state=tk.NORMAL)
				self.fogmode=1
			else:
				glDisable(GL_FOG)
				self.renwin.Render()
				self.itf.dist.configure(state=tk.DISABLED)
				self.itf.density.configure(state=tk.DISABLED)
				self.fogmode=0
예제 #4
0
    def gl_init(self):
        #must be called within a context!
        #performs init if needed
        if not self.debug_setup:
            self.debug_setup = True
            self.gl_init_debug()

        if not self.gl_setup:
            w, h = self.size
            self.gl_marker("Initializing GL context for window size %d x %d", w, h)
            # Initialize viewport and matrices for 2D rendering
            glViewport(0, 0, w, h)
            glMatrixMode(GL_PROJECTION)
            glLoadIdentity()
            glOrtho(0.0, w, h, 0.0, -1.0, 1.0)
            glMatrixMode(GL_MODELVIEW)
            # Mesa docs claim: this hint can improve the speed of texturing
            #when perspective-correct texture coordinate interpolation isn't needed,
            #such as when using a glOrtho() projection:
            glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST)
            # Could be more optimal to use vertex arrays:
            # glEnableClientState(GL_VERTEX_ARRAY)
            # glEnableClientState(GL_TEXTURE_COORD_ARRAY)

            # Clear background to transparent black
            glClearColor(0.0, 0.0, 0.0, 0.0)

            # we don't use the depth (2D only):
            glDisable(GL_DEPTH_TEST)
            # only do alpha blending in present_fbo:
            glDisable(GL_BLEND)

            # Default state is good for YUV painting:
            #  - fragment program enabled
            #  - YUV fragment program bound
            #  - render to offscreen FBO
            if self.textures is None:
                self.gl_init_textures()

            # Define empty FBO texture and set rendering to FBO
            glEnable(GL_FRAGMENT_PROGRAM_ARB)
            glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO])
            # nvidia needs this even though we don't use mipmaps (repeated through this file):
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0)
            glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, self.texture_pixel_format, w, h, 0, self.texture_pixel_format, GL_UNSIGNED_BYTE, None)
            glBindFramebuffer(GL_FRAMEBUFFER, self.offscreen_fbo)
            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO], 0)
            glClear(GL_COLOR_BUFFER_BIT)

            # Create and assign fragment programs
            if not self.shaders:
                self.gl_init_shaders()

            # Bind program 0 for YUV painting by default
            glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, self.shaders[YUV2RGB_SHADER])
            self.gl_setup = True
예제 #5
0
 def set_texture(m):
     texture_data = np.array(m.texture_image, dtype='int8')
     m.textureID = glGenTextures(1)
     glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
     glBindTexture(GL_TEXTURE_2D, m.textureID)
     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture_data.shape[1],
                  texture_data.shape[0], 0, GL_BGR, GL_UNSIGNED_BYTE,
                  texture_data.flatten())
     glHint(GL_GENERATE_MIPMAP_HINT,
            GL_NICEST)  # must be GL_FASTEST, GL_NICEST or GL_DONT_CARE
     glGenerateMipmap(GL_TEXTURE_2D)
예제 #6
0
 def GLsetup(self, display):
     "Set up OpenGL."
     self.projection = glm.perspective(
         45,
         float(display.get_width()) / display.get_height(), .02, 5)
     # Set up the drawing field.
     glEnable(GL_POLYGON_SMOOTH)
     glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST)
     glEnable(GL_BLEND)
     glEnable(GL_DEPTH_TEST)
     glClearColor(.5, .5, .5, 0.)
예제 #7
0
 def basic_gl_setup(self):
     glEnable(GL_POINT_SPRITE)
     glEnable(GL_VERTEX_PROGRAM_POINT_SIZE)  # overwrite pointsize
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
     glEnable(GL_BLEND)
     glClearColor(0.8, 0.8, 0.8, 1.0)
     glEnable(GL_LINE_SMOOTH)
     # glEnable(GL_POINT_SMOOTH)
     glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
     glEnable(GL_LINE_SMOOTH)
     glEnable(GL_POLYGON_SMOOTH)
     glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST)
예제 #8
0
파일: __init__.py 프로젝트: boothead/pymt
    def init_gl(self):
        version = glGetString(GL_VERSION)
        pymt_logger.info("Window: OpenGL version <%s>" % str(version))

        line_smooth = pymt.pymt_config.getint("graphics", "line_smooth")
        if line_smooth:
            if line_smooth == 1:
                hint = GL_FASTEST
            else:
                hint = GL_NICEST
            glHint(GL_LINE_SMOOTH_HINT, hint)
            glEnable(GL_LINE_SMOOTH)
예제 #9
0
    def init_gl(self):
        version = glGetString(GL_VERSION)
        pymt_logger.info('Window: OpenGL version <%s>' % str(version))

        line_smooth = pymt.pymt_config.getint('graphics', 'line_smooth')
        if line_smooth:
            if line_smooth == 1:
                hint = GL_FASTEST
            else:
                hint = GL_NICEST
            glHint(GL_LINE_SMOOTH_HINT, hint)
            glEnable(GL_LINE_SMOOTH)
예제 #10
0
 def make_fog(self):
     if self.has_gl:
         self.has_fog = 1
         glEnable(GL_FOG)
         glFogf(GL_FOG_MODE, GL_LINEAR)
         glFogf(GL_FOG_DENSITY, 0.2)
         glHint(GL_FOG_HINT, GL_NICEST)
         c = self.camera.GetDistance()
         s = self.slab
         z = self.zpos
         glFogf(GL_FOG_START, c - z - s / 2.)
         glFogf(GL_FOG_END, c - z + s / 2.)
         self.renwin.Render()
예제 #11
0
파일: gfx.py 프로젝트: ggoret/VEDA
	def make_fog(self):
		if self.has_gl :
			self.has_fog=1
			glEnable(GL_FOG)
			glFogf(GL_FOG_MODE, GL_LINEAR)
			glFogf(GL_FOG_DENSITY,0.2)
			glHint(GL_FOG_HINT, GL_NICEST)
			c=self.camera.GetDistance()
			s=self.slab
			z=self.zpos
			glFogf(GL_FOG_START, c-z-s/2.)
			glFogf(GL_FOG_END, c-z+s/2.)
			self.renwin.Render()
예제 #12
0
파일: fonts.py 프로젝트: zfountas/mesh
def get_textureid_with_text(text, fgcolor, bgcolor):
    if not hasattr(get_textureid_with_text, 'cache'):
        get_textureid_with_text.cache = {}

    import zlib
    uid = str(zlib.crc32(text)) + str(zlib.crc32(np.array(fgcolor))) + str(
        zlib.crc32(np.array(bgcolor)))
    if uid not in get_textureid_with_text.cache:
        from PIL import ImageFont
        from PIL import Image
        from PIL import ImageDraw

        font = ImageFont.truetype(
            os.path.join(os.path.dirname(__file__), "ressources", "Arial.ttf"),
            100)

        imsize = (128, 128)

        bgarray = np.asarray(np.zeros((imsize[0], imsize[1], 3)), np.uint8)
        bgarray[:, :, 0] += bgcolor[0]
        bgarray[:, :, 1] += bgcolor[1]
        bgarray[:, :, 2] += bgcolor[2]
        img = Image.fromarray(bgarray)
        draw = ImageDraw.Draw(img)
        w, h = draw.textsize(text, font=font)
        text_pos = ((imsize[0] - w) / 2, (imsize[1] - h) / 2)
        draw.text(text_pos,
                  text,
                  fill=tuple(np.asarray(fgcolor, np.uint8)),
                  font=font)
        texture_data = np.asarray(
            np.array(img.getdata()).reshape(img.size[0], img.size[1], 3) * 255,
            np.uint8)

        textureID = glGenTextures(1)
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
        glBindTexture(GL_TEXTURE_2D, textureID)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture_data.shape[1],
                     texture_data.shape[0], 0, GL_BGR, GL_UNSIGNED_BYTE,
                     texture_data.flatten())
        glHint(GL_GENERATE_MIPMAP_HINT,
               GL_NICEST)  # must be GL_FASTEST, GL_NICEST or GL_DONT_CARE
        glGenerateMipmap(GL_TEXTURE_2D)
        get_textureid_with_text.cache[uid] = textureID

    return get_textureid_with_text.cache[uid]
예제 #13
0
    def resizeGL(self, w, h):
        '''
		Resize the GL window
		'''

        glViewport(0, 0, w, h)
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        glOrtho(0, w, h, 0, -1, 1)
        glMatrixMode(GL_MODELVIEW)
        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
        self.w = w
        self.h = h

        if self.logoon == "On":
            if self.logo[0] and len(self.logo) == 5:
                self.logo[4].setDrawRect([0, 0, w, h])
예제 #14
0
    def initializeGL(self):
        print("initializeGL")
        self.texNumeros, self.texDecor = self.load_textures()
        glEnable(GL_TEXTURE_2D)
        glShadeModel(GL_SMOOTH)
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_CULL_FACE)

        glFrontFace(GL_CCW)

        light_ambient = [0.3, 0.3, 0.3, 0.1]

        glEnable(GL_LIGHTING)
        lightpos = (0, 0, 50)
        glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient)
        glLightfv(GL_LIGHT0, GL_POSITION, lightpos)
        glEnable(GL_LIGHT0)
        glEnable(GL_COLOR_MATERIAL)
        glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE)

        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
예제 #15
0
    def InitGL(self, Width, Height):
        self.view_port_xr = 1
        self.view_port_yr = 1
        self.original_x = Width
        self.original_y = Height

        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity()
        glOrtho(0, Width, 0, Height, -1, 1)
        glScalef(1, -1, 1)
        glTranslatef(0, -Height, 0)
        glMatrixMode(GL_MODELVIEW)
        glDisable(GL_DEPTH_TEST)  # Disables Depth Testing
        glShadeModel(GL_SMOOTH)  # Enables Smooth Color Shading

        # Anti-aliasing/prettyness stuff
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glEnable(GL_BLEND)
        glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
        glHint(GL_POINT_SMOOTH_HINT, GL_NICEST)
        glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST)
        glEnable(GL_LINE_SMOOTH)
        glEnable(GL_POINT_SMOOTH)
        glEnable(GL_POLYGON_SMOOTH)
        glClearColor(background_color()[0],
                     background_color()[1],
                     background_color()[2], 1.0)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
예제 #16
0
    def initializeGL(self):
        # We call this right after our OpenGL window is created.
        glClearColor(1.0, 1.0, 1.0, 1.0)
        glClearDepth(1.0)
        glDepthFunc(GL_LESS)
        glEnable(GL_DEPTH_TEST)
        glShadeModel(GL_SMOOTH)

        glEnable(GL_NORMALIZE)
        light_position = (0., 0., 1., 0.)
        white_light = (1., 1., 1., 0.501)
        d_light = (1., 1., 1., 0.01)
        spec = (1., 1., 1., 0.08)
        glLightfv(GL_LIGHT0, GL_POSITION, light_position)
        glLightfv(GL_LIGHT0, GL_AMBIENT, white_light)
        #glLightfv(GL_LIGHT0, GL_DIFFUSE,  d_light)
        glLightfv(GL_LIGHT0, GL_SPECULAR, spec)

        glEnable(GL_LIGHTING)
        glEnable(GL_LIGHT0)

        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        #glBlendFunc(GL_SRC_ALPHA,GL_ONE)
        glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
        glEnable(GL_COLOR_MATERIAL)
        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()

        gluPerspective(
            45.0,
            float(self.size().height()) / float(self.size().width()), 0.1,
            1000000.0)

        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        self.rotation = [0.0, 0.0]
        self.mesh.prepDraw()
예제 #17
0
	def initializeGL(self):
		# We call this right after our OpenGL window is created.
		glClearColor(1.0, 1.0, 1.0, 1.0)
		glClearDepth(1.0)
		glDepthFunc(GL_LESS)
		glEnable(GL_DEPTH_TEST)
		glShadeModel(GL_SMOOTH)

		glEnable(GL_NORMALIZE)
		light_position = (0., 0., 1., 0.)
		white_light = (1., 1., 1., 0.501)
		d_light = (1., 1., 1., 0.01)
		spec = (1., 1., 1., 0.08)
		glLightfv(GL_LIGHT0, GL_POSITION, light_position)
		glLightfv(GL_LIGHT0, GL_AMBIENT,  white_light)
		#glLightfv(GL_LIGHT0, GL_DIFFUSE,  d_light)
		glLightfv(GL_LIGHT0, GL_SPECULAR, spec)

		glEnable(GL_LIGHTING)
		glEnable(GL_LIGHT0)

		glEnable(GL_BLEND)
		glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
		#glBlendFunc(GL_SRC_ALPHA,GL_ONE)
		glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
		glEnable(GL_COLOR_MATERIAL)
		glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)

		glMatrixMode(GL_PROJECTION)
		glLoadIdentity()

		gluPerspective(45.0, float(self.size().height())/
						float(self.size().width()), 0.1, 1000000.0)

		glMatrixMode(GL_MODELVIEW)
		glLoadIdentity()
		self.rotation = [0.0, 0.0]
		self.mesh.prepDraw()
예제 #18
0
    def init_opengl(self):
        """A general OpenGL initialization function.  Sets all of the initial parameters.

        We call this right after our OpenGL window is created.
        """

        glClearColor(0.0, 0.0, 0.0,
                     1.0)  # This Will Clear The Background Color To Black
        glClearDepth(1.0)  # Enables Clearing Of The Depth Buffer
        glDepthFunc(GL_LEQUAL)  # The Type Of Depth Test To Do
        glEnable(GL_DEPTH_TEST)  # Enables Depth Testing
        glShadeModel(GL_SMOOTH)
        glHint(GL_PERSPECTIVE_CORRECTION_HINT,
               GL_NICEST)  # Really Nice Perspective Calculations

        glEnable(GL_LIGHT0)
        glEnable(GL_LIGHTING)

        glEnable(GL_COLOR_MATERIAL)
        glEnable(
            GL_NORMALIZE)  # important since we rescale the modelview matrix

        return True
예제 #19
0
파일: Qt.py 프로젝트: simply-nicky/cbc
 def paint(self):
     """
     Draw grid object
     """
     self.setupGLState()
     if self.antialias:
         glEnable(GL_LINE_SMOOTH)
         glEnable(GL_BLEND)
         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
         glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
     glBegin(GL_LINES)
     _x, _y = self.size()
     _xs, _ys = self.spacing()
     _x_vals = np.arange(0, _x + _xs * 0.001, _xs)
     _y_vals = np.arange(0, _y + _ys * 0.001, _ys)
     glColor4f(*self.color)
     for x in _x_vals:
         glVertex3f(x, _y_vals[0], 0)
         glVertex3f(x, _y_vals[-1], 0)
     for y in _y_vals:
         glVertex3f(_x_vals[0], y, 0)
         glVertex3f(_x_vals[-1], y, 0)
     glEnd()
예제 #20
0
    def paint(self):
        self.setupGLState()

        if self.antialias:
            glEnable(GL_LINE_SMOOTH)
            glEnable(GL_BLEND)
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
            glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)

        glBegin(GL_LINES)

        x, y = self.size()
        xs, ys = self.spacing()
        xvals = np.arange(0, x + xs * 0.001, xs)
        yvals = np.arange(0, y + ys * 0.001, ys)
        glColor4f(*self.color)
        for x in xvals:
            glVertex3f(x, yvals[0], 0)
            glVertex3f(x, yvals[-1], 0)
        for y in yvals:
            glVertex3f(xvals[0], y, 0)
            glVertex3f(xvals[-1], y, 0)

        glEnd()
예제 #21
0
파일: items.py 프로젝트: unrza72/qplotutils
    def paint(self):
        super(Grid, self).paint()

        glEnable(GL_LINE_SMOOTH)
        glEnable(GL_POLYGON_SMOOTH)
        glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
        glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        glLineWidth(1.3)
        glBegin(GL_LINES)  # lgtm [py/call/wrong-arguments]

        xvals = np.linspace(-self.x / 2.0, self.x / 2.0, self.x / self.xs + 1)
        yvals = np.linspace(-self.y / 2.0, self.y / 2.0, self.y / self.ys + 1)

        glColor4f(*self.edge_color)
        for x in xvals:
            glVertex3f(x, yvals[0], 0)
            glVertex3f(x, yvals[-1], 0)
        for y in yvals:
            glVertex3f(xvals[0], y, 0)
            glVertex3f(xvals[-1], y, 0)
        glEnd()  # lgtm [py/call/wrong-arguments]
예제 #22
0
    def gl_init(self):
        #must be called within a context!
        #performs init if needed
        if not self.debug_setup:
            self.debug_setup = True
            self.gl_init_debug()

        if not self.gl_setup:
            mt = get_max_texture_size()
            rw, rh = self.render_size
            w, h = self.size
            if w>mt or h>mt:
                raise Exception("invalid texture dimensions %ix%i, maximum is %i" % (w, h, mt))
            self.gl_marker("Initializing GL context for window size %s, backing size %s, max texture size=%i",
                           self.render_size, self.size, mt)
            # Initialize viewport and matrices for 2D rendering
            x, _, _, y = self.offsets
            glViewport(x, y, w, h)
            glMatrixMode(GL_PROJECTION)
            glLoadIdentity()
            glOrtho(0.0, w, h, 0.0, -1.0, 1.0)
            glMatrixMode(GL_MODELVIEW)
            # Mesa docs claim: this hint can improve the speed of texturing
            #when perspective-correct texture coordinate interpolation isn't needed,
            #such as when using a glOrtho() projection:
            glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST)
            # Could be more optimal to use vertex arrays:
            # glEnableClientState(GL_VERTEX_ARRAY)
            # glEnableClientState(GL_TEXTURE_COORD_ARRAY)

            # Clear background to transparent black
            glClearColor(0.0, 0.0, 0.0, 0.0)

            # we don't use the depth (2D only):
            glDisable(GL_DEPTH_TEST)
            glDisable(GL_SCISSOR_TEST)
            glDisable(GL_LIGHTING)
            glDisable(GL_DITHER)
            # only do alpha blending in present_fbo:
            glDisable(GL_BLEND)

            # Default state is good for YUV painting:
            #  - fragment program enabled
            #  - YUV fragment program bound
            #  - render to offscreen FBO
            if self.textures is None:
                self.gl_init_textures()

            mag_filter = GL_NEAREST
            if float(rw)/w!=rw//w or float(rh)/h!=rh//h:
                #non integer scaling, use linear magnification filter:
                mag_filter = GL_LINEAR

            log("initializing FBOs")
            # Define empty tmp FBO
            target = GL_TEXTURE_RECTANGLE_ARB
            glBindTexture(target, self.textures[TEX_TMP_FBO])
            glTexParameteri(target, GL_TEXTURE_MAG_FILTER, mag_filter)
            glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
            glTexImage2D(target, 0, self.internal_format, w, h, 0, self.texture_pixel_format, GL_UNSIGNED_BYTE, None)
            glBindFramebuffer(GL_FRAMEBUFFER, self.tmp_fbo)
            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, self.textures[TEX_TMP_FBO], 0)
            glClear(GL_COLOR_BUFFER_BIT)

            # Define empty FBO texture and set rendering to FBO
            glBindTexture(target, self.textures[TEX_FBO])
            # nvidia needs this even though we don't use mipmaps (repeated through this file):
            glTexParameteri(target, GL_TEXTURE_MAG_FILTER, mag_filter)
            glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
            glTexImage2D(target, 0, self.internal_format, w, h, 0, self.texture_pixel_format, GL_UNSIGNED_BYTE, None)
            glBindFramebuffer(GL_FRAMEBUFFER, self.offscreen_fbo)
            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, self.textures[TEX_FBO], 0)
            glClear(GL_COLOR_BUFFER_BIT)

            glBindTexture(target, 0)

            # Create and assign fragment programs
            if not self.shaders:
                self.gl_init_shaders()

            # Bind program 0 for YUV painting by default
            glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, self.shaders[YUV2RGB_SHADER])
            self.gl_setup = True
            log("gl_init() done")
예제 #23
0
    def gl_init(self):
        #must be called within a context!
        #performs init if needed
        if not self.debug_setup:
            self.debug_setup = True
            self.gl_init_debug()

        if not self.gl_setup:
            w, h = self.size
            self.gl_marker("Initializing GL context for window size %s, backing size %s", self.render_size, self.size)
            # Initialize viewport and matrices for 2D rendering
            x, _, _, y = self.offsets
            glViewport(x, y, w, h)
            glMatrixMode(GL_PROJECTION)
            glLoadIdentity()
            glOrtho(0.0, w, h, 0.0, -1.0, 1.0)
            glMatrixMode(GL_MODELVIEW)
            # Mesa docs claim: this hint can improve the speed of texturing
            #when perspective-correct texture coordinate interpolation isn't needed,
            #such as when using a glOrtho() projection:
            glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST)
            # Could be more optimal to use vertex arrays:
            # glEnableClientState(GL_VERTEX_ARRAY)
            # glEnableClientState(GL_TEXTURE_COORD_ARRAY)

            # Clear background to transparent black
            glClearColor(0.0, 0.0, 0.0, 0.0)

            # we don't use the depth (2D only):
            glDisable(GL_DEPTH_TEST)
            glDisable(GL_SCISSOR_TEST)
            glDisable(GL_LIGHTING)
            glDisable(GL_DITHER)
            # only do alpha blending in present_fbo:
            glDisable(GL_BLEND)

            # Default state is good for YUV painting:
            #  - fragment program enabled
            #  - YUV fragment program bound
            #  - render to offscreen FBO
            if self.textures is None:
                self.gl_init_textures()

            def clear_fbo():
                try:
                    glClear(GL_COLOR_BUFFER_BIT)
                except Exception as e:
                    log("glClear error", exc_info=True)
                    log.warn("Warning: failed to clear FBO")
                    log.warn(" %r", e)
                    if getattr(e, "err", None)==1286:
                        raise Exception("OpenGL error '%r' likely caused by buggy drivers" % e)

            # Define empty tmp FBO
            glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_TMP_FBO])
            set_texture_level()
            glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, self.texture_pixel_format, w, h, 0, self.texture_pixel_format, GL_UNSIGNED_BYTE, None)
            glBindFramebuffer(GL_FRAMEBUFFER, self.tmp_fbo)
            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_TMP_FBO], 0)
            clear_fbo()

            # Define empty FBO texture and set rendering to FBO
            glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO])
            # nvidia needs this even though we don't use mipmaps (repeated through this file):
            set_texture_level()
            glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, self.texture_pixel_format, w, h, 0, self.texture_pixel_format, GL_UNSIGNED_BYTE, None)
            glBindFramebuffer(GL_FRAMEBUFFER, self.offscreen_fbo)
            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO], 0)
            clear_fbo()

            # Create and assign fragment programs
            if not self.shaders:
                self.gl_init_shaders()

            # Bind program 0 for YUV painting by default
            glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, self.shaders[YUV2RGB_SHADER])
            glEnable(GL_FRAGMENT_PROGRAM_ARB)
            self.gl_setup = True
예제 #24
0
 def hint(cls, name: FogParam, val: FogParam):
     glHint(name.value, val.value)
예제 #25
0
    def gl_init(self):
        #must be called within a context!
        #performs init if needed
        if not self.debug_setup:
            self.debug_setup = True
            self.gl_init_debug()

        if not self.gl_setup:
            w, h = self.size
            self.gl_marker("Initializing GL context for window size %d x %d",
                           w, h)
            # Initialize viewport and matrices for 2D rendering
            glViewport(0, 0, w, h)
            glMatrixMode(GL_PROJECTION)
            glLoadIdentity()
            glOrtho(0.0, w, h, 0.0, -1.0, 1.0)
            glMatrixMode(GL_MODELVIEW)
            # Mesa docs claim: this hint can improve the speed of texturing
            #when perspective-correct texture coordinate interpolation isn't needed,
            #such as when using a glOrtho() projection:
            glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST)
            # Could be more optimal to use vertex arrays:
            # glEnableClientState(GL_VERTEX_ARRAY)
            # glEnableClientState(GL_TEXTURE_COORD_ARRAY)

            # Clear background to transparent black
            glClearColor(0.0, 0.0, 0.0, 0.0)

            # we don't use the depth (2D only):
            glDisable(GL_DEPTH_TEST)
            # only do alpha blending in present_fbo:
            glDisable(GL_BLEND)

            # Default state is good for YUV painting:
            #  - fragment program enabled
            #  - YUV fragment program bound
            #  - render to offscreen FBO
            if self.textures is None:
                self.gl_init_textures()

            # Define empty FBO texture and set rendering to FBO
            glEnable(GL_FRAGMENT_PROGRAM_ARB)
            glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO])
            # nvidia needs this even though we don't use mipmaps (repeated through this file):
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0)
            glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0,
                         self.texture_pixel_format, w, h, 0,
                         self.texture_pixel_format, GL_UNSIGNED_BYTE, None)
            glBindFramebuffer(GL_FRAMEBUFFER, self.offscreen_fbo)
            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                                   GL_TEXTURE_RECTANGLE_ARB,
                                   self.textures[TEX_FBO], 0)
            glClear(GL_COLOR_BUFFER_BIT)

            # Create and assign fragment programs
            if not self.shaders:
                self.gl_init_shaders()

            # Bind program 0 for YUV painting by default
            glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB,
                             self.shaders[YUV2RGB_SHADER])
            self.gl_setup = True
예제 #26
0
파일: items.py 프로젝트: unrza72/qplotutils
    def paint(self):
        self._applyGLOptions()

        if self.__antialiasing:
            glEnable(GL_LINE_SMOOTH)
            glEnable(GL_BLEND)
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
            glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
            glLineWidth(1.5)

        if self.draw_faces:
            # need face
            with self.shader_program:
                glEnableClientState(GL_VERTEX_ARRAY)

                glVertexPointerf(self.mesh.face_vertices)
                glColor4f(*self.face_color)

                glEnableClientState(GL_NORMAL_ARRAY)
                glNormalPointerf(self.mesh.face_normal_vectors)

                glDrawArrays(GL_TRIANGLES, 0,
                             np.product(self.mesh.face_vertices.shape[:-1]))

                glDisableClientState(GL_NORMAL_ARRAY)
                glDisableClientState(GL_VERTEX_ARRAY)
                glDisableClientState(GL_COLOR_ARRAY)

        if self.debug_face_normals:
            # Visualize the face normal vectors
            glEnableClientState(GL_VERTEX_ARRAY)

            N = self.mesh.face_vertices.shape[0] * 3
            v = np.concatenate([
                self.mesh.face_vertices,
                self.mesh.face_vertices + self.mesh.face_normal_vectors,
            ])
            e = np.array([np.arange(N), np.arange(N) + N]).T.flatten()

            glColor4f(1.0, 1.0, 0.0, 1.0)
            glVertexPointerf(v)
            glDrawElements(GL_LINES, e.shape[0], GL_UNSIGNED_INT, e)

            glDisableClientState(GL_VERTEX_ARRAY)
            glDisableClientState(GL_COLOR_ARRAY)

        if self.debug_face_edges:
            # visualize all face edges
            glEnableClientState(GL_VERTEX_ARRAY)
            glVertexPointerf(self.mesh.wireframe_vertices)

            glColor4f(1.0, 1.0, 0.0, 1.0)
            edges = self.mesh.face_edges.flatten()
            glDrawElements(GL_LINES, edges.shape[0], GL_UNSIGNED_INT, edges)

            glDisableClientState(GL_VERTEX_ARRAY)
            glDisableClientState(GL_COLOR_ARRAY)

        if self.draw_wireframe and self.mesh.has_wireframe:
            # draw a mesh wireframe which may or may not be identical to the face edges, depending on the mesh
            glEnableClientState(GL_VERTEX_ARRAY)
            glVertexPointerf(self.mesh.wireframe_vertices)
            glColor4f(0, 1, 0, 1)
            edges = self.mesh.wireframe_edges.flatten()
            glDrawElements(GL_LINES, edges.shape[0], GL_UNSIGNED_INT, edges)

            glDisableClientState(GL_VERTEX_ARRAY)
            glDisableClientState(GL_COLOR_ARRAY)
예제 #27
0
 def initGL(self):
     glEnable(GL_CULL_FACE)
     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
예제 #28
0
    def gl_init(self):
        #must be called within a context!
        #performs init if needed
        if not self.debug_setup:
            self.debug_setup = True
            self.gl_init_debug()

        if not self.gl_setup:
            w, h = self.size
            self.gl_marker("Initializing GL context for window size %s, backing size %s", self.render_size, self.size)
            # Initialize viewport and matrices for 2D rendering
            glViewport(0, 0, w, h)
            glMatrixMode(GL_PROJECTION)
            glLoadIdentity()
            glOrtho(0.0, w, h, 0.0, -1.0, 1.0)
            glMatrixMode(GL_MODELVIEW)
            # Mesa docs claim: this hint can improve the speed of texturing
            #when perspective-correct texture coordinate interpolation isn't needed,
            #such as when using a glOrtho() projection:
            glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST)
            # Could be more optimal to use vertex arrays:
            # glEnableClientState(GL_VERTEX_ARRAY)
            # glEnableClientState(GL_TEXTURE_COORD_ARRAY)

            # Clear background to transparent black
            glClearColor(0.0, 0.0, 0.0, 0.0)

            # we don't use the depth (2D only):
            glDisable(GL_DEPTH_TEST)
            glDisable(GL_SCISSOR_TEST)
            glDisable(GL_LIGHTING)
            glDisable(GL_DITHER)
            # only do alpha blending in present_fbo:
            glDisable(GL_BLEND)

            # Default state is good for YUV painting:
            #  - fragment program enabled
            #  - YUV fragment program bound
            #  - render to offscreen FBO
            if self.textures is None:
                self.gl_init_textures()

            def clear_fbo():
                try:
                    glClear(GL_COLOR_BUFFER_BIT)
                except Exception as e:
                    log("glClear error", exc_info=True)
                    log.warn("Warning: failed to clear FBO")
                    log.warn(" %r", e)
                    if getattr(e, "err", None)==1286:
                        raise Exception("OpenGL error '%r' likely caused by buggy drivers" % e)

            # Define empty tmp FBO
            glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_TMP_FBO])
            set_texture_level()
            glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, self.texture_pixel_format, w, h, 0, self.texture_pixel_format, GL_UNSIGNED_BYTE, None)
            glBindFramebuffer(GL_FRAMEBUFFER, self.tmp_fbo)
            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_TMP_FBO], 0)
            clear_fbo()

            # Define empty FBO texture and set rendering to FBO
            glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO])
            # nvidia needs this even though we don't use mipmaps (repeated through this file):
            set_texture_level()
            glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, self.texture_pixel_format, w, h, 0, self.texture_pixel_format, GL_UNSIGNED_BYTE, None)
            glBindFramebuffer(GL_FRAMEBUFFER, self.offscreen_fbo)
            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_RECTANGLE_ARB, self.textures[TEX_FBO], 0)
            clear_fbo()

            # Create and assign fragment programs
            if not self.shaders:
                self.gl_init_shaders()

            # Bind program 0 for YUV painting by default
            glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, self.shaders[YUV2RGB_SHADER])
            glEnable(GL_FRAGMENT_PROGRAM_ARB)
            self.gl_setup = True