3D Graphics (wireframe rendering)

I’m not sure i know what the state of the OpenGL Control is in after Xojo 2019 r1.1
All I’m trying to do is render a 3d wireframe mesh.
What’s the recommendation for a controller to use?

für Mac hat MBS SceneKit.

xojo3d.com
you can set the drawing color with glColor4d but red,green,blue,alpha is in the range 0 to 1.

OpenGL.glColor4d(Color1.Red, Color1.Green, Color1.Blue, Color1.Alpha)

there are 3 line modes

OpenGL.glBegin OpenGL.GL_LINES 'OpenGL.glBegin OpenGL.GL_LINE_STRIP //Draws a connected group of line segments from the first vertexto the last.Verticesnandn+1define linen.N-1lines are drawn. 'OpenGL.glBegin OpenGL.GL_LINE_LOOP //Draws a connected group of line segments from the first vertexto the last,then back to the first.Verticesnandn+1define linen.The last line, however, is defined by verticesNand1.Nlines are drawn. For Each v As Vertex In Vertices OpenGL.glVertex3d v.Position.X, v.Position.Y, v.Position.Z Next OpenGL.glEnd
the list of points

Public Property Vertices() as Vertex

Public Sub AddLine(v1 as Vertex, v2 as Vertex) Vertices.AddRow(v1) Vertices.AddRow(v2) End Sub

'Vertex 
Public Property Position as Vector
'Vector
Public Property X as Double = 0
Public Property Y as Double = 0
Public Property Z as Double = 0

the camera if it would look from 0,0,0

[code]OpenGL.glClearColor(0.5,0.5,0.5,1.0)

OpenGL.glClear(Bitwise.BitOr( OpenGL.GL_COLOR_BUFFER_BIT , OpenGL.GL_DEPTH_BUFFER_BIT))

OpenGL.glMatrixMode(OpenGL.GL_MODELVIEW)
OpenGL.glLoadIdentity [/code]

called once if the 3d surface view changed it size

[code]Public Shared Sub AfterResizedSetPerspective(surface As OpenGLSurface, fov As Double = 60.0, zNear As Double = 1, zFar As Double = 100)

OpenGL.glViewport 0, 0, surface.Width, surface.Height

OpenGL.glMatrixMode OpenGL.GL_PROJECTION
OpenGL.glLoadIdentity
OpenGL.gluPerspective fov, surface.Width/surface.Height, zNear, zFar

OpenGL.glMatrixMode OpenGL.GL_MODELVIEW
OpenGL.glLoadIdentity
End Sub
[/code]

examplpe of Initialize the 3d system once

[code]Public Shared Sub InitializeMe()

OpenGl.glClearDepth(1.0)

OpenGL.glEnable(OpenGL.GL_DEPTH_TEST)
OpenGL.glDepthFunc(OpenGL.GL_LESS)

//OpenGL.glEnable(OpenGL.GL_CULL_FACE)
OpenGL.glDisable(OpenGL.GL_CULL_FACE)

OpenGL.glHint(OpenGL.GL_PERSPECTIVE_CORRECTION_HINT, OpenGL.GL_NICEST)
OpenGL.glShadeModel(OpenGL.GL_SMOOTH)
//OpenGL.glShadeModel(OpenGL.GL_FLAT)

//OpenGL.glEnable(OpenGL.GL_DITHER)
OpenGL.glDisable(OpenGL.GL_DITHER)

OpenGL.glEnable(OpenGL.GL_COLOR_MATERIAL)
OpenGL.glEnable(OpenGL.GL_NORMALIZE)

OpenGL.glEnable OpenGL.GL_BLEND
OpenGL.glBlendFunc OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA

End Sub
[/code]

you can move,rotate and scale things also

[code]OpenGL.glPushMatrix

OpenGL.glTranslated( Position.X,Position.Y,Position.Z)

OpenGL.glRotated(Rotate.X, 1, 0, 0)
OpenGL.glRotated(Rotate.Y, 0, 1, 0)
OpenGL.glRotated(Rotate.Z, 0, 0, 1)

OpenGL.glScaled(Scale.X,Scale.Y,Scale.Z)

// here would be something with OpenGL.glBegin OpenGL.glEnd

OpenGL.glPopMatrix
[/code]

Brian,
I use OpenGlSurface all the time and I have noticed nothing with the last versions. In fact I use Xojo 2019r3.1 without problem, at least on Windows and Mac. I don’t know about other environments.
Here in the forum many people have pointed out that OpenGl will disappear, first from Mac and later on from others, but I’m sure I will “disappear” first (I mean from programming :slight_smile: ), so I am not very worried about this.

Thank you very much for the effort you put in that post @Markus Rauch. However it isn’t that i don’t have open gl code to do this… it’s that I want to know if I should port it to some other object than OpenGLSurface as I am worried about depreciation in future releases of Xojo and Mac OS X… to a lesser extent windows or linux.

