initializeGL
中的:
我正在使用QGLWidget
.exr
图像(128mb)4000x2000
imageio.imread
<{1}}中的from imageio import imread
img_array = imread("c:/sample.exr")
self.textureID = glGenTextures(1)
中的:
我使用paintGL
和QGLWidget
绘制单个四边形,然后将纹理输入glBegin(GL_QUADS)
并将其绑定到我之前创建的四边形。
glEnd()
加载图像或代码本身没有任何问题,一切都运行正常,但我面临性能问题,导航场景开始滞后,我认为是因为图像的大小。
有什么方法可以缩小尺寸吗?还是提高它的表现?
注意:即使图像为glTexImage2D
我也只显示为glBindTexture(GL_TEXTURE_2D, self.textureID)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1920, 1080, 0, GL_RGBA, GL_FLOAT, img_array)
,这意味着有0.4545伽玛乘法,我不知道这是否影响性能但想指出来。
提前致谢。
更新:
这是代码:
numpy.float32
我试过这个:
我将GL_RGBA
移动到import os
from PySide.QtGui import QColor
from PySide.QtOpenGL import QGLWidget
from imageio import imread
from OpenGL.GL import *
from OpenGL.GLU import *
from engine.nodes import (ImageNode, NodeType, CubeNode, Vector3)
class QImageProcessor(QGLWidget):
def __init__(self, parent=None):
super(QImageProcessor, self).__init__(parent)
self.model = list()
self.zoomVal = 1.2
self.local_translate = (0.0, 0.0, 0.0)
self.local_scale = (1.0, 1.0, 1.0)
self.xRot = 0
self.yRot = 0
self.zRot = 0
def initializeGL(self):
self.qglClearColor(QColor.fromCmykF(0.0, 0.1, 0.0, 0.882))
glViewport( 0, 0, self.width(), self.height())
glEnable(GL_TEXTURE_2D)
glEnable(GL_CULL_FACE)
glEnable(GL_MULTISAMPLE)
glEnable(GL_LINE_SMOOTH, GL_LINE_WIDTH, GL_ALIASED_LINE_WIDTH_RANGE)
glShadeModel(GL_FLAT)
glEnable(GL_DEPTH_TEST)
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
glDepthRange (0.1, 1.0)
# adding images
image1 = "c:/sample.exr"
new_image1 = ImageNode(image1)
new_image1.TextureID = glGenTextures(1)
new_image1.Data = imread(image1, format='.exr')
self.model.append(new_image1)
image2 = "c:/sample2.jpg"
new_image2 = ImageNode(image2)
new_image2.TextureID = glGenTextures(1)
new_image2.Data = imread(image2, format='.jpg')
self.model.append(new_image2)
def paintGL(self):
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
gluOrtho2D(-self.zoomVal, +self.zoomVal, -self.zoomVal, +self.zoomVal)
glLoadIdentity()
glTranslated(*self.local_translate)
glRotated(self.xRot / 16.0, 1.0, 0.0, 0.0)
glRotated(self.yRot / 16.0, 0.0, 1.0, 0.0)
glRotated(self.zRot / 16.0, 0.0, 0.0, 1.0)
glScalef(*self.local_scale)
genList = glGenLists(1)
glNewList(genList, GL_COMPILE)
for node in self.model:
vertices = node.Vertices # list of vertices
edges = node.Edges # list of edges
face = node.Face # list of faces
texcoords = node.TextureCoordinates # list of texture coordinates
glPushAttrib(GL_ALL_ATTRIB_BITS)
glPolygonMode(GL_FRONT, GL_FILL)
glPixelStorei(GL_UNPACK_ALIGNMENT,1)
glBindTexture(GL_TEXTURE_2D, node.TextureID)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexImage2D(GL_TEXTURE_2D, 0, node.InternalFormat, node.Width, node.Height, 0, node.Format, node.Type, node.Data)
# face and UV
glBegin(GL_QUADS)
self.qglColor(QColor(255,255,255))
for vertex in face:
glVertex3fv(vertices[vertex])
glTexCoord2f(texcoords[vertex][0], texcoords[vertex][1])
glEnd()
glPopAttrib()
glEndList()
glCallList(genList)
函数,将其绑定一次然后将其绑定到0:
glTexCoord2f
然后在initializeGL
再绑定它,
image2 = "c:/sample2.jpg"
new_image2 = ImageNode(image2)
new_image2.TextureID = glGenTextures(1)
new_image2.Data = imread(image2, format='.jpg')
glTexImage2D(GL_TEXTURE_2D, 0, new_image2.InternalFormat, new_image2.Width, new_image2.Height, 0, new_image2.Format, new_image2.Type, new_image2.Data)
glBindTexture(GL_TEXTURE_2D, new_image2.TextureID)
glBindTexture(GL_TEXTURE_2D, 0)
self.model.append(new_image2)
但它没有显示纹理,不确定我是否遗漏了某些东西。