OpenGL depth buffer deosn't seem to work in wx.glcanvas?

435 views
Skip to first unread message

bradcan

unread,
Oct 24, 2012, 2:48:06 PM10/24/12
to wxpytho...@googlegroups.com
Hello All
I'm working on a wxPython glcanvas program running under Fedora 17 Linux
system and I'm experiencing the following problem.

I have downloaded the wx.glcanvas example from here:
http://xoomer.virgilio.it/infinity77/wxPython/glcanvas/wx.glcanvas.html?highlight=glcanvas#module-glcanvas

This produces a cube with some of the faces not shown correctly. If I use
the same example code, but remove it from wx, ie just use PyOpenGL, the
problem goes away. The problem seems to be that the GL depth buffer is not
working correctly when I inherit from wx.glcanvas!

Any help would be much appreciated.

I include links to clips to demonstrate that my hardware and OpenGL are
working properly:
original broken version <http://www.unionsteammodels.co.uk/files/broken.ogv>
working modified version
<http://www.unionsteammodels.co.uk/files/working.ogv>

My working version uses a glutCreateWindow instead of glcanvas, the code is
here: (sorry about the length):

from OpenGL.GL import *
from OpenGL.GLUT import *

class MyGL():

def __init__(self):
glutInit(sys.argv)
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA |
GLUT_DEPTH)
self.w=320; self.h=240;
glutInitWindowSize(self.w, self.h)
glutInitWindowPosition(20, 20)
self.window = glutCreateWindow("Test 3")
glutIdleFunc(self.Draw)
glutMotionFunc(self.Mouse)
glutReshapeFunc(self.Resize)

glClearColor(1.0, 1.0, 1.0, 1.0) # Black
glClearDepth(1.0) # Enables Clearing Of The Depth Buffer
glDepthFunc(GL_LESS) # The Type Of Depth Test To Do
glEnable(GL_DEPTH_TEST) # Enables Depth Testing
glShadeModel(GL_SMOOTH) # Enables Smooth Color Shading

self.x=self.y=self.lastx=self.lasty=self=0

def InitGL(self):
# set viewing projection
glMatrixMode(GL_PROJECTION)
glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0)

# position viewer
glMatrixMode(GL_MODELVIEW)
glTranslatef(0.0, 0.0, -2.0)

glEnable(GL_DEPTH_TEST)
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)

def Mouse(self,x,y):
self.x=x; self.y=y;

def Resize(self,w,h):
self.w=w; self.h=h
glViewport(0, 0, w, h)

def Draw(self):
# clear color and depth buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

# draw six faces of a cube
glBegin(GL_QUADS)
glNormal3f( 0.0, 0.0, 1.0)
glVertex3f( 0.5, 0.5, 0.5)
glVertex3f(-0.5, 0.5, 0.5)
glVertex3f(-0.5,-0.5, 0.5)
glVertex3f( 0.5,-0.5, 0.5)

glNormal3f( 0.0, 0.0,-1.0)
glVertex3f(-0.5,-0.5,-0.5)
glVertex3f(-0.5, 0.5,-0.5)
glVertex3f( 0.5, 0.5,-0.5)
glVertex3f( 0.5,-0.5,-0.5)

glNormal3f( 0.0, 1.0, 0.0)
glVertex3f( 0.5, 0.5, 0.5)
glVertex3f( 0.5, 0.5,-0.5)
glVertex3f(-0.5, 0.5,-0.5)
glVertex3f(-0.5, 0.5, 0.5)

glNormal3f( 0.0,-1.0, 0.0)
glVertex3f(-0.5,-0.5,-0.5)
glVertex3f( 0.5,-0.5,-0.5)
glVertex3f( 0.5,-0.5, 0.5)
glVertex3f(-0.5,-0.5, 0.5)

glNormal3f( 1.0, 0.0, 0.0)
glVertex3f( 0.5, 0.5, 0.5)
glVertex3f( 0.5,-0.5, 0.5)
glVertex3f( 0.5,-0.5,-0.5)
glVertex3f( 0.5, 0.5,-0.5)

glNormal3f(-1.0, 0.0, 0.0)
glVertex3f(-0.5,-0.5,-0.5)
glVertex3f(-0.5,-0.5, 0.5)
glVertex3f(-0.5, 0.5, 0.5)
glVertex3f(-0.5, 0.5,-0.5)
glEnd()

# self.rot = self.rot + 0.2;
# if self.size is None:
# self.size = self.GetClientSize()
# w, h = self.size
# w = max(w, 1.0)
# h = max(h, 1.0)
xScale = 180.0 / self.w
yScale = 180.0 / self.h
glRotatef((self.y - self.lasty) * yScale, 1.0, 0.0, 0.0);
glRotatef((self.x - self.lastx) * xScale, 0.0, 1.0, 0.0);
self.lastx=self.x; self.lasty=self.y

