47 lines
1.2 KiB
C++
47 lines
1.2 KiB
C++
#include "ImageHelper.h"
|
|
#include <vector>
|
|
#include "../external/QRCode/QrCode.hpp"
|
|
|
|
ImageHelper::ImageHelper()
|
|
{
|
|
}
|
|
|
|
|
|
ImageHelper::~ImageHelper()
|
|
{
|
|
}
|
|
|
|
GLuint ImageHelper::GetQr(std::string strcode)
|
|
{
|
|
if (strcode.empty())return 0;
|
|
std::vector<unsigned char> qrcode;
|
|
qrcodegen::QrCode qr0 = qrcodegen::QrCode::encodeText(strcode.c_str(), qrcodegen::QrCode::Ecc::MEDIUM);
|
|
for (int y = 0; y < qr0.getSize(); y++) {
|
|
for (int x = 0; x < qr0.getSize(); x++) {
|
|
if (qr0.getModule(x, y)) {
|
|
qrcode.push_back(0);
|
|
qrcode.push_back(0);
|
|
qrcode.push_back(0);
|
|
}
|
|
else {
|
|
qrcode.push_back(0xFF);
|
|
qrcode.push_back(0xFF);
|
|
qrcode.push_back(0xFF);
|
|
}
|
|
|
|
}
|
|
}
|
|
GLuint tex;
|
|
glGenTextures(1, &tex);
|
|
if (tex > 0) {
|
|
glBindTexture(GL_TEXTURE_2D, tex);
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, qr0.getSize(), qr0.getSize(), 0, GL_RGB, GL_UNSIGNED_BYTE, &qrcode[0]);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
}
|
|
return tex;
|
|
} |