Wasabi
17th August 2011, 18:41
The title isn't really the question, but it's the best I could do to summarize my problem.
I have a Qt program with a child of QGLWidget and everything is working just fine with OpenGL 3.3. The one problem I'm getting is that all the meshes I create are transparent even though their alpha values are set to 1 (remembering that OpenGL works on 0-1, not 0-255). I've played around with the OpenGL commands but can't get it to work. This all sounds and feels like its more of an OpenGL problem than a Qt problem, but I'm not being able to get much help from the people at the opengl.org forums and so, thinking that maybe I was missing something Qt-related, I returned to the documentation and found the following.
In the QGLWidget docs, there's a little example of how a child should look like, and it contains:
glEnable(GL_DEPTH_TEST);
However, the QGLFormat::depth() docs say that depth-testing is active by default. So why does QGLWidget enable it?
In any case, here is my code attempting to set these things up.
//fragment shader
#version 330
precision highp float;
uniform vec3 EyeAxis = vec3(0.0,0.0,1.0);
uniform mat4 Modelview;
uniform mat4 Projection;
in vec3 ex_Color;
in vec4 ex_Normal;
out vec4 FragColor;
void main(void)
{
vec4 Normal = Projection*Modelview*ex_Normal;
vec4 Eye = vec4(EyeAxis,1.0);
float c = abs(dot(normalize(Eye.xyz),normalize(Normal.xyz))) ;
FragColor = vec4((0.2+0.8*c)*ex_Color,1.0);
}
void MyNGLWidget::Initialize()
{
//only called after drawing data (coordinates, colors, normals, etc) have been loaded
GenBuffers();
GenShaders();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_DEPTH_TEST);
Initialized = true;
updateGL();
}
void MyNGLWidget::initializeGL()
{
glewInit();
format().setDepth(true); //even though its true by default
format().setDepthBufferSize(32); //even though Qt tends to reject this value and stick to 24X8
}
Any hints and tips?
I have a Qt program with a child of QGLWidget and everything is working just fine with OpenGL 3.3. The one problem I'm getting is that all the meshes I create are transparent even though their alpha values are set to 1 (remembering that OpenGL works on 0-1, not 0-255). I've played around with the OpenGL commands but can't get it to work. This all sounds and feels like its more of an OpenGL problem than a Qt problem, but I'm not being able to get much help from the people at the opengl.org forums and so, thinking that maybe I was missing something Qt-related, I returned to the documentation and found the following.
In the QGLWidget docs, there's a little example of how a child should look like, and it contains:
glEnable(GL_DEPTH_TEST);
However, the QGLFormat::depth() docs say that depth-testing is active by default. So why does QGLWidget enable it?
In any case, here is my code attempting to set these things up.
//fragment shader
#version 330
precision highp float;
uniform vec3 EyeAxis = vec3(0.0,0.0,1.0);
uniform mat4 Modelview;
uniform mat4 Projection;
in vec3 ex_Color;
in vec4 ex_Normal;
out vec4 FragColor;
void main(void)
{
vec4 Normal = Projection*Modelview*ex_Normal;
vec4 Eye = vec4(EyeAxis,1.0);
float c = abs(dot(normalize(Eye.xyz),normalize(Normal.xyz))) ;
FragColor = vec4((0.2+0.8*c)*ex_Color,1.0);
}
void MyNGLWidget::Initialize()
{
//only called after drawing data (coordinates, colors, normals, etc) have been loaded
GenBuffers();
GenShaders();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_DEPTH_TEST);
Initialized = true;
updateGL();
}
void MyNGLWidget::initializeGL()
{
glewInit();
format().setDepth(true); //even though its true by default
format().setDepthBufferSize(32); //even though Qt tends to reject this value and stick to 24X8
}
Any hints and tips?