Example usage for org.lwjgl.opengl GL11 glEnable

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

Introduction

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

Prototype

public static void glEnable(@NativeType("GLenum") int target) 

Source Link

Document

Enables the specified OpenGL state.

Usage

From source file:com.opengrave.og.MainThread.java

License:Open Source License

public static void set2D() {
    GL11.glDisable(GL11.GL_CULL_FACE);//from  w  w  w  .  j a  v a  2 s . c o m
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glDepthFunc(GL11.GL_LEQUAL);

}

From source file:com.opengrave.og.MainThread.java

License:Open Source License

protected void initGL() {
    if (glfwInit() != GLFW_TRUE) {
        System.exit(1);//from  w w  w  .j av  a2  s . c o  m
    }
    glfwDefaultWindowHints();
    glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE);
    glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
    window = glfwCreateWindow(800, 600, "HiddenGrave", NULL, NULL);
    if (window == NULL) {
        System.exit(1);
    }
    glfwMakeContextCurrent(window);
    glfwSwapInterval(1); // TODO condig of vsync. Enable vsync
    GL.createCapabilities();
    glfwSetFramebufferSizeCallback(window, (framebufferSizeCallback = new GLFWFramebufferSizeCallback() {
        @Override
        public void invoke(long window, int width, int height) {
            onResize(width, height);
        }
    }));
    onResize(800, 600);
    // TODO Check all extensions. TEX 2D ARRAY, GLSL 130
    createConfig();

    Util.initMatrices();
    Renderable.init();
    GUIXML.init();

    // Prepare Lighting
    initLighting();
    // Default Values
    GL11.glClearColor(0.5f, 0.5f, 0.5f, 1.0f); // sets background to grey
    Util.checkErr();
    GL11.glClearDepth(1.0f); // clear depth buffer
    Util.checkErr();
    GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables depth testing
    Util.checkErr();
    GL11.glDepthFunc(GL11.GL_LEQUAL); // sets the type of test to use for
    // depth testing
    GL11.glEnable(GL11.GL_BLEND);
    Resources.loadTextures(); // Reconsider positioning. Other than GUI
    // texture we could offset these in another
    // thread... Possibly?
    Resources.loadModels();
    Resources.loadFonts();

}

From source file:com.owens.oobjloader.lwjgl.VBO.java

License:BSD License

public void render() {

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textId); // Bind The Texture

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, verticeAttributesID);

    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    GL11.glVertexPointer(3, GL11.GL_FLOAT, ATTR_V_STRIDE2_BYTES, ATTR_V_OFFSET_BYTES);

    GL11.glEnableClientState(GL11.GL_NORMAL_ARRAY);
    GL11.glNormalPointer(GL11.GL_FLOAT, ATTR_N_STRIDE2_BYTES, ATTR_N_OFFSET_BYTES);

    GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
    GL11.glTexCoordPointer(2, GL11.GL_FLOAT, ATTR_T_STRIDE2_BYTES, ATTR_T_OFFSET_BYTES);

    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesID);
    GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_INT, 0);

    GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
    GL11.glDisableClientState(GL11.GL_NORMAL_ARRAY);
    GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
    GL11.glDisable(GL11.GL_TEXTURE_2D);/*w  ww  .ja v a  2 s . co  m*/
}

From source file:com.owens.oobjloader.Main.java

License:BSD License

/**
 * Runs the program (the "main loop")/*from www  . j  av a2 s. c  om*/
 */