# self.SwapBuffers()
glutSwapBuffers()

g=MyGL()
g.InitGL()
glutMainLoop()



--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/OpenGL-depth-buffer-deosn-t-seem-to-work-in-wx-glcanvas-tp5714984.html
Sent from the wxPython-users mailing list archive at Nabble.com.

Robin Dunn

unread,
Oct 24, 2012, 7:00:14 PM10/24/12
to wxpytho...@googlegroups.com
On 10/24/12 11:48 AM, bradcan wrote:
> Hello All
> I'm working on a wxPython glcanvas program running under Fedora 17 Linux
> system and I'm experiencing the following problem.
>
> I have downloaded the wx.glcanvas example from here:
> http://xoomer.virgilio.it/infinity77/wxPython/glcanvas/wx.glcanvas.html?highlight=glcanvas#module-glcanvas
>
> This produces a cube with some of the faces not shown correctly. If I use
> the same example code, but remove it from wx, ie just use PyOpenGL, the
> problem goes away. The problem seems to be that the GL depth buffer is not
> working correctly when I inherit from wx.glcanvas!
>
> Any help would be much appreciated.

I'm not sure what is going on there, but I see it on my Linux box too.
You may want to experiment with setting some GL attributes when creating
the context. It may be that the defaults used on wxGTK are not
sufficient, or perhaps wx is assuming that OpenGL has different default
attributes than it does.



--
Robin Dunn
Software Craftsman
http://wxPython.org

bradcan

unread,
Oct 25, 2012, 8:32:19 AM10/25/12
to wxpytho...@googlegroups.com
On Oct 25, 2012; 12:00am, Robin wrote:

>It may be that the defaults used on wxGTK are not
>sufficient, or perhaps wx is assuming that OpenGL has different default
>attributes than it does.

I'm sure you're right. One clue is the difference between
self.SwapBuffers() and glutSwapBuffers() the former being
essential, the latter does NOT work at all when using glcanvas, ie we can
call gl... directly for most things, but not all.

The wxPython documents here: http://wxpython.org/onlinedocs.php offer some
clues.
My first problem is that these docs. are C++, not Python, despite being
listed as "wxPython".

Whatever: I see the constructor for wxGLCanvas has the parameter
attribList=0 and a list of possible attributes including
WX_GL_DEPTH_SIZE and the example code snippet:
attribList[index]= WX_GL_DEPTH_SIZE;
attribList[index+1]=32;

Unfortunately, the constant WX_GL_DEPTH_SIZE is NOT defined! ie:
print "the depth buffer constant is:", WX_GL_DEPTH_SIZE produces the Python
error:
"NameError: global name 'WX_GL_DEPTH_SIZE' is not defined"

Where are the constants defined?
And how-to code attribList in Python. Can you point me to an example?

---
Charles Bradshaw
Determined old hack.
---



--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/OpenGL-depth-buffer-deosn-t-seem-to-work-in-wx-glcanvas-tp5714984p5714990.html

bradcan

unread,
Oct 25, 2012, 9:07:52 AM10/25/12
to wxpytho...@googlegroups.com
Solved it !

This Python code works:

from wx.glcanvas import WX_GL_DEPTH_SIZE

attribs=[WX_GL_DEPTH_SIZE,16,0,0];
glcanvas.GLCanvas.__init__(self, parent, -1,attribList=attribs)

Note: On my machine the value must be 16, presumably determined by
hardware.?
Anything else produces a blank canvas!

Thanks for the help.




--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/OpenGL-depth-buffer-deosn-t-seem-to-work-in-wx-glcanvas-tp5714984p5714991.html

Bruce Sherwood

unread,
Oct 29, 2012, 2:11:41 PM10/29/12
to wxpytho...@googlegroups.com
I'll comment that the wx.glcanvas demo mentioned here doesn't work for me on Windows. The following canvas example does work:

http://wiki.wxpython.org/GLCanvas%20update


On Wednesday, October 24, 2012 12:50:13 PM UTC-6, oldbrad wrote:
Hello All
I'm working on a wxPython  glcanvas program running under Fedora 17 Linux
system and I'm experiencing the following problem.

I have downloaded the wx.glcanvas example from here:
http://xoomer.virgilio.it/infinity77/wxPython/glcanvas/wx.glcanvas.html?highlight=glcanvas#module-glcanvas

bradcan

unread,
Oct 29, 2012, 7:58:09 PM10/29/12
to wxpytho...@googlegroups.com
Hi Bruce
That demo doesn't work either under Fedora. For the same reason, one has to
pass the depth buffer attribute like this:

attribs=[WX_GL_DEPTH_SIZE,16,0]; # Needed by wxGTK
the defaults are not enough. Obscure!
glcanvas.GLCanvas.__init__(self, parent, -1,attribList=attribs)

