I recently started to learn OpenGL (ver. 3.3 to be specific) and I also wanted to use some object oriented design for some features. For example, I want to create a class called Shader that reads the shader from a text file, attach, detach it etc. The problem I have is the destructor. I suppose all OpenGL objects work more or less like that
glCreateShader()
// some code here
glDeleteShader()
Lets say I design my class like this (this is just a sketch so without any details)
class Shader
{
public:
// read from file - not important right now
Shader( ){}
void delete()
{
glDeleteShader();
}
~Shader()
{
glDeleteShader();
}
};
I could create my object and delete it like this
Shader x;
x.delete();
but this will not delete the object itself - only frees the memory of OpenGL shader. It would be better to have something like this
Shader x;
delete(x);
where function delete() removes everything from the memory (with the object itself). Is it possible, or should I only use pointers?
Shader* x = new Shader();
delete x;
I have the same problem for any C library.