private static void run(String filename, String defaultTextureMaterial) {
    DisplayModel scene = null;

    scene = new DisplayModel();

    log.log(INFO, "Parsing WaveFront OBJ file");
    Build builder = new Build();
    Parse obj = null;
    try {
        obj = new Parse(builder, filename);
    } catch (java.io.FileNotFoundException e) {
        log.log(SEVERE, "Exception loading object!  e=" + e);
        e.printStackTrace();
    } catch (java.io.IOException e) {
        log.log(SEVERE, "Exception loading object!  e=" + e);
        e.printStackTrace();
    }
    log.log(INFO, "Done parsing WaveFront OBJ file");

    log.log(INFO, "Splitting OBJ file faces into list of faces per material");
    ArrayList<ArrayList<Face>> facesByTextureList = createFaceListsByMaterial(builder);
    log.log(INFO, "Done splitting OBJ file faces into list of faces per material, ended up with "
            + facesByTextureList.size() + " lists of faces.");

    TextureLoader textureLoader = new TextureLoader();
    int defaultTextureID = 0;
    if (defaultTextureMaterial != null) {
        log.log(INFO, "Loading default texture =" + defaultTextureMaterial);
        defaultTextureID = setUpDefaultTexture(textureLoader, defaultTextureMaterial);
        log.log(INFO, "Done loading default texture =" + defaultTextureMaterial);
    }
    if (defaultTextureID == -1) {
        BufferedImage img = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB);
        Graphics g = img.getGraphics();
        g.setColor(Color.BLUE);
        g.fillRect(0, 0, 256, 256);
        g.setColor(Color.RED);
        for (int loop = 0; loop < 256; loop++) {
            g.drawLine(loop, 0, loop, 255);
            g.drawLine(0, loop, 255, loop);
        }
        defaultTextureID = textureLoader.convertToTexture(img);
    }
    int currentTextureID = -1;
    for (ArrayList<Face> faceList : facesByTextureList) {
        if (faceList.isEmpty()) {
            log.log(INFO, "ERROR: got an empty face list.  That shouldn't be possible.");
            continue;
        }
        log.log(INFO, "Getting material " + faceList.get(0).material);
        currentTextureID = getMaterialID(faceList.get(0).material, defaultTextureID, builder, textureLoader);
        log.log(INFO, "Splitting any quads and throwing any faces with > 4 vertices.");
        ArrayList<Face> triangleList = splitQuads(faceList);
        log.log(INFO, "Calculating any missing vertex normals.");
        calcMissingVertexNormals(triangleList);
        log.log(INFO, "Ready to build VBO of " + triangleList.size() + " triangles");
        ;

        if (triangleList.size() <= 0) {
            continue;
        }
        log.log(INFO, "Building VBO");

        VBO vbo = VBOFactory.build(currentTextureID, triangleList);

        log.log(INFO, "Adding VBO with text id " + currentTextureID + ", with " + triangleList.size()
                + " triangles to scene.");
        scene.addVBO(vbo);
    }
    log.log(INFO, "Finally ready to draw things.");

    GL11.glEnable(GL11.GL_CULL_FACE);

    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glEnable(GL11.GL_LIGHT0);
    GL11.glEnable(GL11.GL_LIGHT1);

    float lightAmbient[] = { 1.0f, 1.0f, 1.0f, 1.0f };
    float lightDiffuse[] = { 0.5f, 0.5f, 1.0f, 1.0f };
    float lightSpecular[] = { 0.0f, 1.0f, 1.0f, 0.0f };

    GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, asFloatBuffer(lightAmbient));
    GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, asFloatBuffer(lightDiffuse));
    GL11.glLight(GL11.GL_LIGHT0, GL11.GL_SPECULAR, asFloatBuffer(lightSpecular));

    GL11.glLight(GL11.GL_LIGHT1, GL11.GL_AMBIENT, asFloatBuffer(lightAmbient));
    GL11.glLight(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, asFloatBuffer(lightDiffuse));
    GL11.glLight(GL11.GL_LIGHT1, GL11.GL_SPECULAR, asFloatBuffer(lightSpecular));

    float lightPosition0[] = { posix, posiy, posiz, 1.0f };
    GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, asFloatBuffer(lightPosition0));
    float lightPosition1[] = { posix, posiy, posizz, 1.0f };
    GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, asFloatBuffer(lightPosition1));

    while (!finished) {
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glLoadIdentity();

        GLU.gluLookAt(orix, oriy, oriz, cenx, ceny, cenz, 0, 1, 0);

        // rotate(based on camera)
        GL11.glRotatef(rotateSee, 0, 1, 0);
        GL11.glRotatef(rotateSeeAnother, 1, 0, 0);
        // transform
        GL11.glTranslated(0, -0.75, -2);
        // rotate(based on model)
        GL11.glRotatef(rotate, 0, 1, 0);
        GL11.glRotatef(rotateAnother, 1, 0, 0);

        // Always call Window.update(), all the time - it does some behind the
        // scenes work, and also displays the rendered output
        Display.update();

        // Check for close requests
        if (Display.isCloseRequested()) {
            finished = true;
        } // The window is in the foreground, so render!
        else if (Display.isActive()) {
            logic();
            GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
            scene.render();
            Display.sync(FRAMERATE);
        } // The window is not in the foreground, so we can allow other stuff to run and infrequently update
        else {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            }
            logic();

            // Only bother rendering if the window is visible or dirty
            if (Display.isVisible() || Display.isDirty()) {
                System.err.print(".");
                scene.render();
            }
        }
    }
}

From source file:com.pahimar.ee3.client.renderer.item.ItemAlchemyTableRenderer.java

License:LGPL

private void renderAlchemyTable(float x, float y, float z, float scale) {

    GL11.glPushMatrix();/*from  w w w.  j  a va2  s  . c o  m*/
    GL11.glDisable(GL11.GL_LIGHTING);

    // Scale, Translate, Rotate
    GL11.glScalef(scale, scale, scale);
    GL11.glTranslatef(x, y, z);
    GL11.glRotatef(-90F, 1F, 0, 0);

    // Bind texture
    FMLClientHandler.instance().getClient().renderEngine.bindTexture(Textures.MODEL_ALCHEMY_TABLE);

    // Render
    modelAlchemyTable.render();

    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glPopMatrix();
}

From source file:com.pahimar.ee3.client.renderer.item.ItemAludelRenderer.java

License:LGPL

