OpenGL 3 not working on Mac with wxGLCanvas

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
In need of some credit
In need of some credit
Posts: 1
Joined: Mon May 28, 2018 6:58 am

OpenGL 3 not working on Mac with wxGLCanvas

Post by kitebizelt » Mon May 28, 2018 7:06 am

So today I was just went trying copying my wxWidgets that works on my Windows to my Mac laptop, compiled and run the same file. It originally was the "cube" I downloaded from the official wxWidgets sample, and I changed it so it works with OpenGl 3.2, and it ran fine on Windows.

But everytime I try to run on Mac it keeps getting me at the GLSL point, where it says:

Code: Select all

ERROR: 0:1: '' :  version '330' is not supported
I tried adding attributes for my wxGLCanvas as like this:

Code: Select all

#ifdef __APPLE__
	new TestGLCanvas(this, stereoWindow ? stereoAttribList : NULL);
But it always shows:

Code: Select all

ERROR: 0:1: '' :  version '330' is not supported
Now I don't know what to do. I thought I did everything correctly?

Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 656
Joined: Mon Apr 30, 2012 11:07 pm

Re: OpenGL 3 not working on Mac with wxGLCanvas

Post by Manolo » Mon May 28, 2018 8:09 pm

If you are working with shaders (it seems so), then have a mismatch between the OpenGL version you ask for (3.2) and the one you require in your shaders (3.3).
I hope you don't use the old gl-commads (glBegin, glMatrixMode, etc) that the cube sample uses. They won't work on Core Profile.
Notice that the cube sample works with old OGL (<=2.1), where no Core Profile context is set. You can not just take the cube sample, change the context version to a Core Profile one and expect it to work.

Some (most of after 2007) Apple machines support OGL 3.3, even 4.1. See
Apple decided not to support OGL > 4.1 any more, they prefer their own "Metal" API.

While using the old array "list of attributes" is still supported by wxWidgets, starting with wx 3.1.0 the prefered way is with wxGLAttributes and wxGLContextAttrs. See docs at ... attrs.html and related. This is the way the pyramid sample uses.

Apple creates one of three types of contexts: The old (OGL <= 2.1), the 3.2 Core and the 4.1 Core. This is controlled by an attribute.
Currently wxWidgets does not provide an attribute for 4.1 version. Perhaps just setting the CoreProfile() attribute is enough for Apple to set the 4.1 version if the machine allows it.
But you can ask specifically for it:

Code: Select all

//Early in your code:
#ifdef __APPLE__
    // Suppress warnings when including gl3.h
    #include <OpenGL/gl3.h> // For Core Profile

//Create an use window features by wxGLAttributes
wxGLAttributes wAtt;
wAtt.PlatformDefaults().Defaults().Stero().EndList(); //Stereo is rarely supported
... check the attributes are available

//Context 4.1 version
wxGLContextAttrs cxtAttrs;

#ifdef __APPLE__
   //Add new attribute NSOpenGLProfileVersion4_1Core is defined in Apple's gl3.h
    cxtAttrs.EndList(); // Don't forget this
    // Other platforms
    cxtAttrs.PlatformDefaults().CoreProfile().OGLVersion(4, 1).EndList();
... check the context is OK

Some notes about your attributes:
* Some tutorials in the web say that WX_GL_FORWARD_COMPAT is required in Apple. I don't think so, Apple does not define an attribute for it. In other words, it's useless for Apple.
* There are not many cards that support WX_GL_STEREO

Post Reply