def createTexture(self, gl, width=None, height=None, wrapMode=QOpenGLTexture.ClampToEdge, format=QOpenGLTexture.RGBA8U, filter=QOpenGLTexture.Linear, filename=None, allocate=True, **kwparams): ''' Creates texture object with required parameters ''' assert width is not None or filename is not None if height is None: height = width if filename: texture = QOpenGLTexture(QImage('{}/{}'.format(Resources.directory, filename)).mirrored(), QOpenGLTexture.DontGenerateMipMaps) else: texture = QOpenGLTexture(QOpenGLTexture.Target2D) texture.setFormat(format) texture.setSize(width, height) if allocate: texture.allocateStorage() texture.setMinificationFilter(filter) texture.setMagnificationFilter(filter) texture.setWrapMode(wrapMode) assert texture.create() texture.bind() for k, v in kwparams.items(): gl.glTexParameteri(gl.GL_TEXTURE_2D, getattr(gl, k), v) texture.release() return texture
def load_texture(material): # Note that the QImage is mirrored vertically to account for the fact that OpenGL and QImage use opposite directions for the y axis. # (https://doc.qt.io/qt-5/qopengltexture.html#details) texture = QOpenGLTexture(QImage(get_resources_path(material['diffuse_map'])).mirrored()) texture.setMinificationFilter(QOpenGLTexture.Nearest) texture.setMagnificationFilter(QOpenGLTexture.Nearest) texture.setWrapMode(QOpenGLTexture.ClampToEdge) return texture
def load_texture(material): # Note that the QImage is mirrored vertically to account for the fact that OpenGL and QImage use opposite directions for the y axis. # (https://doc.qt.io/qt-5/qopengltexture.html#details) texture = QOpenGLTexture( QImage(get_resources_path(material['diffuse_map'])).mirrored()) texture.setMinificationFilter(QOpenGLTexture.Nearest) texture.setMagnificationFilter(QOpenGLTexture.Nearest) texture.setWrapMode(QOpenGLTexture.ClampToEdge) return texture