@Ramon SASTRE Indeed… one never knows when one may be deprecated. :slight_smile:

Apple is removing OpenGL - not deprecating it
So unless you link in the entire OpenGL library - which I’m pretty sure the OpenGL pluging does not do - when Apple has fully removed it your code wont work
A wrapper around Vulkan, the OpenGL replacement, and the implementation that exists for macOS that sits on Metal will be required (see https://github.com/KhronosGroup/MoltenVK)

@Norman P I wish there was an application that could take a c/c++ header or library include file and build an Xojo interface to that object.
Intel is going to publish something called OneAPI and in my opinion its the only logical choice at the moment.

A VulkanSurface incredible!!! Gimme Gimme!

That would uncomplicate sooo many graphics and other programming issues, and would make Xojo a seriously competitive language.

I hadn’t heard about OneAPI. From the main website page it looks like this will be a great cross-platform development tool.

I looked into this, and having a VulkanSurface tools would be great. I put together a simple program in C++ with Vulkan and the setup portion to draw a simple triangle was a little over 1,000 lines of code. A VulkanSurface plugin or control would be very nice, as it would take advantage of old to new hardware.

The current OpenGLSurface Control uses approximately version 1.3 of OpenGL which is circa August 2001 (19 years-old) and is able to perform some simple graphics work for proof-of-concept. Version 1.3 OpenGLSurface control is still light-years-ahead of drawing with the canvas control that is available today in 2020.

Except for the simplest of drawing programs, drawing with a graphics GPU is really the only way to go.

I spend some time with SceneKit which may also be configurable for wire frame mode.

Making a Vulkan plugin would be some bigger job…

[quote=482234:@Brian O’Brien]I’m not sure i know what the state of the OpenGL Control is in after Xojo 2019 r1.1
All I’m trying to do is render a 3d wireframe mesh.
What’s the recommendation for a controller to use?[/quote]

Hi Brian,

In my OpenGL book, there are examples to create 3D meshes, with full rotation, and then add texturing within the meshes… I am waiting to see what the effects API 2 has on the rest of the programming language to see what the next steps would be.

[quote=482667:@Eugene Dakin]Hi Brian,

In my OpenGL book, there are examples to create 3D meshes, with full rotation, and then add texturing within the meshes… I am waiting to see what the effects API 2 has on the rest of the programming language to see what the next steps would be.[/quote]

Hi Eugene… I have lots of wireframe code and it’s working… I just wanted to know if it would continue working given Apples Decision on OpenGL etc…
Thanks!

What would be nice is a collaboration to take a c/C++ or library header and convert it to Declairs for Xojo… I haven’t looked at Vulkan in a while, but I was really close to getting OpenCV and Intel IPL working in Xojo… but then… I got to a point where the IPL wasn’t working. Apparently a group of accounting students did the OpenCV Declares???

[quote=482579:@Brian O’Brien]@Norman P I wish there was an application that could take a c/c++ header or library include file and build an Xojo interface to that object.
[/quote]
You more or less just asked for interops :slight_smile:

C is a crappy language for doing this with since you need to know the intent
For instance when you see “void *” you actually have to read the code to know how its going to be used to know how to call it from Xojo
C++ would not work unless it has an exposed C api and then you have the same problem
And this is why an API like Win32 will probably never get interops - the typing is ambiguous in the header file and you need to read the docs to know how something is used to know how to define the proper types to pass. Sometimes the right thing to pass is a Ptr, sometimes an integer, and … its messy

Objective-C and Java have a lot of information that makes this a whole lot simpler
see
https://forum.xojo.com/conversation/post/385637
I’m sure there are others around as well just the forums are poor at searching for such things

[quote=482667:@Eugene Dakin]Hi Brian,

In my OpenGL book, there are examples to create 3D meshes, with full rotation, and then add texturing within the meshes… I am waiting to see what the effects API 2 has on the rest of the programming language to see what the next steps would be.[/quote]

OpenGL is not going to be useful on macOS any longer :frowning:

Vulkan, and a mac API for it to use Metal under the hood, really looks like the path forward everywhere

If you’re doing simple wire frames (ha), have you considered doing it yourself use a canvas and drawline?

I know it would be a lot of hassle, but the end result would be x-plat :slight_smile:

yeah, back to the nineties :slight_smile:
at least it need a simple vector class
GraphicsPath or FigureShape could do the drawing


seems Vulkan is used by all mainstream game engines.
i made a (big) feature request 59681

[quote=482715:@Markus Rauch]seems Vulkan is used by all mainstream game engines.
i made a (big) feature request 59681[/quote]
I added points to the feedback request.

Thanks Markus