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?
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:
#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
", 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.