I have the following simple struct, which represents an OpenGL texture:
#pragma once
#include <GL/glew.h>
#include <string>
#include "Shader.hpp"
struct Texture
{
static constexpr GLenum UNIT[] = {GL_TEXTURE0, GL_TEXTURE1, GL_TEXTURE2, GL_TEXTURE3,
GL_TEXTURE4, GL_TEXTURE5, GL_TEXTURE6, GL_TEXTURE7,
GL_TEXTURE8, GL_TEXTURE9, GL_TEXTURE10, GL_TEXTURE11,
GL_TEXTURE12, GL_TEXTURE13, GL_TEXTURE14, GL_TEXTURE15};
int width, height;
int unit;
GLuint id;
void use(const Shader &shader, const std::string &name) const
{
glActiveTexture(UNIT[unit]);
glBindTexture(GL_TEXTURE_2D, id);
glUniform1i(shader.getLocation(name), unit);
}
};
The variables GL_TEXTURE0
through GL_TEXTURE15
are defined in glew.h, as per this excerpt:
#define GL_TEXTURE0 0x84C0
#define GL_TEXTURE1 0x84C1
#define GL_TEXTURE2 0x84C2
//etc...
When I try to compile my code I get the following error:
Undefined symbols for architecture x86_64:
"Texture::UNIT", referenced from:
Texture::use(Shader const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const in main.cpp.o
ld: symbol(s) not found for architecture x86_64
I obviously defined and initialized UNIT
in the struct, yet it claims it doesn't exist. This error persists if I change UNIT
to Texture::UNIT
when it is accessed in the use
method. It also persists if I change the type of UNIT
to an array of integers. Why is this error being generated?