| 18 | #include "common.hpp" |
| 19 | |
| 20 | void Texture::InitFromRawRGB(int width, int height, bool hasAlpha, |
| 21 | const unsigned char* data) { |
| 22 | GLenum format = hasAlpha ? GL_RGBA : GL_RGB; |
| 23 | |
| 24 | glGenTextures(1, &mTextureH); |
| 25 | glBindTexture(GL_TEXTURE_2D, mTextureH); |
| 26 | |
| 27 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 28 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 29 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 30 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 31 | glPixelStorei(GL_PACK_ALIGNMENT, 1); |
| 32 | |
| 33 | glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, |
| 34 | GL_UNSIGNED_BYTE, data); |
| 35 | glBindTexture(GL_TEXTURE_2D, 0); |
| 36 | } |
| 37 | |
| 38 | void Texture::Bind(int unit) { |
| 39 | glActiveTexture(unit); |