QImage image(256, 256, QImage::Format::Format_RGBA8888); image.fill(QColor(255, 127, 63, 255)); m_texture = std::make_unique<QOpenGLTexture>(QOpenGLTexture::Target::Target2D); m_texture->setFormat(QOpenGLTexture::TextureFormat::RGBA8U); m_texture->setSize(256, 256); m_texture->setMipLevels(8); m_texture->allocateStorage(); m_texture->setData(QOpenGLTexture::PixelFormat::RGBA_Integer, QOpenGLTexture::PixelType::UInt8, image.constBits());
#version 330 corein vec2 TexCoord;out vec4 color;uniform usampler2D ourTexture1;void main(){ uvec4 d = texture(ourTexture1, TexCoord); color = vec4(d.r / 255.0f, d.g / 255.0f, d.b / 255.0f, 1.0);}
m_funcs->glGenTextures(1, &m_textureId); m_funcs->glPixelStorei(GL_UNPACK_ALIGNMENT, 4); m_funcs->glBindTexture(GL_TEXTURE_2D, m_textureId); m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); // вот это нужно! m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // и это! m_funcs->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8UI, 256, 256, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, m_image.imageData({0, 0}).data()); m_funcs->glGenerateMipmap(GL_TEXTURE_2D); m_funcs->glBindTexture(GL_TEXTURE_2D, 0);
m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); // вот это нужно! m_funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // и это!