Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLScatterPlotItem wont render with GLViewWidget.renderToArray #366

Closed
feketeimre opened this issue Aug 7, 2016 · 1 comment
Closed

GLScatterPlotItem wont render with GLViewWidget.renderToArray #366

feketeimre opened this issue Aug 7, 2016 · 1 comment

Comments

@feketeimre
Copy link
Contributor

While trying to render the current view with GLViewWidget.renderToArray that contains a GLScatterPlotItem the following error is thrown:

Traceback (most recent call last):
File "", line 15, in
File "C:\Python27\lib\site-packages\pyqtgraph\opengl\GLViewWidget.py", line 451, in renderToArray
data = np.fromstring(data, dtype=np.ubyte).reshape(texwidth,texwidth,4).transpose(1,0,2)[:, ::-1]
ValueError: total size of new array must be unchanged

Heres a test code to reproduce the error:

from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph.opengl as gl
import numpy

app = QtGui.QApplication([])
win = gl.GLViewWidget()
win.show()

s = gl.GLScatterPlotItem(pos = numpy.random.random((10,3)))
win.addItem(s)

m = gl.GLMeshItem(vertexes = numpy.random.random((10,3,3)))
win.addItem(m)

a = win.renderToArray((800,600))

if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()

If you comment out the scatter plot part it runs just fine. Looking at source of GLViewWidget.renderToArray at the errors location:

self.paintGL(region=(x, h-y-h2, w2, h2), viewport=(0, 0, w2, h2)) # only render sub-region
## read texture back to array
data = glGetTexImage(GL_TEXTURE_2D, 0, format, type)
data = np.fromstring(data, dtype=np.ubyte).reshape(texwidth,texwidth,4).transp....

It looks like glGetTexImage returns too small of a string to be reshaped to the given size.
By trial and error i found out that the returned string can be reshaped to a 64x64x4 image that shows a circle (hint: its GLScatterPlotItem.pointTexture). It seems that the texture bindings change and the scatter plots texture is rendered instead. Calling glGetIntegerv(GL_TEXTURE_BINDING_2D) showed that before calling glGetTexImage the bound texture is the scatter plots texture and before self.paintGL the bound texture is the correct texture.
By repainting with self.paintGL the scatter plots paint function is called, which changes the bound texture, after the call the bound texture should be reset to tex right after self.paintGL by simply adding:
glBindTexture(GL_TEXTURE_2D, tex)

@feketeimre
Copy link
Contributor Author

I have checked on 5 different systems, 2 of them had this issue. Is solved by PR #626

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant