예제 #1
0
    def __init__(self, width, height):
        super().__init__()

        buffer_format = QOpenGLFramebufferObjectFormat()
        buffer_format.setAttachment(QOpenGLFramebufferObject.Depth)
        self._fbo = QOpenGLFramebufferObject(width, height, buffer_format)

        self._contents = None
예제 #2
0
    def createFramebufferObject(self, size):
        format = QOpenGLFramebufferObjectFormat()
        format.setAttachment(QOpenGLFramebufferObject.CombinedDepthStencil)
        format.setSamples(4)

        self._qfbo = QOpenGLFramebufferObject(size, format)
        return self._qfbo
    def createFramebuffer(self, gl, dim, depth=False, filter=None, internalFormat=None, format=None, type=None):
        ''' Creates framebuffer object with required parameters '''
        if filter is None: filter = gl.GL_LINEAR
        framebuffer = QOpenGLFramebufferObject(dim, dim)
        if depth: framebuffer.setAttachment(QOpenGLFramebufferObject.Depth)
        textureId = framebuffer.texture()
        assert textureId >= 0

        gl.glBindTexture(gl.GL_TEXTURE_2D, textureId)
        gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, filter)
        gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, filter)
        if internalFormat and format and type:
            gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, internalFormat, dim, dim, 0, format, type, None)
        gl.glBindTexture(gl.GL_TEXTURE_2D, 0)

        return framebuffer
예제 #4
0
    def animate(self):
        #print("OpenGL Version: ",GL.glGetString(GL.GL_VERSION))
        #print("OpenGL Vendor: ",GL.glGetString(GL.GL_VENDOR))
        #print("OpenGL Renderer: ",GL.glGetString(GL.GL_RENDERER))

        # build a new frame number self.frameid

        self.an += 0.05

        self.counter += 1

        self.frameid += 1

        sid = 0

        #MY ATTEMPT TO SAVE TO HIGHER RESOLUTION THAN SCREEN in other frame buffer
        #GL.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
        tempw = 2000
        temph = 2000

        print("OpenGL MAX TEXTURE SIZE: ",
              GL.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE))
        print("OpenGL VIEWPORT DIMS: ", GL.glGetIntegerv(GL.GL_VIEWPORT))
        attachment = 2  # default =< try 2 for depth
        self.fbo = QOpenGLFramebufferObject(
            QtCore.QSize(tempw, temph), attachment, GL.GL_TEXTURE_2D,
            GL.GL_RGB8)  #,GL.GL_COLOR_ATTACHMENT0)#,GL.GL_RGB)

        self.fbo.bind()
        self.resizeGL(tempw, temph)
        self.paintGL()

        buffer = GL.glReadPixels(0, 0, tempw, temph, GL.GL_RGB,
                                 GL.GL_UNSIGNED_BYTE, None)

        print('buffer', len(buffer), tempw, temph)
        image = Image.frombytes(mode="RGB", size=(tempw, temph), data=buffer)
        image = image.transpose(Image.FLIP_TOP_BOTTOM)
        fname = 'D:/Users/Antoine/Documents/copenhague-1/togit/gaussian_forAntoine/doughnut/frame_nb_' + str(
            self.counter) + '.png'
        image.save(fname)
        self.fbo.release()

        self.resizeGL(self.width, self.height)

        self.update()
예제 #5
0
 def createFramebufferObject(self, size):
     #print("\n\nLogoInFboRenderer.createFramebufferObject", size)#, QApplication.instance()
     format = QOpenGLFramebufferObjectFormat()
     format.setAttachment(QOpenGLFramebufferObject.CombinedDepthStencil)
     format.setSamples(4)
     self.frmBuffer = QOpenGLFramebufferObject(size, format)
     #print("hola3", self.frmBuffer)
     return self.frmBuffer
예제 #6
0
    def __init__(self, width, height):
        super().__init__()

        buffer_format = QOpenGLFramebufferObjectFormat()
        buffer_format.setAttachment(QOpenGLFramebufferObject.Depth)
        self._fbo = QOpenGLFramebufferObject(width, height, buffer_format)

        self._contents = None
