How do I load a texture from a file?

This is what I have tried:

void Texture2D::load(string path) {
	int width, height, components;

	// Use stbi image library to load our image
	unsigned char* imageData = stbi_load(path.c_str(), &width, &height, &components, STBI_rgb_alpha);

	unsigned char* thepix = new unsigned char[width * height * 4];
	text.allocate(width, height, GL_RGBA)

	text.loadData(thepix, width, height, GL_RGBA);
}

did you try using ofImage object to load the image?

like this?

ofPixels mypix;
	ofLoadImage(mypix, path);
	text.loadData(mypix);
	mypath = path;

Hey that will work, and can also use use an ofTexture as an argument in ofLoadImage():

    ofTexture texture;
    std::string path = "myImage.jpg";
    ofLoadImage(texture, path);