I want to reuse the same image several times as tiles in a game level. I defined the texture as class member:
private:
ofTexture floor;
Then I load the image for the texture in the setup() method:
void ofApp::setup(){
ofLoadImage(floor, “floor.png”);
…
}
And finally, I draw it:
void ofApp::draw(){
floor.draw(x,y,1);
…
}
I receive the warning message [warning] ofGLRenderer: draw(): texture is not allocated for each tile; what am I doing wrong? Where and how can I allocate the texture, and how? Is there a better way to do what I’m trying to achieve?
check your image name and image path… for example if your image path is : yourProject/bin/images/floor.png … in your setup must: ofLoadImage(floor, “images/floor.png”);
if you know the dimensions of the image (300x300 for example), you can call the allocate() method explicitly before loading the texture:
floor.allocate( 300, 300, GL_RGB );
you could also check for the loading/allocation in the draw method:
if(floor.isAllocated()){
floor.draw(x,y,1)
}
Thanks @nickhubben! Checking whether textures are allocated before calling the drawing functions did the job, apparently draw() was called before setup() (where the textures were loaded and allocated) was finished.