Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
allow binding the sprite object
Browse files Browse the repository at this point in the history
refs #15
  • Loading branch information
kkaefer committed Feb 3, 2014
1 parent a6e464b commit e478ae2
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/style/sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <string>
#include <llmr/platform/platform.hpp>
#include <llmr/platform/gl.hpp>

#include <png.h>

Expand Down Expand Up @@ -223,3 +224,27 @@ ImagePosition Sprite::getPosition(const std::string& name, bool repeating) {
}
};
}

void Sprite::bind(bool linear) {
if (!width || !height) {
fprintf(stderr, "trying to bind texture without dimension\n");
return;
}

if (!texture) {
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.data());
} else {
glBindTexture(GL_TEXTURE_2D, texture);
}

GLuint filter = linear ? GL_LINEAR : GL_NEAREST;
if (filter != this->filter) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
this->filter = filter;
}
}

0 comments on commit e478ae2

Please sign in to comment.