예제 #7
0
class QtFrameBufferObject(FrameBufferObject):
    def __init__(self, width, height):
        super().__init__()

        buffer_format = QOpenGLFramebufferObjectFormat()
        buffer_format.setAttachment(QOpenGLFramebufferObject.Depth)
        self._fbo = QOpenGLFramebufferObject(width, height, buffer_format)

        self._contents = None

    def bind(self):
        self._contents = None
        self._fbo.bind()

    def release(self):
        self._fbo.release()

    def getTextureId(self):
        return self._fbo.texture()

    def getContents(self):
        if not self._contents:
            self._contents = self._fbo.toImage()

        return self._contents
예제 #8
0
class FrameBufferObject:
    """An interface for OpenGL FrameBuffer Objects.

    This class describes a minimal interface that is expected of FrameBuffer Object
    classes.
    """
    def __init__(self, width: int, height: int) -> None:
        super().__init__()

        buffer_format = QOpenGLFramebufferObjectFormat()
        buffer_format.setAttachment(QOpenGLFramebufferObject.Depth)
        self._fbo = QOpenGLFramebufferObject(width, height, buffer_format)

        self._contents = None

    def getTextureId(self) -> int:
        """Get the texture ID of the texture target of this FBO."""
        return self._fbo.texture()

    def bind(self) -> None:
        """Bind the FBO so it can be rendered to."""
        self._contents = None
        self._fbo.bind()

    def release(self) -> None:
        """Release the FBO so it will no longer be rendered to."""
        self._fbo.release()

    def getContents(self) -> QImage:
        """Get the contents of the FBO as an image data object."""
        if not self._contents:
            self._contents = self._fbo.toImage()

        return self._contents
예제 #9
0
class FrameBufferObject:
    def __init__(self, width, height):
        super().__init__()

        buffer_format = QOpenGLFramebufferObjectFormat()
        buffer_format.setAttachment(QOpenGLFramebufferObject.Depth)
        self._fbo = QOpenGLFramebufferObject(width, height, buffer_format)

        self._contents = None

    ##  Get the texture ID of the texture target of this FBO.
    def getTextureId(self):
        return self._fbo.texture()

    ##  Bind the FBO so it can be rendered to.
    def bind(self):
        self._contents = None
        self._fbo.bind()

    ##  Release the FBO so it will no longer be rendered to.
    def release(self):
        self._fbo.release()

    ##  Get the contents of the FBO as an image data object.
    def getContents(self):
        if not self._contents:
            self._contents = self._fbo.toImage()

        return self._contents
예제 #10
0
class QtFrameBufferObject(FrameBufferObject):
    def __init__(self, width, height):
        super().__init__()

        buffer_format = QOpenGLFramebufferObjectFormat()
        buffer_format.setAttachment(QOpenGLFramebufferObject.Depth)
        self._fbo = QOpenGLFramebufferObject(width, height, buffer_format)

        self._contents = None

    def bind(self):
        self._contents = None
        self._fbo.bind()

    def release(self):
        self._fbo.release()

    def getTextureId(self):
        return self._fbo.texture()

    def getContents(self):
        if not self._contents:
            self._contents = self._fbo.toImage()

        return self._contents
예제 #11
0
class FrameBufferObject:
    def __init__(self, width, height):
        super().__init__()

        buffer_format = QOpenGLFramebufferObjectFormat()
        buffer_format.setAttachment(QOpenGLFramebufferObject.Depth)
        self._fbo = QOpenGLFramebufferObject(width, height, buffer_format)

        self._contents = None

    ##  Get the texture ID of the texture target of this FBO.
    def getTextureId(self):
        return self._fbo.texture()

    ##  Bind the FBO so it can be rendered to.
    def bind(self):
        self._contents = None
        self._fbo.bind()

    ##  Release the FBO so it will no longer be rendered to.
    def release(self):
        self._fbo.release()

    ##  Get the contents of the FBO as an image data object.
    def getContents(self):
        if not self._contents:
            self._contents = self._fbo.toImage()

        return self._contents
