Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9289419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:10:27+00:00 2026-06-18T20:10:27+00:00

I have coded a N-Body/GPU program with OpenCL and GLUT functions, and it works

  • 0

I have coded a N-Body/GPU program with OpenCL and GLUT functions, and it works fine. 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.

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” :

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 :

#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.

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 (i.e without Qt user interface)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T20:10:29+00:00Added an answer on June 18, 2026 at 8:10 pm

    Depending on which OpenGL / GLSL version you’re targeting, don’t you need a trivial fragment shader in order to link successfully? 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)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following jQuery code: $(body.page-calendar-practices-2012-05 #content-header h1#title) which works fine. I can
I have the following code that works fine in IE: <HTML> <BODY> <script language=JavaScript>
OK, every other browser works fine with the method I have coded so far
Right now I have coded about 80% of my game and the remaining 20%
I have a form sheet segue that should display hard-coded html page. Now I
I have some code which I want to document with in-body comments like so:
i have this code: $('.access a').toggle(function() { $('link').attr('href', 'styles/accessstyles.css'); $('body').css('font-size', '16px'); }, function() {
I mean I have this code: <script> $(document).ready( function() { $('html, body').animate({ scrollTop: $(.error).offset().top
I have this background, the css code is: body { background: #FFF url('images/bg.png') no-repeat
In my erb file, I have the following code in the body tag: <%

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.