Follow along with the video below to see how to install our site as a web app on your home screen.
Примечание: This feature may not be available in some browsers.
IntBuffer buf = BufferUtils.createIntBuffer(width * height);
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++)
buf.put(pixels[y * width + x]); // RGBA
// как хочешь, здесь ты пиксели как угодно можешь получить
buf.flip();
int textureID = glGenTextures();
glBindTexture(GL_TEXTURE_2D, textureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf);
//... всё это лишь куски кода, но думаю разберешься
//выделение памяти с очисткой
private synchronized void freeFrameBuffer() {
try {
if (this.texture != 0) GlStateManager.deleteTexture(this.texture);
this.texture = 0;
} catch (Exception e) {
// Just in case, we make sure we don't crash. Because crashing is bad.
LoggerUtils.error("Error while cleaning up a world view frame buffer.");
}
}
// This method builds the frame buffer and texture references
private void allocateFrameBuffer() {
this.texture = GlStateManager.generateTexture(); //Release via: GlStateManager.deleteTexture(colorTexture);
GlStateManager.bindTexture(this.texture);
GlStateManager.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GlStateManager.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL11.GL_RGBA, GL11.GL_INT, null);
EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, this.texture, 0);
EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);
}
//рисование на текстуре (в текстуру)
//Set gl options
GlStateManager.viewport(0, 0, mc.displayWidth, mc.displayHeight);
GlStateManager.bindTexture(0);
EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, framebuffer);
GlStateManager.clearColor(1.0f, 0.0f, 0.0f, 0.5f);
GlStateManager.clear(GL11.GL_COLOR_BUFFER_BIT);
Ок! А биндить-то как? Нешёл вот это Забиндить TextureAtlasSprite, но не нашёл такого метода.Ага, пишешь свою реализацию, потом юзаешь ее при создании квадов или чего там
//int texture...
GlStateManager.bindTexture(this.texture);
TextureUtil.int textureId = GL11.glGenTextures();
TextureUtil.uploadTextureImage(textureId, myBufferedImage);
GlStateManager.bindTexture(textureId);
Боюсь, что она на то и процедурная, что никаким атласом не описывается.Поэтому лучше делать шейдером или подготовить атлас метаморфозы