I struggled for many days and tried most of the samples google could find.
The fundamental problem seems to be that very few have been tested under X.




--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/OpenGL-depth-buffer-deosn-t-seem-to-work-in-wx-glcanvas-tp5714984p5715014.html
Sent from the wxPython-users mailing list archive at Nabble.com.

annakrat

unread,
Mar 2, 2013, 11:30:58 AM3/2/13
to wxpytho...@googlegroups.com


On Tuesday, February 5, 2013 2:44:28 PM UTC+1, Thomas wrote:
I have a similar situation where a wx app requires WX_GL_DEPTH_SIZE to be 16 on one platform (RHEL 6.3 64 bit with wx 2.8.12), whereas 32 will work on another (OS X 10.6 with wx 2.9).  Does anyone know of a straightforward way to determine the max allowable depth prior to creating the GLCanvas?

Hi all,

I am also interested in this question. I have been using GLCanvas for some time without problems and recently (probably due to upgrading to Ubuntu 12 with newer wxPython) the rendering order became strange. Setting WX_GL_DEPTH_SIZE to 16 works for me. I don't understand if the attribList parameter needs to be used on all platforms and which value to use? for example, will 16 work where 32 works, or only one value is right? What should a developer of a multiplatform application do?

Thanks very much,
Anna
 

Thanks,
Thomas

Bruce Sherwood

unread,
Mar 2, 2013, 2:35:24 PM3/2/13
to wxpytho...@googlegroups.com
This is pretty puzzling, as the use VPython makes of OpenGL is pretty basic, in large part because the architecture dates back to 2000 with the exception of materials, which requires GPUs.

VPython has always been, and still is, rather fiercely multiplatform. However, there have always been problems with Linux, most typically related to the need for and difficulty of updating the graphics driver. Note that these arcane OpenGL issues are not a problem on Windows and Mac.


--
You received this message because you are subscribed to a topic in the Google Groups "wxPython-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/lbzhzaBNkxQ/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to wxpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

annakrat

unread,
Apr 19, 2013, 2:28:19 AM4/19/13
to wxpytho...@googlegroups.com


On Saturday, March 2, 2013 5:30:58 PM UTC+1, annakrat wrote:


On Tuesday, February 5, 2013 2:44:28 PM UTC+1, Thomas wrote:
I have a similar situation where a wx app requires WX_GL_DEPTH_SIZE to be 16 on one platform (RHEL 6.3 64 bit with wx 2.8.12), whereas 32 will work on another (OS X 10.6 with wx 2.9).  Does anyone know of a straightforward way to determine the max allowable depth prior to creating the GLCanvas?

Hi all,

I am also interested in this question. I have been using GLCanvas for some time without problems and recently (probably due to upgrading to Ubuntu 12 with newer wxPython) the rendering order became strange. Setting WX_GL_DEPTH_SIZE to 16 works for me. I don't understand if the attribList parameter needs to be used on all platforms and which value to use? for example, will 16 work where 32 works, or only one value is right? What should a developer of a multiplatform application do? 

Thanks very much,
Anna


 Hi all

is there any progress concerning this question? I found out that there is IsDisplaySupported method which can check if the attributes are supported, however it's only in the wxPython version 2.9. Since I need to support also older version 2.8 it's not a solution. Do we at least know on what depth buffer number depends? Is there a way to test if creating of the glcanvas with the given attributes failed? Which numbers could work apart from 16 and 32?

Thanks,
Anna

Thomas

unread,
Apr 19, 2013, 10:07:41 AM4/19/13
to wxpytho...@googlegroups.com
Thanks for the info on IsDisplaySupported.  I have a similar situation where I need to support wxPython 2.8.x.  Regarding your last question, I have found on one of my systems that WX_GL_DEPTH_SIZE of 24 will work (whereas 32 fails).  Interestingly, on that system IsDisplaySupported returns True for any value of WX_GL_DEPTH_SIZE <= 24 (including negative numbers).

Thomas

br...@bradcan.homelinux.com

unread,
Sep 17, 2017, 5:46:53 PM9/17/17
to wxPython-users
I'm posting an update to this thread because things seemed to have changed with versions since 2013.

In the GLCanvas sub class we need this snippet:

        # We need additional attribs for wxGTK the defaults are not enough. Very Obscure!!
        attribs=[WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE,24]; 
        super(Canvas,self).__init__(parent, -1, attribList=attribs)

Also note this:
        self.context = glcanvas.GLContext(self)            # OpenGL context (obviously!)

But the following must be delayed until the canvas is displayed. In my case I put the it in InitGl(self) which is called by OnPaint(self, event)
        self.SetCurrent(self.context)

In the above self is GLCanvas subclass.

These obscure snippets are running under Linux Mint as of Sept 2017
Reply all
Reply to author
Forward
0 new messages