예제 #12
0
 def get_frame_cv(self, width, height):
     fmt = QOpenGLFramebufferObjectFormat()
     fmt.setSamples(self.fmt.samples())
     fbo = QOpenGLFramebufferObject(width, height)
     fbo.setAttachment(fbo.Depth)
     fbo.bind()
     GL.glFinish()
     # resize framebuffer to desired resolution
     self.resizeGL(width, height)
     # draw the scene
     self.update_scene()
     self.glDraw()
     GL.glFinish()
     # read the raw image data
     img = GL.glReadPixels(0, 0, width, height, GL.GL_RGB,
                           GL.GL_UNSIGNED_BYTE)
     # convert raw image data to cv2 format
     img = np.reshape(np.frombuffer(img, np.ubyte), (height, width, 3))
     img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
     img = cv2.flip(img, 0)
     fbo.release()
     return img
예제 #13
0
 def createFrameBuffer(self, width, height):
     buffer_format = QOpenGLFramebufferObjectFormat()
     buffer_format.setAttachment(QOpenGLFramebufferObject.Depth)
     return QOpenGLFramebufferObject(width, height, buffer_format)
예제 #14
0
    def animate(self):
        #print("OpenGL Version: ",GL.glGetString(GL.GL_VERSION))
        #print("OpenGL Vendor: ",GL.glGetString(GL.GL_VENDOR))
        #print("OpenGL Renderer: ",GL.glGetString(GL.GL_RENDERER))

        # build a new frame number self.frameid

        self.an += 0.05

        self.counter += 1

        self.frameid += 1

        sid = 0

        zarr = np.linspace(
            self.center_mass[self.counter % self.nbframes] + self.ZL,
            self.center_mass[self.counter % self.nbframes] + self.ZR,
            2 * 64 * 2,
            endpoint=True
        )  #z axis #defined with normalized length #for real axis *L
        xarr = np.linspace(
            self.YB, self.YT, 64 * 2, endpoint=True
        )  #x axis #defined with normalizad length #for real axis *L

        data = np.array([
            [It0((zi + z0 / L) * L, xi * L, 0.0) for zi in zarr] for xi in xarr
        ])  #stores the information about the intensity profile

        # map the normalized data to colors
        # image is now RGBA
        cmap = plt.cm.viridis  #hot#viridis
        norm = plt.Normalize(vmin=0.0, vmax=np.max(data))  #
        image = cmap(norm(data))

        #image = cmap(data)
        # save the image
        plt.imsave('tmp.png', image)

        #something misterious
        i = self.lasti0
        self.texture_id.append(i)

        img = Image.open('tmp.png').convert("RGBA")
        d = ImageDraw.Draw(img)
        d.text(
            (0, 0),
            str('%.6f' % (self.center_mass[self.counter % self.nbframes] * L)),
            fill=(255, 255, 255, 255))
        itm = np.asarray(img)
        itm2 = itm.copy()
        #itm2[:,:,0] = data[:,:]
        self.pixels.append(itm2)
        print('done')
        self.lasti0 = i + 1

        #MY ATTEMPT TO SAVE TO HIGHER RESOLUTION THAN SCREEN in other frame buffer
        #GL.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
        tempw = 2000
        temph = 2000

        #print("OpenGL MAX TEXTURE SIZE: ", GL.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE))
        #print("OpenGL VIEWPORT DIMS: ",GL.glGetIntegerv(GL.GL_VIEWPORT))
        attachment = 2  # default =< try 2 for depth
        self.fbo = QOpenGLFramebufferObject(
            QtCore.QSize(tempw, temph), attachment, GL.GL_TEXTURE_2D,
            GL.GL_RGB8)  #,GL.GL_COLOR_ATTACHMENT0)#,GL.GL_RGB)

        self.fbo.bind()
        self.resizeGL(tempw, temph)
        self.paintGL()

        buffer = GL.glReadPixels(0, 0, tempw, temph, GL.GL_RGB,
                                 GL.GL_UNSIGNED_BYTE, None)

        #print('buffer',len(buffer), tempw,temph)
        image = Image.frombytes(mode="RGB", size=(tempw, temph), data=buffer)
        image = image.transpose(Image.FLIP_TOP_BOTTOM)
        fname = 'D:/Users/Antoine/Documents/copenhague-1/togit/MyMCPython/doughnut_' + simulation_name + '_frame_nb_' + str(
            self.counter) + '.png'
        image.save(fname)
        self.fbo.release()

        self.resizeGL(self.width, self.height)

        self.update()
