3D Rendering question

This is from code that used to work perfectly on Mac and Windows.
I have to update it after years of neglect, and the 3D renders differently. I’ve never been great with the guts of OpenGL, so before I paw around blindly in the dark, I’d send this to the forum to see if any of you have an idea to short-track my search.

The issue is the rectangle in the background (I’ve simplified the rest of the model for sake of illustration).

It is a polygon made of 4 points set to show the lines not fill.
Note the diagonal line from top left to bottom right?

On Mac, it behaves as it always had. What’s worth of additional note is that the line weight on all objects seems heavier on Mac than Windows. That was never the case before.

I’m positive that there is just some flag or setting that I now have to use and didn’t back in 2018 when this was first written.

I did update the deprecated 3D control to the new one as well. I had hoped that would solve it by itself but it hasn’t.

Any suggestions will be greatly appreciated.

Is the problem the diagonal line? If so, my guess is that it sees the rectangle as a surface and not a four segment line, possibly being a ever so slightly twisted, and therefore divides it into two triangles. Not all OpenGL applications support lines, so that can cause the problem. Have you tried drawing it as four lines, or making the rectangle not quite a closed shape?

it is a polygon not just four lines, but for sure it isn’t twisted. I can double check all the code again, but if it were it would also be twisted on Mac.

And I do have to make it a polygon so it has sides. I render this with the backside not showing and then invert it. The net effect is that there is a 3d object surrounded by walls with a grid, where the side between the viewer and the object is hidden (so you aren’t looking through it).

I googled this and it seems others have seen the same issue too, but haven’t found a resolution.

The fact that the line weight also isn’t showing the same maybe is an indicator of the issue, but I haven’t uncovered it yet.

Of course the problem for me is that this all worked perfectly well before and without any code change it now isn’t working. But it was working 4 years ago and I don’t know what underlaying libraries may have updated.

Could be that the library just decomposes everything into triangles by default.

it seems that way, but it didn’t do that before.
And I’m still struggling with why the line weight isn’t being respected.

I’m happy to pay for someone’s time to help me uncover this.
I’m certain someone with the right OpenGL knowledge can fix it asap. It was working brilliantly before so it’s likely just a flag or default property that has changed in the api over the last few years.

PM me if you are interested.

@Eugene_Dakin ?

Hello Chris,

I am not sure if this is the cure, and I have noticed that an OpenGL bug has been fixed for Windows. The bug went something like this: Face culling is drawing the front or back of a shape, like a triangle. If the triangle was drawn counter-clockwise then the front of the image was facing you, and drawing clockwise the back of the image was facing you. I can’t remember the order at the moment.


When I created an OpenGL example in the latest version, this had changed.

Maybe try drawing the triangle clockwise instead of counter-clockwise on Windows.

Let me know if this works for your program :slight_smile:

I got that part down. I use that to create a lot of triangles with blended colors from each corner.
Always counter clockwise.
This is something different.
But thank you for the answer!

I’ve been testing with Parallels and it occurred to me that this could be something to do with the video driver in emulation.

Can anyone try this out please - see if you are seeing the same platform difference as I am.

Drop a DesktopOpenGLSurface in a window.

In the open of the DesktopOpenGLSurface add this code:
(sorry, not sure how to share a file here)

OpenGL.glOrtho(-1.0, 1.0, -1.0, 1.0, -100.0, 100.0)



in the render event:

openGL.glPolygonMode openGL.GL_FRONT_AND_BACK, openGL.gl_line

opengl.glLineWidth 2
opengl.glColor3f 1.,0.,0.

OpenGL.glBegin OpenGL.GL_POLYGON
OpenGL.glVertex3f -.5,-.5, -0.5
OpenGL.glVertex3f 0.5, -.5, -0.5
OpenGL.glVertex3f 0.5, 0.5, -0.5
OpenGL.glVertex3f -.5, 0.5, -0.5

On Mac I get the following…

While on Windows…

I fully realize that OpenGL converts everything to triangles, but there must be a way to draw a square wireframe?

I could draw it with lines, but it’s essential that I cull back faces (longer story).

I tried GL_Quads, but it didn’t solve it, and I’ve read that GL_Quads is deprecated.

Thanks in advance.

PS: Again, this same code used to work just fine on Windows.

I followed your instructions on Windows 11, GeForce RTX 2080, Xojo 2022 r2, OpenGLSurface, and here is my screen grab. It looks fine.

Well this is somewhat of a relief.
I’m guessing it has something to do with Parallels then.

Thank you, very much, for testing this. It’s really appreciated.

Hi Chris,

I also ran your code on some Plugins that I am developing for Xojo, and I get the same result, and your code looks good.

I agree that something might not be compatible with Parallels.

Warm regards

Edit: Made the picture clearer for the forums.

1 Like

Again, very appreciated!