I'm trying to setup my assignment from school, but the only guidance is for windows. We're using Qt to for the shaders, and I'm working through visual studio code and compiling with terminal. Problem is it seems that what ever version of openGL I try end up with the same error:
*QOpenGLShader::compile(Vertex): ERROR: 0:1: '' : version '150' is not supported*
I'm using a macbook mid 12, and as it seems I'm using version 4.1 of openGL, I've tried multiple versions like 3.3, 2.1 4.1 and so on. Nothing seems to do the trick. I have also tried to override the version but that doesn't work. Am I looking at the problem the wrong way?
This is the source code that is causing the error:
#version 150 core <----
// input from application
uniform vec3 vecLight;
uniform sampler2D samTexture;
// input from geometry shader
smooth in vec3 normal;
smooth in vec3 vertex;
smooth in vec3 cartescoord;
// material constants
float ka = 0.1;
float kd = 0.6;
float ks = 0.3;
float spec_exp = 50.0;
// useful constants
float PI = 3.14159265;
// output color
out vec4 outFragColor;
vec2 cartesian2normspherical(vec3 cart)
{
float fPhi = 0.0;
float fTheta = 0.0;
float fRadius = length(cart);
fTheta = acos (cart.z / fRadius) / (PI);
fPhi = atan(cart.y, cart.x)/ (PI);
//transform phi from [-1,1] to [0,1]
fPhi = (fPhi+1.0)/2.0;
return vec2(fPhi, fTheta);
}
float calcPhongBlinn(vec3 vecV, vec3 vecN, vec3 vecL)
{
float fLightingIntesity = 1.0;
float fDiffuseIntensity = clamp(dot(normal, vecLight), 0, 1);
vec3 vecHalfway = normalize(vecL + vecV);
float fSpecularIntensity = pow(clamp(dot(vecHalfway, vecN), 0, 1), spec_exp);
fLightingIntesity = ka + kd*fDiffuseIntensity + ks*fSpecularIntensity;
return fLightingIntesity;
}
void main(void)
{
vec2 sphCoord = cartesian2normspherical(cartescoord);
vec2 texcoord = sphCoord.xy;
// this vector is constant since we assume that we look orthogonally at the computer screen
vec3 vecView = vec3(0.0, 0.0, 1.0);
float fI = calcPhongBlinn(vecView, normal, vecLight);
vec4 vecColor = texture2D(samTexture, texcoord.xy);
outFragColor = vec4(vecColor.rgb*fI, 1.0);
}
This is the extensive error:
QOpenGLShader::compile(Vertex): ERROR: 0:1: '' : version '150' is not supported
*** Problematic Vertex shader source code ***
QOpenGLShader: could not create shader
QOpenGLShader::link: ERROR: One or more attached shaders not successfully compiled
With my script file running: make && ./myMain.app/Contents/MacOS/myMain
EDIT1: Adding my window file to the question
Window::Window()
{
QGridLayout *mainLayout = new QGridLayout;
QGLFormat glFormat;
glFormat.setVersion(3, 3);
glFormat.setProfile(QGLFormat::CoreProfile);
glFormat.setSampleBuffers(true);
GLWidget *glWidget = new GLWidget(/*glFormat,0*/);
mainLayout->addWidget(glWidget, 0, 0);
setLayout(mainLayout);
setWindowTitle(tr("Rendering with OpenGL"));
}
EDIT2:
After a lot of research, I have concluded that first and foremost I have to use openGL v: 3.3 for the shaders to work. Which my "OpenGl Extensions Viewer" says my mac does not support, i'm still wondering if there is a loophole I can exploit. So any information about how or if it's possible to do, would help.
LAST EDIT:
I found the solution, you have to pass the QGLFormat to QGLWidget as a constructor parameter. Found some of the solution here:
Thank you for all the help!