예제 #15
0
class GLWidget(QtOpenGL.QGLWidget):
    def __init__(self, parent=None, smooth=True):
        global L
        #super(GLWidget, self).__init__(parent)
        self.parent = parent
        #fmt = QtOpenGL.QGLFormat()

        # QGLFormat.__init__ (self)

        # Constructs a QGLFormat object with the following default settings:
        # Double buffer: Enabled.
        # Depth buffer: Enabled.
        # RGBA: Enabled (i.e., color index disabled).
        # Alpha channel: Disabled.
        # Accumulator buffer: Disabled.
        # Stencil buffer: Enabled.
        # Stereo: Disabled.
        # Direct rendering: Enabled.
        # Overlay: Disabled.
        # Plane: 0 (i.e., normal plane).
        # Multisample buffers: Disabled
        self.bsmooth = smooth
        fmt = QtOpenGL.QGLFormat.defaultFormat()
        fmt.setSampleBuffers(
            True)  # require multi sampling.. works well to fight aliasing
        #fmt.setSamples(4)

        # double buffer is enabled by default and swap buffer should be called automatically after a paintevent.
        super(GLWidget, self).__init__(QtOpenGL.QGLFormat(fmt), parent)

        self.blackbkg = QtGui.QColor.fromRgbF(0.2, 0.2, 0.2,
                                              0.0)  #Black background

        # LOAD TRAJECTORIES
        print("loading trajectories..")
        data = np.load(
            'D:/Users/Antoine/Documents/copenhague-1/togit/MyMCPython/MC_3D_' +
            simulation_name + '.npz',
            allow_pickle=True)
        print(data['sol_arr'].shape)
        self.traj0 = data['sol_arr']  #stores the trajectories
        self.nb = len(self.traj0)
        self.nbframes = len(self.traj0[0].t)
        print('NUMBER OF ATOMS is:', self.nb)

        #print number of frames
        print('number of frames:', self.nbframes)

        # LOAD TRAJECTORIES
        print("loading trajectory center of mass..")
        data = np.load(
            'D:/Users/Antoine/Documents/copenhague-1/togit/MyMCPython/center_mass_'
            + simulation_name + '.npz',
            allow_pickle=True)
        print(data['arr_0'].shape)
        self.center_mass = data['arr_0']  #stores the trajectories

        self.width = 800
        self.height = 600
        # generate the intensity profile images
        self.ZL = -0.1  #minimum point z axis
        self.ZR = 0.1  #maximum point z axis
        self.YB = -0.05  #minimum point x axis
        self.YT = 0.05  #maximum point x axis

        zarr = np.linspace(
            self.center_mass[0] + self.ZL,
            self.center_mass[0] + self.ZR,
            2 * 64 * 2,
            endpoint=True
        )  #z axis #defined with normalized length #for real axis *L
        xarr = np.linspace(
            self.YB, self.YT, 64 * 2, endpoint=True
        )  #x axis #defined with normalizad length #for real axis *L

        self.counter = self.nbframes - 4
        self.texture_id = []
        self.pixels = []

        data = np.array([
            [It0((zi + z0 / L) * L, xi * L, 0.0) for zi in zarr] for xi in xarr
        ])  #stores the information about the intensity profile

        # map the normalized data to colors
        # image is now RGBA
        cmap = plt.cm.viridis  #hot#viridis
        norm = plt.Normalize(vmin=0.0, vmax=np.max(data))  #
        image = cmap(norm(data))

        #image = cmap(data)
        # save the image
        plt.imsave('tmp.png', image)

        #something misterious
        i = 0
        self.texture_id.append(i)

        img = Image.open('tmp.png').convert("RGBA")
        d = ImageDraw.Draw(img)
        d.text((0, 0),
               str('%.6f' % (self.center_mass[self.counter] * L)),
               fill=(255, 255, 255, 255))
        itm = np.asarray(img)
        itm2 = itm.copy()
        #itm2[:,:,0] = data[:,:]
        self.pixels.append(itm2)
        print('done')
        self.lasti0 = i

        # The frames are being built in different threads each 20 ms

        self.frameid = 0
        self.an = 135  #initial vision angle

        self.timer = QtCore.QTimer(self)
        self.timer.timeout.connect(self.animate)
        self.timer.start(20)

    def animate(self):
        #print("OpenGL Version: ",GL.glGetString(GL.GL_VERSION))
        #print("OpenGL Vendor: ",GL.glGetString(GL.GL_VENDOR))
        #print("OpenGL Renderer: ",GL.glGetString(GL.GL_RENDERER))

        # build a new frame number self.frameid

        self.an += 0.05

        self.counter += 1

        self.frameid += 1

        sid = 0

        zarr = np.linspace(
            self.center_mass[self.counter % self.nbframes] + self.ZL,
            self.center_mass[self.counter % self.nbframes] + self.ZR,
            2 * 64 * 2,
            endpoint=True
        )  #z axis #defined with normalized length #for real axis *L
        xarr = np.linspace(
            self.YB, self.YT, 64 * 2, endpoint=True
        )  #x axis #defined with normalizad length #for real axis *L

        data = np.array([
            [It0((zi + z0 / L) * L, xi * L, 0.0) for zi in zarr] for xi in xarr
        ])  #stores the information about the intensity profile

        # map the normalized data to colors
        # image is now RGBA
        cmap = plt.cm.viridis  #hot#viridis
        norm = plt.Normalize(vmin=0.0, vmax=np.max(data))  #
        image = cmap(norm(data))

        #image = cmap(data)
        # save the image
        plt.imsave('tmp.png', image)

        #something misterious
        i = self.lasti0
        self.texture_id.append(i)

        img = Image.open('tmp.png').convert("RGBA")
        d = ImageDraw.Draw(img)
        d.text(
            (0, 0),
            str('%.6f' % (self.center_mass[self.counter % self.nbframes] * L)),
            fill=(255, 255, 255, 255))
        itm = np.asarray(img)
        itm2 = itm.copy()
        #itm2[:,:,0] = data[:,:]
        self.pixels.append(itm2)
        print('done')
        self.lasti0 = i + 1

        #MY ATTEMPT TO SAVE TO HIGHER RESOLUTION THAN SCREEN in other frame buffer
        #GL.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
        tempw = 2000
        temph = 2000

        #print("OpenGL MAX TEXTURE SIZE: ", GL.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE))
        #print("OpenGL VIEWPORT DIMS: ",GL.glGetIntegerv(GL.GL_VIEWPORT))
        attachment = 2  # default =< try 2 for depth
        self.fbo = QOpenGLFramebufferObject(
            QtCore.QSize(tempw, temph), attachment, GL.GL_TEXTURE_2D,
            GL.GL_RGB8)  #,GL.GL_COLOR_ATTACHMENT0)#,GL.GL_RGB)

        self.fbo.bind()
        self.resizeGL(tempw, temph)
        self.paintGL()

        buffer = GL.glReadPixels(0, 0, tempw, temph, GL.GL_RGB,
                                 GL.GL_UNSIGNED_BYTE, None)

        #print('buffer',len(buffer), tempw,temph)
        image = Image.frombytes(mode="RGB", size=(tempw, temph), data=buffer)
        image = image.transpose(Image.FLIP_TOP_BOTTOM)
        fname = 'D:/Users/Antoine/Documents/copenhague-1/togit/MyMCPython/doughnut_' + simulation_name + '_frame_nb_' + str(
            self.counter) + '.png'
        image.save(fname)
        self.fbo.release()

        self.resizeGL(self.width, self.height)

        self.update()

    def drawParticles_simplepoints0(self, color_en=False):

        #choose the color you want to use to color the points
        colw = QtGui.QColor.fromRgbF(1.0, 1.0, 1.0, 0.0)  #White
        colb = QtGui.QColor.fromRgbF(0.0, 0.0, 0.0, 0.2)  #Black
        colr = QtGui.QColor.fromRgbF(1.0, 0.0, 0.0, 0.0)  #Red
        colbu = QtGui.QColor.fromRgbF(0.0, 0.0, 1.0, 0.0)  #Blue

        #color chosen black
        self.qglColor(colw)
        GL.glBegin(GL.GL_POINTS)  #initialize points
        col = colw
        self.qglColor(col)

        #Working on the frame number
        i = (self.counter) % len(self.traj0[0].t)
        print('frame:', i)

        #We draw the position of all the particles for this frame
        for sol in self.traj0:
            pz = sol.y[1, i]
            py = sol.y[3, i]
            #px = sol.y[5,i]
            px = 0
            GL.glVertex3f(pz, py, px)  #writes the point (pz,py,px)

        #We stop addind points to this frame
        GL.glEnd()

    # base methods of QWidget
    def minimumSizeHint(self):
        return QtCore.QSize(50, 50)

    def sizeHint(self):
        return QtCore.QSize(800, 600)

    # base methods of QGLWidget (see also updateGL)
    def initializeGL(self):

        #Define Visualization aspects :

        #background color
        self.qglClearColor(self.blackbkg)

        #self.object = self.makeObject()
        #GL.glShadeModel(GL.GL_FLAT)

        #shades
        if self.bsmooth:
            GL.glShadeModel(GL.GL_SMOOTH)
        else:
            GL.glShadeModel(GL.GL_FLAT)

        GL.glEnable(GL.GL_DEPTH_TEST)
        #GL.glEnable(GL.GL_CULL_FACE)

        #size of the points
        GL.glPointSize(5.0)
        #GL.glEnable(GL.GL_MULTISAMPLE)

    def paintGL(self):

        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)

        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glLoadIdentity()
        GL.glTranslatef(self.center_mass[self.counter % self.nbframes], -0.05,
                        -2)  #camera set at y = -5, x = -50
        #GL.glRotatef(20.0,1.0,0.0,0.0)#camera rotated from 20° around the z axis
        GL.glRotatef(
            180.0, 0.0, 1.0,
            0.0)  #camera rotated from 120+0.05*frameid around the y axis

        GL.glDisable(GL.GL_BLEND)
        GL.glEnable(GL.GL_DEPTH_TEST)

        # drawparticles
        GL.glPushMatrix()
        GL.glTranslatef(0.0, 0.0, 0.0)
        self.drawParticles_simplepoints0(color_en=True)
        GL.glPopMatrix()

        if DRAWPOT:
            GL.glPushMatrix()
            GL.glTranslatef(self.center_mass[self.counter % self.nbframes],
                            0.0, 0.0)
            self.drawpic(self.lasti0)
            GL.glPopMatrix()
            #GL.glPushMatrix()
            #GL.glRotatef(90.0,1.0,0.0,0.0)
            #GL.glTranslatef(self.center_mass[self.counter%self.nb],0.0,0.0)
            #self.drawpic(self.lasti0)
            #GL.glPopMatrix()

        #self.drawGrid()

    def drawpic(self, i):

        GL.glEnable(GL.GL_TEXTURE_2D)
        GL.glGenTextures(1, self.texture_id[i])
        GL.glBindTexture(GL.GL_TEXTURE_2D, self.texture_id[i])
        GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA,
                        self.pixels[i].shape[1], self.pixels[i].shape[0], 0,
                        GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, self.pixels[i])
        #print(self.pixels.shape)
        GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER,
                           GL.GL_LINEAR)
        GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER,
                           GL.GL_LINEAR)
        GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP)
        GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP)
        GL.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_DECAL)

        GL.glBegin(GL.GL_QUADS)
        #GL.glColor4f(1.0,1.0,1.0,0.04)
        GL.glTexCoord2i(0, 0)
        #GL.glColor4f(1.0,1.0,1.0,0.4)
        GL.glVertex2f(self.ZL, self.YB)

        GL.glTexCoord2i(1, 0)
        GL.glVertex2f(self.ZR, self.YB)

        GL.glTexCoord2i(1, 1)
        GL.glVertex2f(self.ZR, self.YT)

        GL.glTexCoord2i(0, 1)
        GL.glVertex2f(self.ZL, self.YT)
        GL.glEnd()
        GL.glDisable(GL.GL_TEXTURE_2D)

    def drawGrid(self):
        #draw grid

        # line smooth and alpha blending of the lines
        if self.bsmooth:
            GL.glEnable(GL.GL_LINE_SMOOTH)
            GL.glEnable(GL.GL_BLEND)
            GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)
            GL.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST)

        GL.glBegin(GL.GL_LINES)

        xr = 200.0
        zr = 200.0
        dx = 10.0
        dz = 10.0
        xval = np.arange(-0.5 * xr, +0.5 * xr + dx * 0.001, dx)
        zval = np.arange(
            self.center_mass[self.lasti0 % self.nbframes] - 0.5 * zr,
            self.center_mass[self.lasti0 % self.nbframes] + 0.5 * zr +
            dz * 0.001, dz)
        GL.glColor4f(1.0, 1.0, 1.0, 0.3)
        for x in xval:
            GL.glVertex3f(zval[0], 0.0, x)
            GL.glVertex3f(zval[-1], 0.0, x)
        for z in zval:
            GL.glVertex3f(z, 0.0, xval[0])
            GL.glVertex3f(z, 0.0, xval[-1])
        GL.glEnd()

    def resizeGL(self, width, height):

        #print('WINDOWS',width,height)
        GL.glViewport(0, 0, width, height)

        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glLoadIdentity()

        # projection parallele
        # Seuls les objets min <= x <= max, min <= y <= max
        # et 0 <= z < 1.0 seront vus.
        #GL.glOrtho(0.0,width,0,height,0.0,1000.0)
        #fov = 60.0
        near = 1.0  #np.max([0.001,0.0001]) # near should never be equal to zero
        far = 1000.0
        depthbufferbitlost = np.log2(far / near)

        self.fov = 55.0  #+20.0*np.cos(0.1*self.an) # angle de vue
        # en prenant la moitie de l'angle de vue et la distance du centre de vue au premier plan de clip on calcule les coordonnes laterales qui sont mappe aux coordonnes en pixels de la fenetre

        xn = near * np.tan(np.deg2rad(self.fov / 2.0))
        aspect = (1.0 * height) / np.max([1.0, width
                                          ])  # au cas ou width serait zero..
        yn = xn * aspect  # to keep the aspect ratio fix

        #GL.glFrustum(-width*0.5,width*0.5,-height*0.5,0.5*height,near,far)
        GL.glFrustum(-xn, xn, -yn, yn, near, far)
        #print(xn,yn)
        #GL.glMultMatrix()
        #GL.glOrtho(0.0,600.0,0.0,400.0,0.001,1000.0)

        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glLoadIdentity()
예제 #16
0
 def hasFrameBufferObjects(self) -> bool:
     return QOpenGLFramebufferObject.hasOpenGLFramebufferObjects()
예제 #17
0
    def hasFrameBufferObjects(self) -> bool:
        """Check if the current OpenGL implementation supports FrameBuffer Objects.

        :return: True if FBOs are supported, False if not.
        """
        return QOpenGLFramebufferObject.hasOpenGLFramebufferObjects()
예제 #18
0
 def hasFrameBufferObjects(self):
     return QOpenGLFramebufferObject.hasOpenGLFramebufferObjects()
예제 #19
0
 def createFrameBufferObject(self, size):
     f = QOpenGLFramebufferObjectFormat()
     f.setAttachment(QOpenGLFramebufferObject.CombinedDepthStencil)
     f.setSamples(4)
     return QOpenGLFramebufferObject(size, f)