mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-02 11:21:15 +01:00
Example demonstrates multiple OpenGL contexts possible
This commit is contained in:
parent
247dfeefc8
commit
3144f64b06
@ -18,10 +18,12 @@ import static org.lwjgl.opengl.GL11.*;
|
||||
public class MapAnimationDemo {
|
||||
|
||||
public static final int MAP_ID = 1;
|
||||
public static final int EGL_MAP_ID = 2;
|
||||
public static final int OPENGL_MAP_ID = 2;
|
||||
public static final int OPENGL2_MAP_ID = 3;
|
||||
|
||||
private static final Graphics2DFramebuffer framebuffer = new Graphics2DFramebuffer();
|
||||
private static final GLFWFramebuffer glfwFramebuffer = new GLFWFramebuffer();
|
||||
private static final GLFWFramebuffer glfwFramebuffer2 = new GLFWFramebuffer();
|
||||
|
||||
public static void init() {
|
||||
SchedulerManager scheduler = MinecraftServer.getSchedulerManager();
|
||||
@ -34,8 +36,12 @@ public class MapAnimationDemo {
|
||||
player.getInventory().addItemStack(map);
|
||||
|
||||
ItemStack map2 = new ItemStack(Material.FILLED_MAP, (byte) 1);
|
||||
map2.setItemMeta(new MapMeta(EGL_MAP_ID));
|
||||
map2.setItemMeta(new MapMeta(OPENGL_MAP_ID));
|
||||
player.getInventory().addItemStack(map2);
|
||||
|
||||
ItemStack map3 = new ItemStack(Material.FILLED_MAP, (byte) 1);
|
||||
map3.setItemMeta(new MapMeta(OPENGL2_MAP_ID));
|
||||
player.getInventory().addItemStack(map3);
|
||||
});
|
||||
});
|
||||
|
||||
@ -56,6 +62,24 @@ public class MapAnimationDemo {
|
||||
|
||||
glEnd();
|
||||
});
|
||||
|
||||
glfwFramebuffer2.setupRenderLoop(16, TimeUnit.MILLISECOND, () -> {
|
||||
glClearColor(0f, 1f, 0f, 1f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
|
||||
glVertex2f(0, -0.75f);
|
||||
glColor3f(1f, 0f, 0f);
|
||||
|
||||
glVertex2f(0.75f, 0.75f);
|
||||
glColor3f(0f, 1f, 0f);
|
||||
|
||||
glVertex2f(-0.75f, 0.75f);
|
||||
glColor3f(0f, 0f, 1f);
|
||||
|
||||
glEnd();
|
||||
});
|
||||
}
|
||||
|
||||
private static float time = 0f;
|
||||
@ -95,10 +119,16 @@ public class MapAnimationDemo {
|
||||
p.getPlayerConnection().sendPacket(mapDataPacket);
|
||||
});
|
||||
|
||||
mapDataPacket.mapId = EGL_MAP_ID;
|
||||
mapDataPacket.mapId = OPENGL_MAP_ID;
|
||||
glfwFramebuffer.preparePacket(mapDataPacket);
|
||||
MinecraftServer.getConnectionManager().getOnlinePlayers().forEach(p -> {
|
||||
p.getPlayerConnection().sendPacket(mapDataPacket);
|
||||
});
|
||||
|
||||
mapDataPacket.mapId = OPENGL2_MAP_ID;
|
||||
glfwFramebuffer2.preparePacket(mapDataPacket);
|
||||
MinecraftServer.getConnectionManager().getOnlinePlayers().forEach(p -> {
|
||||
p.getPlayerConnection().sendPacket(mapDataPacket);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user