[英]Qt - GLUT - vertex shader program link
I have coded a N-Body/GPU program with OpenCL and GLUT functions, and it works fine. 我已经用OpenCL和GLUT函数编写了一个N-Body / GPU程序,并且运行良好。 I try now to convert it in order to get the main GLUT window into a QGLWidget subclass ("here GLWidget") with a Qt graphical interface.
我现在尝试将其转换,以便将主GLUT窗口转换为具有Qt图形界面的QGLWidget子类(“此处为GLWidget”)。
My problem is that the "program vertex shader" link fails. 我的问题是“程序顶点着色器”链接失败。 Here is this part of the source file "GLWidget.cpp" where I get in "
_compileProgram
" the error " Failed to link program
" : 这是源文件“ GLWidget.cpp”的这一部分,在该文件中,我获得“
_compileProgram
”错误“ Failed to link program
”:
extern const char *vertexShader;
void GLWidget::GLInit()
{
LoadGLTextures(); // load the textures.
glClearColor(0.0 ,0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
m_program = _compileProgram(vertexShader);
glClampColor(GL_CLAMP_VERTEX_COLOR, GL_FALSE);
glClampColor(GL_CLAMP_FRAGMENT_COLOR, GL_FALSE);
// memsize of GPU data
unsigned int memSize = sizeof(cl_double4) * 4 * Galaxy->getNumParticles();
createVBO(memSize);
}
void GLWidget::createVBO(uint size)
{
GLuint vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, size, Galaxy->pos, GL_DYNAMIC_DRAW);
}
GLuint GLWidget::_compileProgram(const char *vsource)
{
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vsource, 0);
glCompileShader(vertexShader);
GLuint program = glCreateProgram();
glAttachShader(program, vertexShader);
glLinkProgram(program);
// check if program linked
GLint success = 0;
glGetProgramiv(program, GL_LINK_STATUS, &success);
if (!success) {
char temp[256];
glGetProgramInfoLog(program, 256, 0, temp);
printf("Failed to link program:\n%s\n", temp);
glDeleteProgram(program);
program = 0;
}
return program;
}
I use the following vertex shader program in shader.cpp : 我在shader.cpp中使用以下顶点着色器程序:
#define STRINGIFY(A) #A
// vertex shader
const char *vertexShader = STRINGIFY(
uniform float pointRadius; // point size in world space
uniform float pointScale; // scale to calculate size in pixels
void main()
{
// calculate window-space point size
vec3 posEye = vec3(gl_ModelViewMatrix * vec4(gl_Vertex.xyz, 1.0));
float dist = length(posEye);
gl_PointSize = pointRadius * (pointScale / dist);
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_ModelViewProjectionMatrix * vec4(gl_Vertex.xyz, 1.0);
gl_FrontColor = gl_Color;
}
);
I make you notice that the "GLuint m_program" is a data member of the subclass GLWidget. 我使您注意到,“ GLuint m_program”是子类GLWidget的数据成员。
Anyone could see what's wrong? 任何人都可以看到有什么问题吗?
More generally, can I use directly the same GLUT functions " glAttachShader
", " glLinkProgram
" on a GLWidget object like I did it with the first version of my code (ie without Qt user interface)? 更一般而言,我可以像在第一个版本的代码中(即没有Qt用户界面的情况下)那样,在GLWidget对象上直接使用相同的GLUT函数“
glAttachShader
”,“ glLinkProgram
”吗?
Depending on which OpenGL / GLSL version you're targeting, don't you need a trivial fragment shader in order to link successfully? 根据要定位的OpenGL / GLSL版本,是否不需要琐碎的片段着色器才能成功链接? You mention OpenGL 4.1 but your vertex shader code is using GLSL variable names which are deprecated in GLSL 3.3 (gl_TexCoord, for example)
您提到了OpenGL 4.1,但是您的顶点着色器代码使用的是GLSL 3.3中已弃用的GLSL变量名称(例如,gl_TexCoord)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.