Been teaching myself "modern" OpenGL w/ shaders (as opposed to the old fixed pipeline) with GLFW (and using GLAD loader). So far, so good - draws a rectangle that I can move around, with a texture that I loaded using stb_image. I've even gotten animations going, and for shits and giggles I've even made it so I can scale the rectangle (and can alter the rate at which the scaling occurs). Now I want to compartmentalize, make modular - such as, for instance, making an animation class that can handle loading a texture, animating it, etc. My problem, however, is avoiding multiple definitions when trying to create separate classes that will need OpenGL/GLFW functionality, or to use stb_image. If I just outright include the headers in my class file, I get a spam of multiple definition errors. So, I tried moving this part: #define GLAD_GL_IMPLEMENTATION #include <glad/glad.h> #define GLFW_INCLUDE_NONE #include <GLFW/glfw3.h> #include <glm/glm.hpp> #include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/type_ptr.hpp> into its own header and including it everywhere I needed my GL and stb_image stuff, and that didn't work. I then tried making it just into a separate cpp file, instead of being in a header, and that didn't work either. I tried the latter ideas AND (at the same time) just including the headers minus the defines in my class header file(s), and that didn't work. Well crap, I'm not getting anywhere. All these ideas were stuff that I got when Googling how others fixed this conundrum. I'm feeling really dumb because it seems so simple a solution, like I'm missing something very obvious (which ended up being the case with an issue I had with loading textures and having them rendering correctly - racked my brains for days before I realized that I messed up the glVertexAttribPointer call for my texture coordinates). Holy crap. What am I missing? ~_~
Maybe a dumb question, but does your new class' header have header guards? I don't know how much C++ you know. Otherwise, can you post the actual error message you're getting, as well as your class structure? EDIT: Coming back to this later, I realized you may only need the #includes and #defines listed above in your class file, especially the #defines. Including your class elsewhere would also include these headers, and the header guards would hopefully make sure nothing is defined multiple times. For example, if you have a class called Animation defined in animation.h that has all of these #includes etc., you'd just have to #include "animation.h" in your main.cpp, and not any of the OpenGL stuff in main.cpp, since it'd already be included via animation.h. Hope that makes any kind of sense.
Alright, I THINK I'VE FINALLY figured it out. Holy crap, I'm slow. I was supposed to include stb_image.h not in the header for my class, but in the implementation cpp... which I feel weird admitting I've never had to do before. It SEEMS to work now! (Also had a similar problem with openGL, GLFW functions in separate classes that was likely-solved the same way)