Example usage for org.lwjgl.opengl GL11 glPolygonMode

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

Introduction

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

Prototype

public static void glPolygonMode(@NativeType("GLenum") int face, @NativeType("GLenum") int mode) 

Source Link

Document

Controls the interpretation of polygons for rasterization.

Usage

From source file:fr.ign.cogit.geoxygene.appli.render.DisplayableTextRenderer.java

License:Open Source License

private void drawText() throws GLException {
    if (this.program == null || this.textImage == null) {
        Logger.getRootLogger().debug("The GeoxGLTextRenderer " + this.hashCode() + "is not ready yet");
        return;//from   w ww . j a va 2 s . c o  m
    }
    this.textImage.getRGB(0, 0, width, height, this.pixels, 0, width);
    this.buffer.rewind();
    for (int y = height - 1; y >= 0; y--) {
        for (int x = 0; x < width; x++) {
            int pixel = this.pixels[y * width + x];
            this.buffer.put((byte) (pixel >> 16 & 0xFF)); // Red component
            this.buffer.put((byte) (pixel >> 8 & 0xFF)); // Green component
            this.buffer.put((byte) (pixel >> 0 & 0xFF)); // Blue component
            this.buffer.put((byte) (pixel >> 24 & 0xFF)); // Alpha component
        }
    }
    this.buffer.rewind();
    glEnable(GL_TEXTURE_2D);
    GL13.glActiveTexture(GL13.GL_TEXTURE0 + 2);
    glBindTexture(GL_TEXTURE_2D, this.getTextTextureId());

    // Setup texture scaling filtering
    GL11.glTexParameteri(GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    GL11.glTexImage2D(GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE,
            this.buffer);

    Integer fbow = (Integer) GLContext.getActiveGlContext()
            .getSharedUniform(GeoxygeneConstants.GL_VarName_FboWidth);
    Integer fboh = (Integer) GLContext.getActiveGlContext()
            .getSharedUniform(GeoxygeneConstants.GL_VarName_FboHeight);
    GL11.glViewport(0, 0, fbow, fboh);
    glDisable(GL11.GL_POLYGON_SMOOTH);
    GLContext.getActiveGlContext().setCurrentProgram(program);
    program.setUniform1i("colorTexture2", 2);
    GLTools.glCheckError("texture binding");

    GL11.glDepthMask(false);
    glDisable(GL11.GL_DEPTH_TEST);

    GL30.glBindVertexArray(LayerViewGLPanel.getScreenQuad().getVaoId());
    GLTools.glCheckError("before drawing textured quad VAO binding");

    program.setUniform(GeoxygeneConstants.GL_VarName_ObjectOpacityVarName, 1f);
    program.setUniform(GeoxygeneConstants.GL_VarName_GlobalOpacityVarName, 1f);
    glEnable(GL_BLEND);
    GL11.glBlendFunc(GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
    GLTools.glCheckError("blending set for textured quad");

    LwjglLayerRenderer.drawComplex(LayerViewGLPanel.getScreenQuad());
    GLTools.glCheckError("Drawing textured quad");

    GL30.glBindVertexArray(0); // unbind VAO
    GLTools.glCheckError("exiting Text rendering");
    glBindTexture(GL_TEXTURE_2D, 0); // unbind texture

}

From source file:fr.ign.cogit.geoxygene.appli.render.LwjglLayerRenderer.java

License:Open Source License

/**
 * Draw the Rendered FBO into the Ping Pong FBO
 * // www  . j a v  a 2 s . c  om
 * @throws GLException
 */
private void drawInPingPongFBO() throws GLException {
    if (this.current_symbolizer == null) {
        logger.error("The current symbolizer is NULL");
        return;
    }
    // Get the blending mode of this symbolizer and the filter of the
    // current Layer.
    BlendingMode bmode = this.current_symbolizer.getBlendingMode();
    if (bmode == null) {
        bmode = GeoxygeneConstants.GL_VarName_DefaultBlendingMode;
    }

    LayerFilter layerfilter = ((AbstractLayer) this.getLayer()).getFilter();
    if (layerfilter == null)
        layerfilter = new LayerFilterIdentity();
    String program_name = "GLProgram-"
            + (bmode.toString() + "-" + layerfilter.getClass().getSimpleName()).toLowerCase();
    GLProgram p = GLContext.getActiveGlContext().getProgram(program_name);
    if (p == null) {
        GLProgramBuilder builder = new GLProgramBuilder();
        builder.addDelegateBuilder(new BlendingModeGLProgramBuilder(bmode, layerfilter));
        p = builder.build(program_name, null);
        if (p == null) {
            logger.warn("Failed to create the blending program " + bmode);
            logger.warn("Fallback to the default blending program "
                    + GeoxygeneConstants.GL_VarName_DefaultBlendingMode);
            bmode = GeoxygeneConstants.GL_VarName_DefaultBlendingMode;
            p = builder.build("GLProgram-"
                    + (bmode.toString() + "-" + LayerFilterIdentity.class.getSimpleName()).toLowerCase(), null);
        }
        if (p == null) {
            logger.fatal("Failed to create the blending program " + bmode + ". Exiting the rendering.");
            return;
        }
        GLContext.getActiveGlContext().addProgram(p);
    }
    GLContext.getActiveGlContext().setCurrentProgram(p);
    this.getLayerViewPanel().getGLCanvas().drawInPingPong(p);

    GL30.glBindVertexArray(LayerViewGLPanel.getScreenQuad().getVaoId());

    p.setUniform(GeoxygeneConstants.GL_VarName_ObjectOpacityVarName, 1f);
    p.setUniform(GeoxygeneConstants.GL_VarName_GlobalOpacityVarName, 1f);
    GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);

    GLTools.glCheckError("before FBO drawing textured quad");
    LwjglLayerRenderer.drawComplex(LayerViewGLPanel.getScreenQuad());
    GLTools.glCheckError("FBO drawing textured quad");
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
    GL30.glBindVertexArray(0); // unbind VAO
    GLTools.glCheckError("exiting FBO rendering");
    glBindTexture(GL_TEXTURE_2D, 0); // unbind texture
}

From source file:fr.ign.cogit.geoxygene.appli.render.primitive.LinePrimitiveRenderer.java

License:Open Source License

/**
 * Render simple line./* www .  ja  va  2  s  .  c  o  m*/
 * @param primitive primitive to paint
 */
private void renderLine(final ParameterizedPolyline line) {
    if (line.getPointCount() < 2) {
        logger.warn("Line has " + line.getPointCount() + " points and cannot be rendered");
        return;
    }
    this.texture.initializeRendering();
    this.texture.setRange(0., 0, line.getParameter(line.getPointCount() - 1), 1);
    //    System.err.println("set range to " + this.texture.getMinX() + "x" + this.texture.getMinY() + " - " + this.texture.getMaxX() + "x"
    //        + this.texture.getMaxY());
    /**
     * p1 is the nth point, n1 the segment normal at p1 point 
     * p2 is the (n+1)th point, n2 the segment normal at p2 point
     * 
     * pXa, pXb are the 
     */
    Point2d p1 = line.getPoint(0); // nth point
    double p1t = line.getParameter(0);
    Point2d p2 = line.getPoint(1); // n+1 th point
    double p2t = line.getParameter(1);
    Point2d p3 = null; // n+2 th point
    Vector2d v1 = MathUtil.vector(p1, p2); // line direction at p1
    Vector2d v2 = null; // line direction at p2 
    Vector2d n1 = MathUtil.computeNormal(v1); // line normal at p1 (perpendicular to segment direction)
    Vector2d n2 = null; // line normal at p2 (perpendicular to segment direction)
    Point2d p1a = MathUtil.pointOfLine(p1, n1, -this.getLineWidth() / 2); // first stretched point at p1 (p1 + lineWidth/2 * n1)
    Point2d p1b = MathUtil.pointOfLine(p1, n1, this.getLineWidth() / 2); // second stretched point at p1 (p1 - lineWidth/2 * n1)
    Point2d p2a = null; // first stretched point at p2 (p2 + lineWidth/2 * n2)
    Point2d p2b = null; // second stretched point at p2 (p2 - lineWidth/2 * n2)

    if (line.getPointCount() <= 2) {
        p3 = p2;
        n2 = n1;
    }

    GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
    GL11.glBegin(GL11.GL_QUAD_STRIP);
    try {
        GL11.glTexCoord2d(p1t, 0);
        GLTools.glTexCoord(this.texture.vertexCoordinates(p1t, 0));
        GL11.glVertex2d(p1a.x, p1a.y);
        GLTools.glTexCoord(this.texture.vertexCoordinates(p1t, 1));
        GL11.glVertex2d(p1b.x, p1b.y);
        //      System.err.println("set first point coordinates = " + p1t + "x" + "0" + " => " + this.texture.vertexCoordinates(p1t, 0));
        //      System.err.println("set first point coordinates = " + p1t + "x" + "1" + " => " + this.texture.vertexCoordinates(p1t, 1));

        for (int nPoint = 0; nPoint < line.getPointCount() - 2; nPoint++) {

            p3 = line.getPoint(nPoint + 2);
            v2 = MathUtil.vector(p2, p3);
            n2 = MathUtil.computeNormal(v2);
            p2a = MathUtil.pointOfLine(p2, n2, -this.getLineWidth() / 2);
            p2b = MathUtil.pointOfLine(p2, n2, this.getLineWidth() / 2);
            p2t = line.getParameter(nPoint);

            Point2d Ia = MathUtil.intersectionPoint(p1a, v1, p2a, v2);
            Point2d Ib = MathUtil.intersectionPoint(p1b, v1, p2b, v2);
            if (Ia == null || Ib == null) {
                Ia = MathUtil.mean(p1a, p2a);
                Ib = MathUtil.mean(p1b, p2b);
            }

            GLTools.glTexCoord(this.texture.vertexCoordinates(p2t, 0));
            GL11.glVertex2d(Ia.x, Ia.y);
            GLTools.glTexCoord(this.texture.vertexCoordinates(p2t, 1));
            GL11.glVertex2d(Ib.x, Ib.y);

            //        System.err.println("set #" + nPoint + " point coordinates = " + p2t + "x" + "0" + " => " + this.texture.vertexCoordinates(p2t, 0));
            //        System.err.println("set #" + nPoint + " point coordinates = " + p2t + "x" + "1" + " => " + this.texture.vertexCoordinates(p2t, 1));
            // shift context to the next point
            p1 = p2;
            p1t = p2t;
            n1 = n2;
            v1 = v2;
            p1a = Ia;
            p1b = Ib;
            p2 = p3;

        }
        // draw the last point
        Point2d p3a = MathUtil.pointOfLine(p3, n2, -this.getLineWidth() / 2);
        Point2d p3b = MathUtil.pointOfLine(p3, n2, this.getLineWidth() / 2);
        double p3t = line.getParameter(line.getPointCount() - 1);
        GLTools.glTexCoord(this.texture.vertexCoordinates(p3t, 0));
        GL11.glVertex2d(p3a.x, p3a.y);
        GLTools.glTexCoord(this.texture.vertexCoordinates(p3t, 1));
        GL11.glVertex2d(p3b.x, p3b.y);
        //      System.err.println("set last point coordinates = " + p3t + "x" + "0" + " => " + this.texture.vertexCoordinates(p3t, 0));
        //      System.err.println("set last point coordinates = " + p3t + "x" + "1" + " => " + this.texture.vertexCoordinates(p3t, 1));
    } finally {
        GL11.glEnd();
    }

    this.texture.initializeRendering();

}

From source file:hud.ManagerOverlay.java

License:Open Source License

public void draw() {
    GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_LINE);
    GL11.glColor4f(0.0f, 0.0f, 0.4f, 1.0f);
    GL11.glLineWidth(2.0f);/*ww  w.java 2  s  . c o  m*/
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2i(x, y);
    GL11.glVertex2i(x, y + height);
    GL11.glVertex2i(x + width, y + height);
    GL11.glVertex2i(x + width, y);
    GL11.glEnd();

    GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL);
    GL11.glColor4f(0.0f, 0.5f, 1.0f, 0.5f);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2i(x, y);
    GL11.glVertex2i(x, y + height);
    GL11.glVertex2i(x + width, y + height);
    GL11.glVertex2i(x + width, y);
    GL11.glEnd();
    GL11.glDisable(GL11.GL_BLEND);

    drawSelectionArrow(selectableWidgets[curWidget]);

    GL11.glPushMatrix();
    GL11.glTranslatef(x, y, 0);
    unitDisplay.draw();
    ordersDisplay.draw();
    mapDisplay.draw();
    GL11.glPopMatrix();

}

From source file:hud.ManagerOverlay.java

License:Open Source License

private void drawSelectionArrow(HZWidget selected) {

    int x = selected.getX() - 16;
    int y = selected.getY() + selected.height / 2;

    GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_LINE);
    GL11.glColor4f(0.0f, 0.0f, 0.4f, 1.0f);
    GL11.glLineWidth(2.0f);/* w ww . j  a v a 2 s .  c  o  m*/
    GL11.glBegin(GL11.GL_TRIANGLES);
    GL11.glVertex2i(x, y);
    GL11.glVertex2i(x - 16, y - 32);
    GL11.glVertex2i(x - 16, y + 32);
    GL11.glEnd();

    GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL);
    GL11.glColor4f(0.0f, 0.5f, 1.0f, 0.5f);
    GL11.glBegin(GL11.GL_TRIANGLES);
    GL11.glVertex2i(x, y);
    GL11.glVertex2i(x - 16, y - 32);
    GL11.glVertex2i(x - 16, y + 32);
    GL11.glEnd();
}

From source file:hud.MapDisplay.java

License:Open Source License

public void draw() {
    GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_LINE);
    GL11.glColor4f(0.0f, 0.0f, 0.4f, 1.0f);
    GL11.glLineWidth(2.0f);/*w w w  . j ava  2 s. com*/
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2i(x, y);
    GL11.glVertex2i(x, y + height);
    GL11.glVertex2i(x + width, y + height);
    GL11.glVertex2i(x + width, y);
    GL11.glEnd();

    GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL);
    game.getMap().getMinimap().bind();
    GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(0, 0);
    GL11.glVertex2i(x, y);
    GL11.glTexCoord2f(0, 1);
    GL11.glVertex2i(x, y + height);
    GL11.glTexCoord2f(1, 1);
    GL11.glVertex2i(x + width, y + height);
    GL11.glTexCoord2f(1, 0);
    GL11.glVertex2i(x + width, y);
    GL11.glEnd();
}

From source file:hud.OrdersDisplay.java

License:Open Source License

public void draw() {
    GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_LINE);
    GL11.glColor4f(0.0f, 0.0f, 0.4f, 1.0f);
    GL11.glLineWidth(2.0f);//  w  w  w  .  ja  v  a 2  s. co m
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2i(x, y);
    GL11.glVertex2i(x, y + height);
    GL11.glVertex2i(x + width, y + height);
    GL11.glVertex2i(x + width, y);
    GL11.glEnd();

    GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL);
    GL11.glColor4f(0.0f, 0.5f, 1.0f, 0.8f);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2i(x, y);
    GL11.glVertex2i(x, y + height);
    GL11.glVertex2i(x + width, y + height);
    GL11.glVertex2i(x + width, y);
    GL11.glEnd();

    GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    GL11.glPushMatrix();
    GL11.glTranslatef(x + 16, y + 16, 0);
    ais[curAI].draw();
    GL11.glPopMatrix();
    GL11.glDisable(GL11.GL_BLEND);
    Material.DEFAULT_WHITE.bind();

}

From source file:hud.UnitDisplay.java

License:Open Source License

public void draw() {
    GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_LINE);
    GL11.glColor4f(0.0f, 0.0f, 0.4f, 1.0f);
    GL11.glLineWidth(2.0f);//from   w  w w.  j a v  a2s .c o m
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2i(x, y);
    GL11.glVertex2i(x, y + height);
    GL11.glVertex2i(x + width, y + height);
    GL11.glVertex2i(x + width, y);
    GL11.glEnd();

    GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL);
    GL11.glColor4f(0.0f, 0.5f, 1.0f, 0.8f);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2i(x, y);
    GL11.glVertex2i(x, y + height);
    GL11.glVertex2i(x + width, y + height);
    GL11.glVertex2i(x + width, y);
    GL11.glEnd();
    GL11.glDisable(GL11.GL_BLEND);

    int[] viewport = GLUtils.getViewport();

    GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();
    GLU.gluPerspective(45, 1.0f, 0.001f, 5.0f);
    GL11.glViewport(getX(), viewport[3] - (getY() + height), width, height);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();
    GLU.gluLookAt(2.0f * (float) Math.cos(angle), 2.0f * (float) Math.sin(angle), 1.0f, 0, 0, 0, 0, 0, 1);
    //        GL11.glTranslatef(x + width/2, y + height/2,0);
    currentUnit.draw();
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPopMatrix();
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPopMatrix();
    GL11.glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_LIGHTING);
}

From source file:io.root.gfx.glutils.GL.java

License:Apache License

public static void glPolygonMode(int face, int type) {
    GL11.glPolygonMode(face, type);
}

From source file:io.root.gfx.ModernGraphics.java

License:Apache License

@Override
public void showWireFrame(boolean show) {
    GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, show ? GL11.GL_LINE : GL11.GL_FILL);
}