Search in sources :

Example 6 with GL11.glDeleteTextures

use of org.lwjgl.opengl.GL11.glDeleteTextures in project Terasology by MovingBlocks.

the class GLFWSplashScreen method run.

@Override
public void run() {
    if (!GLFW.glfwInit()) {
        throw new RuntimeException("Cannot init GLFW!");
    }
    int width = 800;
    int height = 289;
    window = new Window(width, height, "", false);
    pixel = new Texture();
    ByteBuffer bytes = BufferUtils.createByteBuffer(4);
    bytes.put((byte) -1).put((byte) -1).put((byte) -1).put((byte) -1);
    bytes.flip();
    pixel.bind();
    pixel.uploadData(1, 1, bytes);
    try {
        widgets.add(new Image(GLFWSplashScreen.class.getResource("/splash/splash.png"), 0, 0));
        widgets.add(new ActivatableImage(GLFWSplashScreen.class.getResource("/splash/splash_1.png"), 0, 0, TerasologyEngineStatus.PREPARING_SUBSYSTEMS.getDescription()));
        widgets.add(new ActivatableImage(GLFWSplashScreen.class.getResource("/splash/splash_2.png"), 150, 0, TerasologyEngineStatus.INITIALIZING_MODULE_MANAGER.getDescription()));
        widgets.add(new ActivatableImage(GLFWSplashScreen.class.getResource("/splash/splash_3.png"), 300, 0, TerasologyEngineStatus.INITIALIZING_ASSET_TYPES.getDescription()));
        widgets.add(new ActivatableImage(GLFWSplashScreen.class.getResource("/splash/splash_4.png"), 450, 0, TerasologyEngineStatus.INITIALIZING_SUBSYSTEMS.getDescription()));
        widgets.add(new ActivatableImage(GLFWSplashScreen.class.getResource("/splash/splash_5.png"), 630, 0, TerasologyEngineStatus.INITIALIZING_ASSET_MANAGEMENT.getDescription()));
        widgets.add(new Image(GLFWSplashScreen.class.getResource("/splash/splash_text.png"), 0, 0));
        widgets.add(new BorderedRectangle(pixel, 20, 20, 600, 30));
        widgets.add(new AnimatedBoxRow(pixel, 20 + 450 + 10, 20, 600 - 450 - 20, 30));
    } catch (IOException e) {
        throw new RuntimeException("Cannot load splash image resources");
    }
    Renderer renderer = new Renderer();
    renderer.init();
    countDownLatch.countDown();
    GL11.glClearColor(0f, 0f, 0f, 0f);
    double last = GLFW.glfwGetTime();
    try {
        while (!isClosing && !window.isClosing()) {
            double dTime = GLFW.glfwGetTime() - last;
            last = GLFW.glfwGetTime();
            renderer.clear();
            widgets.forEach(widget -> widget.update(dTime));
            widgets.forEach(i -> i.render(renderer));
            renderer.drawText(message, 30, 25, Color.BLACK);
            window.update();
        }
    } finally {
        widgets.stream().filter(w -> w instanceof Image).map(w -> (Image) w).forEach(Image::delete);
        pixel.delete();
        renderer.dispose();
        window.destroy();
    }
}
Also used : Window(org.terasology.splash.glfw.graphics.Window) ActivatableImage(org.terasology.splash.glfw.widgets.ActivatableImage) Image(org.terasology.splash.glfw.widgets.Image) Renderer(org.terasology.splash.glfw.graphics.Renderer) IOException(java.io.IOException) TerasologyEngineStatus(org.terasology.engine.core.TerasologyEngineStatus) GLFW(org.lwjgl.glfw.GLFW) Widget(org.terasology.splash.glfw.widgets.Widget) ByteBuffer(java.nio.ByteBuffer) BufferUtils(org.lwjgl.BufferUtils) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Window(org.terasology.splash.glfw.graphics.Window) AnimatedBoxRow(org.terasology.splash.glfw.widgets.AnimatedBoxRow) BorderedRectangle(org.terasology.splash.glfw.widgets.BorderedRectangle) GL11(org.lwjgl.opengl.GL11) Texture(org.terasology.splash.glfw.graphics.Texture) LinkedList(java.util.LinkedList) SplashScreen(org.terasology.splash.SplashScreen) Color(org.terasology.splash.glfw.graphics.Color) BorderedRectangle(org.terasology.splash.glfw.widgets.BorderedRectangle) ActivatableImage(org.terasology.splash.glfw.widgets.ActivatableImage) IOException(java.io.IOException) ActivatableImage(org.terasology.splash.glfw.widgets.ActivatableImage) Image(org.terasology.splash.glfw.widgets.Image) Texture(org.terasology.splash.glfw.graphics.Texture) ByteBuffer(java.nio.ByteBuffer) Renderer(org.terasology.splash.glfw.graphics.Renderer) AnimatedBoxRow(org.terasology.splash.glfw.widgets.AnimatedBoxRow)

Example 7 with GL11.glDeleteTextures

use of org.lwjgl.opengl.GL11.glDeleteTextures in project runelite by runelite.

the class ModelViewer method main.

public static void main(String[] args) throws Exception {
    Options options = new Options();
    options.addOption(null, "npcdir", true, "npc directory");
    options.addOption(null, "mapdir", true, "maps directory");
    options.addOption(null, "objectdir", true, "objects directory");
    options.addOption(null, "npc", true, "npc to render");
    options.addOption(null, "object", true, "object to render");
    options.addOption(null, "model", true, "model to render");
    options.addOption(null, "map", true, "map region to render");
    options.addOption(null, "kits", true, "kits to render");
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = parser.parse(options, args);
    String npcdir = cmd.getOptionValue("npcdir");
    String mapdir = cmd.getOptionValue("mapdir");
    String objectdir = cmd.getOptionValue("objectdir");
    NpcDefinition npcdef = null;
    ObjectDefinition objdef = null;
    List<ModelDefinition> models = new ArrayList<>();
    Region region = null;
    if (cmd.hasOption("model")) {
        // render model
        String model = cmd.getOptionValue("model");
        ModelDefinition md = ModelManager.getModel(Integer.parseInt(model), null, null);
        models.add(md);
    }
    if (cmd.hasOption("npc")) {
        String npc = cmd.getOptionValue("npc");
        try (FileInputStream fin = new FileInputStream(npcdir + "/" + npc + ".json")) {
            npcdef = new Gson().fromJson(new InputStreamReader(fin), NpcDefinition.class);
        }
        for (int model : npcdef.models) {
            ModelDefinition md = ModelManager.getModel(model, null, null);
            models.add(md);
        }
    }
    if (cmd.hasOption("object")) {
        String obj = cmd.getOptionValue("object");
        try (FileInputStream fin = new FileInputStream(objectdir + "/" + obj + ".json")) {
            objdef = new Gson().fromJson(new InputStreamReader(fin), ObjectDefinition.class);
        }
        for (int model : objdef.getObjectModels()) {
            ModelDefinition md = ModelManager.getModel(model, null, null);
            models.add(md);
        }
    }
    if (cmd.hasOption("map")) {
        String map = cmd.getOptionValue("map");
        String[] s = map.split(",");
        int x = Integer.parseInt(s[0]), y = Integer.parseInt(s[1]);
        region = new Region(x, y);
        MapLoader mapLoader = new MapLoader();
        LocationsLoader locationsLoader = new LocationsLoader();
        try (FileInputStream fin = new FileInputStream(mapdir + "/m" + x + "_" + y + ".dat")) {
            byte[] b = IOUtils.toByteArray(fin);
            MapDefinition mapDef = mapLoader.load(x, y, b);
            region.loadTerrain(mapDef);
        }
        try (FileInputStream fin = new FileInputStream(mapdir + "/l" + x + "_" + y + ".dat")) {
            byte[] b = IOUtils.toByteArray(fin);
            LocationsDefinition locDef = locationsLoader.load(x, y, b);
            region.loadLocations(locDef);
        } catch (FileNotFoundException ex) {
            logger.info("No landscape file for {},{}", x, y);
        }
        loadUnderlays();
        loadOverlays();
    }
    if (cmd.hasOption("kits")) {
        String kits = cmd.getOptionValue("kits");
        Integer[] kitIds = Arrays.stream(kits.split(",")).map(s -> Integer.parseInt(s)).toArray(Integer[]::new);
        for (int kitId : kitIds) {
            KitDefinition kit = KitManager.getKit(kitId);
            for (int model : kit.modelIds) {
                ModelDefinition md = ModelManager.getModel(model, null, null);
                models.add(md);
            }
        }
    }
    Display.setDisplayMode(new DisplayMode(800, 600));
    Display.setTitle("Model Viewer");
    Display.setInitialBackground((float) Color.gray.getRed() / 255f, (float) Color.gray.getGreen() / 255f, (float) Color.gray.getBlue() / 255f);
    Display.create();
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    double aspect = 1;
    // near should be chosen as far into the scene as possible
    double near = 1;
    double far = 10000;
    // 1 gives you a 90° field of view. It's tan(fov_angle)/2.
    double fov = 1;
    GL11.glFrustum(-aspect * near * fov, aspect * near * fov, -fov, fov, near, far);
    GL11.glPopMatrix();
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glCullFace(GL11.GL_BACK);
    GL11.glEnable(GL11.GL_CULL_FACE);
    long last = 0;
    Camera camera = new Camera();
    while (!Display.isCloseRequested()) {
        // Clear the screen and depth buffer
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        for (ModelDefinition def : models) {
            short[] recolourToFind = null, recolourToReplace = null;
            if (npcdef != null) {
                recolourToFind = npcdef.recolorToFind;
                recolourToReplace = npcdef.recolorToReplace;
            }
            if (objdef != null) {
                recolourToFind = objdef.getRecolorToFind();
                recolourToReplace = objdef.getRecolorToReplace();
            }
            drawModel(def, recolourToFind, recolourToReplace);
        }
        drawRegion(region);
        Display.update();
        // fps
        Display.sync(50);
        long delta = System.currentTimeMillis() - last;
        last = System.currentTimeMillis();
        camera.acceptInput(delta);
        camera.apply();
    }
    Display.destroy();
}
Also used : Color(java.awt.Color) Arrays(java.util.Arrays) Location(net.runelite.cache.region.Location) Options(org.apache.commons.cli.Options) GL_TEXTURE_WRAP_T(org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_T) LoggerFactory(org.slf4j.LoggerFactory) GL_TEXTURE_WRAP_S(org.lwjgl.opengl.GL11.GL_TEXTURE_WRAP_S) HashMap(java.util.HashMap) Vector3f(net.runelite.cache.models.Vector3f) GL_NEAREST(org.lwjgl.opengl.GL11.GL_NEAREST) GL_TEXTURE_2D(org.lwjgl.opengl.GL11.GL_TEXTURE_2D) ByteBuffer(java.nio.ByteBuffer) Position(net.runelite.cache.region.Position) ArrayList(java.util.ArrayList) DefaultParser(org.apache.commons.cli.DefaultParser) Gson(com.google.gson.Gson) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) CommandLine(org.apache.commons.cli.CommandLine) Region(net.runelite.cache.region.Region) OverlayDefinition(net.runelite.cache.definitions.OverlayDefinition) GL11(org.lwjgl.opengl.GL11) ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) TextureDefinition(net.runelite.cache.definitions.TextureDefinition) VertexNormal(net.runelite.cache.models.VertexNormal) Display(org.lwjgl.opengl.Display) Logger(org.slf4j.Logger) BufferedImage(java.awt.image.BufferedImage) CommandLineParser(org.apache.commons.cli.CommandLineParser) UnderlayDefinition(net.runelite.cache.definitions.UnderlayDefinition) GL_TEXTURE_MIN_FILTER(org.lwjgl.opengl.GL11.GL_TEXTURE_MIN_FILTER) LocationsLoader(net.runelite.cache.definitions.loaders.LocationsLoader) IOUtils(org.apache.commons.compress.utils.IOUtils) IOException(java.io.IOException) LocationsDefinition(net.runelite.cache.definitions.LocationsDefinition) FileInputStream(java.io.FileInputStream) InputStreamReader(java.io.InputStreamReader) FileNotFoundException(java.io.FileNotFoundException) MapDefinition(net.runelite.cache.definitions.MapDefinition) List(java.util.List) KitDefinition(net.runelite.cache.definitions.KitDefinition) DisplayMode(org.lwjgl.opengl.DisplayMode) GL_TEXTURE_MAG_FILTER(org.lwjgl.opengl.GL11.GL_TEXTURE_MAG_FILTER) NpcDefinition(net.runelite.cache.definitions.NpcDefinition) GL_CLAMP_TO_EDGE(org.lwjgl.opengl.GL12.GL_CLAMP_TO_EDGE) GL11.glTexParameteri(org.lwjgl.opengl.GL11.glTexParameteri) MapLoader(net.runelite.cache.definitions.loaders.MapLoader) ModelDefinition(net.runelite.cache.definitions.ModelDefinition) Options(org.apache.commons.cli.Options) NpcDefinition(net.runelite.cache.definitions.NpcDefinition) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) MapDefinition(net.runelite.cache.definitions.MapDefinition) KitDefinition(net.runelite.cache.definitions.KitDefinition) CommandLineParser(org.apache.commons.cli.CommandLineParser) LocationsDefinition(net.runelite.cache.definitions.LocationsDefinition) DefaultParser(org.apache.commons.cli.DefaultParser) InputStreamReader(java.io.InputStreamReader) ObjectDefinition(net.runelite.cache.definitions.ObjectDefinition) LocationsLoader(net.runelite.cache.definitions.loaders.LocationsLoader) FileInputStream(java.io.FileInputStream) DisplayMode(org.lwjgl.opengl.DisplayMode) CommandLine(org.apache.commons.cli.CommandLine) MapLoader(net.runelite.cache.definitions.loaders.MapLoader) ModelDefinition(net.runelite.cache.definitions.ModelDefinition) Region(net.runelite.cache.region.Region)

Example 8 with GL11.glDeleteTextures

use of org.lwjgl.opengl.GL11.glDeleteTextures in project LogisticsPipes by RS485.

the class OpenGLDebugger method updateNiceToHave.

private static void updateNiceToHave() {
    OpenGLDebugger.niceToHave = new HashMap<>();
    int crawlerVersion = 11;
    boolean almostEnd = false;
    boolean end = false;
    while (!end) {
        String packageGL = String.format("%s%d", "GL", crawlerVersion);
        String nextGL = String.format("%s.%s", "org.lwjgl.opengl", packageGL);
        try {
            crawlerVersion++;
            Class glClass = GL11.class.getClassLoader().loadClass(nextGL);
            com.google.common.reflect.Reflection.initialize(glClass);
            almostEnd = false;
            for (Field f : glClass.getDeclaredFields()) {
                try {
                    if (!f.getType().equals(int.class)) {
                        continue;
                    }
                    int id = f.getInt(null);
                    String nice = f.getName();
                    if (nice.endsWith("BIT")) {
                        continue;
                    }
                    // All the things that are being replaced are not that bad
                    if (OpenGLDebugger.niceToHave.containsKey(id) && !OpenGLDebugger.niceToHave.get(id).equals(nice)) {
                        System.out.printf("NiceToHave: ID %d exists. Replacing %s with %s!!%n", id, OpenGLDebugger.niceToHave.remove(id), nice);
                    }
                    OpenGLDebugger.niceToHave.put(id, String.format("%s.%s", packageGL, nice));
                } catch (IllegalArgumentException e) {
                    System.out.printf("NiceToHave: Illegal Argument!%nNiceToHave: %s%n", e);
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    System.out.printf("NiceToHave: Illegal Access!%nNiceToHave: %s%n", e);
                    e.printStackTrace();
                }
            }
        } catch (ClassNotFoundException e) {
            if (almostEnd) {
                end = true;
            } else {
                almostEnd = true;
                crawlerVersion = (crawlerVersion / 10 + 1) * 10;
            }
        }
    }
}
Also used : JTextField(javax.swing.JTextField) Field(java.lang.reflect.Field) GL11(org.lwjgl.opengl.GL11)

Aggregations

GL11 (org.lwjgl.opengl.GL11)7 List (java.util.List)5 IOException (java.io.IOException)4 ByteBuffer (java.nio.ByteBuffer)3 ArrayList (java.util.ArrayList)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 FloatBuffer (java.nio.FloatBuffer)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Collectors (java.util.stream.Collectors)2 GlStateManager (net.minecraft.client.renderer.GlStateManager)2 DefaultVertexFormats (net.minecraft.client.renderer.vertex.DefaultVertexFormats)2 ItemStack (net.minecraft.item.ItemStack)2 BufferUtils (org.lwjgl.BufferUtils)2 TileQuarry (buildcraft.builders.tile.TileQuarry)1 BCCoreItems (buildcraft.core.BCCoreItems)1 ItemPaintbrush_BC8 (buildcraft.core.item.ItemPaintbrush_BC8)1 ChunkLoaderManager (buildcraft.lib.chunkload.ChunkLoaderManager)1 DetachedRenderer (buildcraft.lib.client.render.DetachedRenderer)1