private void renderAludel(float x, float y, float z, float scale) {

    GL11.glPushMatrix();//  w  ww  .j  ava  2 s  .com
    GL11.glDisable(GL11.GL_LIGHTING);

    // Scale, Translate, Rotate
    GL11.glScalef(scale, scale, scale);
    GL11.glTranslatef(x, y, z);
    GL11.glRotatef(-90F, 1F, 0, 0);

    // Bind texture
    FMLClientHandler.instance().getClient().renderEngine.bindTexture(Textures.MODEL_ALUDEL);

    // Render
    modelAludel.render();

    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glPopMatrix();
}

From source file:com.pahimar.ee3.client.renderer.item.ItemCalcinatorRenderer.java

License:LGPL

private void renderCalcinator(float x, float y, float z, float scale) {

    GL11.glPushMatrix();/* w ww  .j av a  2 s  .c  o  m*/
    GL11.glDisable(GL11.GL_LIGHTING);

    // Scale, Translate, Rotate
    GL11.glScalef(scale, scale, scale);
    GL11.glTranslatef(x, y, z);
    GL11.glRotatef(-90F, 1F, 0, 0);

    // Bind texture
    FMLClientHandler.instance().getClient().renderEngine.bindTexture(Textures.MODEL_CALCINATOR);

    // Render
    modelCalcinator.render();

    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glPopMatrix();
}

From source file:com.pahimar.ee3.client.renderer.item.ItemGlassBellRenderer.java

License:LGPL

private void renderGlassBell(float x, float y, float z, float scale) {

    GL11.glPushMatrix();/*  w  ww .  j ava 2s .c  o  m*/
    GL11.glDisable(GL11.GL_LIGHTING);

    // Scale, Translate, Rotate
    GL11.glScalef(scale, scale, scale);
    GL11.glTranslatef(x, y, z);
    GL11.glRotatef(-90F, 1F, 0, 0);

    // Bind texture
    FMLClientHandler.instance().getClient().renderEngine.bindTexture(Textures.MODEL_GLASS_BELL);

    // Render
    modelGlassBell.render();

    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glPopMatrix();
}

From source file:com.pahimar.ee3.client.renderer.RenderUtils.java

License:LGPL

public static void renderItemIntoGUI(FontRenderer fontRenderer, RenderEngine renderEngine, ItemStack itemStack,
        int x, int y, float opacity, float scale) {

    Icon icon = itemStack.getIconIndex();
    GL11.glDisable(GL11.GL_LIGHTING);// w  w w.j  a v  a2  s . c om
    renderEngine.bindTexture(Textures.VANILLA_ITEM_TEXTURE_SHEET);
    int overlayColour = itemStack.getItem().getColorFromItemStack(itemStack, 0);
    float red = (overlayColour >> 16 & 255) / 255.0F;
    float green = (overlayColour >> 8 & 255) / 255.0F;
    float blue = (overlayColour & 255) / 255.0F;
    GL11.glColor4f(red, green, blue, opacity);
    drawTexturedQuad(x, y, icon, 16 * scale, 16 * scale, -90);
    GL11.glEnable(GL11.GL_LIGHTING);

}

From source file:com.pahimar.ee3.client.renderer.tileentity.TileEntityAlchemicalChestRenderer.java

License:LGPL

@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float tick) {

    if (tileEntity instanceof TileAlchemicalChest) {

        TileAlchemicalChest tileAlchemicalChest = (TileAlchemicalChest) tileEntity;
        ForgeDirection direction = null;

        if (tileAlchemicalChest.getWorldObj() != null) {
            direction = ForgeDirection.getOrientation(tileAlchemicalChest.getBlockMetadata());
        }/*w ww . j a v a  2 s.co  m*/

        FMLClientHandler.instance().getClient().renderEngine.bindTexture(Textures.MODEL_ALCHEMICAL_CHEST);
        GL11.glPushMatrix();
        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        GL11.glTranslatef((float) x, (float) y + 1.0F, (float) z + 1.0F);
        GL11.glScalef(1.0F, -1.0F, -1.0F);
        GL11.glTranslatef(0.5F, 0.5F, 0.5F);
        short angle = 0;

        if (direction != null) {
            if (direction == ForgeDirection.NORTH) {
                angle = 180;
            } else if (direction == ForgeDirection.SOUTH) {
                angle = 0;
            } else if (direction == ForgeDirection.WEST) {
                angle = 90;
            } else if (direction == ForgeDirection.EAST) {
                angle = -90;
            }
        }

        GL11.glRotatef(angle, 0.0F, 1.0F, 0.0F);
        GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
        float adjustedLidAngle = tileAlchemicalChest.prevLidAngle
                + (tileAlchemicalChest.lidAngle - tileAlchemicalChest.prevLidAngle) * tick;
        adjustedLidAngle = 1.0F - adjustedLidAngle;
        adjustedLidAngle = 1.0F - adjustedLidAngle * adjustedLidAngle * adjustedLidAngle;
        modelChest.chestLid.rotateAngleX = -(adjustedLidAngle * (float) Math.PI / 2.0F);
        modelChest.renderAll();
        GL11.glDisable(GL12.GL_RESCALE_NORMAL);
        GL11.glPopMatrix();
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    }
}