Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Weird Error: shader is invalid

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2008
    Posts
    13

    Weird Error: shader is invalid

    hello,
    class ShaderProgram {
    public:
    ShaderProgram(GLuint id) {
    m_uiProgramID = id;
    }
    GLuint programID() {
    return m_uiProgramID;
    }
    }; // this class is defined in another file
    when i use it like this:
    GLuint tmpID = create and link program; // this is correct.
    ShaderProgram p(tmpID);
    GLuint id = p.programID(); // this does not correct.

    but it is ok like this:
    ShaderProgram *p = new ShaderProgram(tmpID);
    GLuint id = p->programID();

    why? The program id is not just a int?? what if it is copied? the program object will lost?

  2. #2
    Intern Newbie
    Join Date
    Jun 2010
    Posts
    34

    Re: Weird Error: shader is invalid

    Is this is the problem
    ShaderProgram(GLuint id) {
    m_uiProgramID = id;
    }

    // m_uiProgramID = id; id is not copied to member variable m_uiProgramID

    No more problem found in this code.

    I faced another problem when creating static object of my shader class.

    Its reason was, the rendering context is not created and not called wglMakeCurrent before calling wglGetProcAddress.

    If rendering context is not active for the current thread, then wglGetProcAddress returns NULL.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2008
    Posts
    13

    Re: Weird Error: shader is invalid

    thank you, i make a mistake in the code, but that is not the cause.

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,894

    Re: Weird Error: shader is invalid

    Quote Originally Posted by cjren
    when i use it like this:
    Code :
    GLuint tmpID = create and link program; // this is correct.
    ShaderProgram p(tmpID);
    GLuint id = p.programID(); // this does not correct.
    but it is ok like this:
    Code :
    ShaderProgram *p = new ShaderProgram(tmpID);
    GLuint id = p->programID();
    why?
    Either should be just fine. This is not an OpenGL problem you're having but a basic C++ problem apparently.

    Post a small "complete" test program that illustrates your problem. For instance, this test prog disproves your assertion:

    Code :
    #include <GL/gl.h>
    #include <stdio.h>
     
    class ShaderProgram {
      GLuint m_uiProgramID;
    public:
      ShaderProgram(GLuint id) {
        m_uiProgramID = id;
      }
     
      GLuint programID() {
        return m_uiProgramID;
      }
    };
     
    int main()
    {
      GLuint tmpID = 123;
      ShaderProgram p(tmpID);
      GLuint id = p.programID();
     
      printf( "This better be 123: %u\n", id );
      return 0;
    }

    The program id is not just a int??
    No, the program handle is exactly a GLuint (unsigned int).

    what if it is copied? the program object will lost?
    No, this is C/C++, and this is just an unsigned int handle. As you know, there is no built-in garbage collection in C/C++. Nothing mysterious going on here.

    Post a short "complete" test program that illustrates your problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •