Example usage for org.lwjgl.opengl GL11 GL_NEAREST

List of usage examples for org.lwjgl.opengl GL11 GL_NEAREST

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL11 GL_NEAREST.

Prototype

int GL_NEAREST

To view the source code for org.lwjgl.opengl GL11 GL_NEAREST.

Click Source Link

Document

TextureMagFilter

Usage

From source file:itdelatrisu.opsu.render.Rendertarget.java

License:Open Source License

/**
 * Creates a Rendertarget with a Texture that it renders the color buffer in
 * and a renderbuffer that it renders the depth to.
 * @param width the width//from   w w w .j  a v  a2  s .co m
 * @param height the height
*/
public static Rendertarget createRTTFramebuffer(int width, int height) {
    int old_framebuffer = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT);
    int old_texture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
    Rendertarget buffer = new Rendertarget(width, height);
    buffer.bind();

    int fboTexture = buffer.textureID;
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, fboTexture);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, 4, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_INT,
            (ByteBuffer) null);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);

    EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, buffer.depthBufferID);
    EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT,
            GL11.GL_DEPTH_COMPONENT, width, height);
    EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
            EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT,
            buffer.depthBufferID);

    EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
            EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, fboTexture, 0);

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, old_texture);
    EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, old_framebuffer);

    return buffer;
}

From source file:itemrender.client.rendering.FBOHelper.java

License:MIT License

private void createFramebuffer() {
    framebufferID = EXTFramebufferObject.glGenFramebuffersEXT();
    textureID = GL11.glGenTextures();//from  w  w  w. j  a v  a 2s . co m
    int currentFramebuffer = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT);
    int currentTexture = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);

    EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, framebufferID);

    // Set our texture up, empty.
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, renderTextureSize, renderTextureSize, 0,
            GL12.GL_BGRA, GL11.GL_UNSIGNED_BYTE, (java.nio.ByteBuffer) null);

    // Restore old texture
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, currentTexture);

    // Create depth buffer
    depthbufferID = EXTFramebufferObject.glGenRenderbuffersEXT();
    EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT, depthbufferID);
    EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT,
            GL11.GL_DEPTH_COMPONENT, renderTextureSize, renderTextureSize);

    // Bind depth buffer to the framebuffer
    EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
            EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT,
            depthbufferID);

    // Bind our texture to the framebuffer
    EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
            EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, textureID, 0);

    // Revert to default framebuffer
    EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, currentFramebuffer);
}

From source file:ivengine.Util.java

License:Creative Commons License

/**
 * Loads a texture from a URL <filename> into a texture unit <textureUnit>
 *//* w  ww  .  j av a  2  s.c o  m*/
public static int loadPNGTexture(URL filename, int textureUnit) {
    ByteBuffer buf = null;
    int tWidth = 0;
    int tHeight = 0;

    try {
        // Open the PNG file as an InputStream
        InputStream in = filename.openStream();
        // Link the PNG decoder to this stream
        PNGDecoder decoder = new PNGDecoder(in);

        // Get the width and height of the texture
        tWidth = decoder.getWidth();
        tHeight = decoder.getHeight();

        // Decode the PNG file in a ByteBuffer
        buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
        decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA);
        buf.flip();

        in.close();
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(-1);
    }

    // Create a new texture object in memory and bind it
    int texId = GL11.glGenTextures();
    GL13.glActiveTexture(textureUnit);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);

    // All RGB bytes are aligned to each other and each component is 1 byte
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);

    // Upload the texture data and generate mip maps (for scaling)
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, tWidth, tHeight, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, buf);
    //GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);

    // Setup the ST coordinate system
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);

    // Setup what to do when the texture has to be scaled
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);

    return texId;
}

From source file:jplatformer.core.JBlock.java

License:Open Source License

public void render(int x, int y, boolean front) {
    if (texture != null) {
        if (texture.equals("none")) {
            texture = null;/*from   www.  j ava2s. c  o  m*/
            return;
        }
        if (i == null) {
            System.out.println(texture);
            System.out.println(JTextureManager.getTexture(texture));
            i = new Image(JTextureManager.getTexture(texture));
            i.setFilter(GL11.GL_NEAREST);
        }
        if (front) {
            i.setImageColor(1, 1, 1);
        } else {
            i.setImageColor(0.5f, 0.5f, 0.5f);
        }
        i.draw(x - 32, y - 32, 64, 64);
    } else {
    }
}

From source file:kuake2.render.lwjgl.Draw.java

License:Open Source License

void Draw_InitLocal() {
    // load console characters (don't bilerp characters)
    draw_chars = GL_FindImage("pics/conchars.pcx", it_pic);
    GL_Bind(draw_chars.texnum);//from  w  ww. j a  va2  s .c  o m
    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
}

From source file:kubex.KubexGame.java

License:Creative Commons License

/**
 * Inits the game resources (Images, pools, shaders, objects, etc.)
 *///from   w  w w .  j ava2 s . c om
private void initResources() throws IOException {
    //Inits static pools
    FloatBufferPool.init(Chunk.CHUNK_DIMENSION * Chunk.CHUNK_DIMENSION * Chunk.CHUNK_DIMENSION * 2 * 6 * 6, 20);
    ByteArrayPool.init(Chunk.CHUNK_DIMENSION,
            (settings.RENDER_DISTANCE * 2 + 1) * World.HEIGHT * (settings.RENDER_DISTANCE * 2 + 1) * 2);
    glEnable(GL11.GL_CULL_FACE);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL11.GL_BLEND);
    glClearColor(0.6f, 0.8f, 1.0f, 0f);

    //Inits shaders
    GL20.glUseProgram(0);
    textManager = new GlobalTextManager();
    this.DVSP = new DepthVoxelShaderProgram(true);
    this.VSP = new TerrainVoxelShaderProgram(true);
    this.HSP = new HudShaderProgram(true);
    this.DTSP = this.settings.SHADOWS_ENABLED ? new DeferredTerrainShaderProgram(true)
            : new DeferredTerrainUnshadowShaderProgram(true);
    this.DRSP = this.settings.REFLECTIONS_ENABLED ? new DeferredReflectionsShaderProgram(true)
            : new DeferredNoReflectionsShaderProgram(true);
    this.DUTSP = this.settings.SHADOWS_ENABLED ? new DeferredUnderwaterTerrainShaderProgram(true)
            : new DeferredUnderwaterUnshadowTerrainShaderProgram(true);
    this.DUFSP = new DeferredUnderwaterFinalShaderProgram(true);

    //Inits essential objects
    this.TM = new TimeManager();
    this.cam = new Camera(CAMERA_NEAR, CAMERA_FAR, 80f, (float) (X_RES * 3 / 4) / Y_RES); //FOV more width than height BY DESIGN, so blocks looks more "plane". Looks nicer that way, i think.
    this.camInvProjEnv = new CameraInverseProjEnvelope(this.cam);
    this.shadowsManager = new ShadowsManager(SHADOW_SPLITS, this.cam);
    this.liquidRenderer = new DepthPeelingLiquidRenderer(LIQUID_LAYERS);

    this.sunCam = new Camera(new Matrix4f());
    this.sunCam.moveTo(0, 5, 0);
    this.sunCam.setPitch(0);

    this.sky = new Sky(cam, this.sunCam);
    File mapRoute = new File(this.settings.MAP_ROUTE);
    mapRoute.mkdir(); //Creates the maps folder
    this.fileManager = new FileManager(mapRoute, settings.RENDER_DISTANCE);
    this.fileManager.getSettingsFromFile(settings); //Reads default settings from settings file.
    this.world = new World(this.VSP, this.cam, this.sunCam, this.shadowsManager, this.sky, fileManager,
            this.settings);
    this.finalDrawManager = new FinalDrawManager(this.world, this.sky, this.shadowsManager, this.liquidRenderer,
            this.camInvProjEnv.getInvProjMatrix(), CAMERA_NEAR, CAMERA_FAR);
    this.hud = new Hud(this.HSP, X_RES, Y_RES);

    //Load textures here
    glActiveTexture(TEXTURE_FETCH[TILES_TEXTURE_LOCATION]);

    //GL_NEAREST for that blocky look
    //loads the tiles textures into a array
    tilesTexture = Util.loadTextureAtlasIntoTextureArray(FileLoader.loadTileImages(), GL11.GL_NEAREST,
            GL11.GL_NEAREST_MIPMAP_LINEAR, true, settings.ANISOTROPIC_FILTERING_ENABLED);

    Util.loadPNGTexture(FileLoader.loadWaterNormalImage(), TEXTURE_FETCH[WATER_NORMAL_TEXTURE_LOCATION]); //loads the water normal texture

    glActiveTexture(GL_TEXTURE0);
    nightDomeTexture = TextureLoader.getTexture("JPG",
            ResourceLoader.getResourceAsStream("images/nightdome.jpg")); //loads the nightdome

    //Without this, text printing using Slick-Utils doesn't work. Seems it still uses some old mode OpenGL.
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_LIGHTING);
    GL11.glClearDepth(1);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glViewport(0, 0, X_RES, Y_RES);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, X_RES, Y_RES, 0, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    //First pass deferred rendering
    this.baseFbo = glGenFramebuffers();
    glBindFramebuffer(GL_FRAMEBUFFER, this.baseFbo);

    int colorTexture = glGenTextures();
    int brightnessNormalsTexture = glGenTextures();

    //Creates and inits the base color texture as a RGB texture
    glActiveTexture(TEXTURE_FETCH[BASEFBO_COLOR_TEXTURE_LOCATION]);
    glBindTexture(GL_TEXTURE_2D, colorTexture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, X_RES, Y_RES, 0, GL_RGB, GL_UNSIGNED_BYTE, (FloatBuffer) null);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    GL30.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTexture, 0);

    //Creates and inits the brightness and normals texture as a RGBA texture
    glActiveTexture(TEXTURE_FETCH[BASEFBO_NORMALS_BRIGHTNESS_TEXTURE_LOCATION]);
    glBindTexture(GL_TEXTURE_2D, brightnessNormalsTexture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL11.GL_RGBA, X_RES, Y_RES, 0, GL11.GL_RGBA, GL_UNSIGNED_BYTE,
            (FloatBuffer) null);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    GL30.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, brightnessNormalsTexture,
            0);

    //The depth buffer of this FBO will be a texture, too. This will make depth sorting slower but we will be able to access depth values later.
    int baseFboDepth = glGenTextures();

    glActiveTexture(TEXTURE_FETCH[BASEFBO_DEPTH_TEXTURE_LOCATION]);
    glBindTexture(GL_TEXTURE_2D, baseFboDepth);
    glTexImage2D(GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT24, X_RES, Y_RES, 0, GL_DEPTH_COMPONENT,
            GL_UNSIGNED_INT, (FloatBuffer) null);
    System.out.println("ERR" + GL11.glGetError());
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    GL30.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, baseFboDepth, 0); //Set the depth texture as the default render depth target

    IntBuffer drawBuffers = BufferUtils.createIntBuffer(2); //Drawing to 2 textures

    drawBuffers.put(GL_COLOR_ATTACHMENT0);
    drawBuffers.put(GL_COLOR_ATTACHMENT1);

    drawBuffers.flip();
    GL20.glDrawBuffers(drawBuffers);

    //Second pass deferred rendering
    this.deferredFbo = glGenFramebuffers();
    glBindFramebuffer(GL_FRAMEBUFFER, this.deferredFbo);

    int deferredColorTex = glGenTextures();

    //Only uses one texture, a RGBA color texture
    glActiveTexture(TEXTURE_FETCH[DEFERREDFBO_COLOR_TEXTURE_LOCATION]);
    glBindTexture(GL_TEXTURE_2D, deferredColorTex);
    glTexImage2D(GL_TEXTURE_2D, 0, GL11.GL_RGBA, X_RES, Y_RES, 0, GL11.GL_RGBA, GL_UNSIGNED_BYTE,
            (FloatBuffer) null);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    GL30.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, deferredColorTex, 0);

    drawBuffers = BufferUtils.createIntBuffer(1);

    drawBuffers.put(GL_COLOR_ATTACHMENT0);

    drawBuffers.flip();
    GL20.glDrawBuffers(drawBuffers);

    //If shadows are enabled, we init each shadow map texture, placed in an array
    if (this.settings.SHADOWS_ENABLED) {

        int shadowTexture = glGenTextures();

        glActiveTexture(TEXTURE_FETCH[SHADOW_TEXTURE_LOCATION]);

        glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, shadowTexture);
        //Creates a texture array to place the shadows in
        GL12.glTexImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, GL14.GL_DEPTH_COMPONENT16, SHADOW_XRES, SHADOW_YRES,
                this.shadowsManager.getNumberSplits(), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT,
                (FloatBuffer) null);
        System.out.println("ERR" + GL11.glGetError());
        glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); //Needed to do hardware PCF comparisons via shader
        glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); //Needed to do hardware PCF comparisons via shader
        glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL14.GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); //Needed to do hardware PCF comparisons via shader

        this.shadowFbos = new int[this.shadowsManager.getNumberSplits()];
        //Creates one framebuffer per shadow map
        for (int i = 0; i < this.shadowsManager.getNumberSplits(); i++) {
            this.shadowFbos[i] = glGenFramebuffers();
            glBindFramebuffer(GL_FRAMEBUFFER, this.shadowFbos[i]);
            GL30.glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, shadowTexture, 0, i); //Each framebuffer will have one texture layer (one index of the texture array created before) assigned as render target

            drawBuffers = BufferUtils.createIntBuffer(0);

            GL20.glDrawBuffers(drawBuffers);

        }
    }

    //Liquid layers depth generation. Equal to the shadows depth textures generation.
    int liquidLayers = glGenTextures();

    glActiveTexture(TEXTURE_FETCH[LIQUIDLAYERS_TEXTURE_LOCATION]);
    glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, liquidLayers);
    GL12.glTexImage3D(GL30.GL_TEXTURE_2D_ARRAY, 0, GL14.GL_DEPTH_COMPONENT24, X_RES, Y_RES,
            this.liquidRenderer.getNumLayers(), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, (FloatBuffer) null);

    glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); //We will compare manually the depth in the shader, we will not perform PCF of any sort in this case
    glTexParameteri(GL30.GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);

    int currentLiquidNormalTex = glGenTextures();

    glActiveTexture(KubexGame.TEXTURE_FETCH[KubexGame.CURRENT_LIQUID_NORMAL_TEXTURE_LOCATION]);
    glBindTexture(GL_TEXTURE_2D, currentLiquidNormalTex);
    glTexImage2D(GL_TEXTURE_2D, 0, GL11.GL_RGB, X_RES, Y_RES, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE,
            (FloatBuffer) null);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

    this.liquidRenderer.initResources(liquidLayers, currentLiquidNormalTex);

    //Reset active texture and fbo to the default
    glActiveTexture(GL13.GL_TEXTURE0);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
}

From source file:mwisbest.openbase.opengl.TextureLoader.java

License:Open Source License

/**
 * Get a texture from a image file/*  w  w w.j  a  va 2  s . co m*/
 * 
 * @param in The stream from which we can load the image
 * @param resourceName The name to give this image in the internal cache
 * @param flipped True if we should flip the image on the y-axis while loading
 * @param filter The filter to use when scaling the texture
 * @param transparent The colour to interpret as transparent or null if none
 * @return The texture loaded
 * @throws IOException Indicates a failure to load the image
 */
public TextureImplementation getTexture(InputStream in, String resourceName, boolean flipped, int filter,
        int[] transparent) throws IOException {
    HashMap<String, Object> hash = this.texturesLinear;
    if (filter == GL11.GL_NEAREST)
        hash = this.texturesNearest;

    String resName = resourceName;
    if (transparent != null)
        resName += ":" + transparent[0] + ":" + transparent[1] + ":" + transparent[2];
    resName += ":" + flipped;

    @SuppressWarnings("unchecked")
    SoftReference<TextureImplementation> ref = (SoftReference<TextureImplementation>) hash.get(resName);
    if (ref != null) {
        TextureImplementation tex = ref.get();
        if (tex != null)
            return tex;
        hash.remove(resName);
    }

    // horrible test until I can find something more suitable
    try {
        GL11.glGetError();
    } catch (NullPointerException e) {
        throw new RuntimeException(
                "Image based resources must be loaded as part of init() or the game loop. They cannot be loaded before initialisation.");
    }

    TextureImplementation tex = this.getTexture(in, resourceName, GL11.GL_TEXTURE_2D, filter, filter, flipped,
            transparent);

    hash.put(resName, new SoftReference<>(tex));

    return tex;
}

From source file:mwisbest.openbase.opengl.TextureLoader.java

License:Open Source License

/**
 * Create an empty texture//from   w ww. j a  v  a2  s  . c o m
 * 
 * @param width The width of the new texture
 * @param height The height of the new texture
 * @return The created empty texture
 * @throws IOException Indicates a failure to create the texture on the graphics hardware
 */
public Texture createTexture(final int width, final int height) throws IOException {
    return this.createTexture(width, height, GL11.GL_NEAREST);
}

From source file:myfirstgame.Window.java

public void init(int width, int height) {

    Window.width = width;/*from  w ww.j  a  v  a  2s . c  om*/
    Window.height = height;

    try { //Look for a displaymode with matching width and height that supports fullscreen, set it to the displaymode we want to use.
        DisplayMode displayMode = null;
        DisplayMode[] modes = Display.getAvailableDisplayModes();

        for (int i = 0; i < modes.length; i++) {
            if (modes[i].getWidth() == width && modes[i].getHeight() == height
                    && modes[i].isFullscreenCapable()) {
                displayMode = modes[i];
            }
        }
        Display.setDisplayMode(displayMode);
        Display.setFullscreen(true);
        Display.create();

    } catch (Exception e) {
        e.printStackTrace();
        System.exit(0);
    }

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, 800, 0, 600, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);

    try {
        Mouse.create();
        Keyboard.create();
    } catch (LWJGLException ex) {
        Logger.getLogger(Window.class.getName()).log(Level.SEVERE, null, ex);
    }
    //Mouse.setGrabbed(true);
}

From source file:name.martingeisse.stackd.client.system.StackdTexture.java

License:Open Source License

/**
 * Constructor.//from w  ww  . j a  va  2s  . com
 * @param anchorClass this class specifies the package to load from
 * @param filename the filename to load from
 * @param flipped whether to y-flip the texture
 */
public StackdTexture(final Class<?> anchorClass, final String filename, boolean flipped) {
    String resourceName = anchorClass.getName() + '/' + filename;
    try (InputStream inputStream = anchorClass.getResourceAsStream(filename)) {
        if (inputStream == null) {
            throw new RuntimeException("file not found: " + filename);
        }
        // TODO slick generates mipmaps *before* it removes the key color pixels, so with GL_LINEAR they bleed into the neighbor pixels
        this.slickTexture = InternalTextureLoader.get().getTexture(inputStream, resourceName, flipped,
                GL11.GL_NEAREST, KEY_COLOR);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}