Search in sources :

Example 1 with Pbuffer

use of org.lwjgl.opengl.Pbuffer in project lwjgl by LWJGL.

the class UniqueRenderer method init.

protected Pbuffer init(final int width, final int height, final int texID) {
    Pbuffer pbuffer = null;
    try {
        pbuffer = new Pbuffer(width, height, new PixelFormat(16, 0, 0, 0, 0), null, null);
        // Initialise state of the pbuffer context.
        pbuffer.makeCurrent();
        PbufferTest.initGLState(width, height, 0.5f);
        glBindTexture(GL_TEXTURE_2D, texID);
        Display.makeCurrent();
    } catch (LWJGLException e) {
        e.printStackTrace();
        System.exit(-1);
    }
    return pbuffer;
}
Also used : PixelFormat(org.lwjgl.opengl.PixelFormat) Pbuffer(org.lwjgl.opengl.Pbuffer) LWJGLException(org.lwjgl.LWJGLException)

Example 2 with Pbuffer

use of org.lwjgl.opengl.Pbuffer in project lwjgl by LWJGL.

the class UniqueRendererRTT method init.

// Initialize texture renderer
protected Pbuffer init(final int width, final int height, final int texID) {
    Pbuffer pbuffer = null;
    try {
        final RenderTexture rt = new RenderTexture(true, false, false, false, RenderTexture.RENDER_TEXTURE_2D, 0);
        pbuffer = new Pbuffer(width, height, new PixelFormat(16, 0, 0, 0, 0), rt, null);
        // Initialise state of the pbuffer context.
        pbuffer.makeCurrent();
        PbufferTest.initGLState(width, height, 0.5f);
        glBindTexture(GL_TEXTURE_2D, texID);
        Display.makeCurrent();
    } catch (LWJGLException e) {
        e.printStackTrace();
        System.exit(-1);
    }
    return pbuffer;
}
Also used : RenderTexture(org.lwjgl.opengl.RenderTexture) PixelFormat(org.lwjgl.opengl.PixelFormat) Pbuffer(org.lwjgl.opengl.Pbuffer) LWJGLException(org.lwjgl.LWJGLException)

Example 3 with Pbuffer

use of org.lwjgl.opengl.Pbuffer in project lwjgl by LWJGL.

the class PbufferTest method initialize.

/**
 * Initializes the test
 */
private void initialize() {
    try {
        // find displaymode
        pbuffer = new Pbuffer(512, 512, new PixelFormat(), null, null);
        mode = findDisplayMode(800, 600, 16);
        Display.setDisplayMode(mode);
        // start of in windowed mode
        Display.create();
        // gl = new GLWindow("Test", 50, 50, mode.width, mode.height, mode.bpp, 0, 0, 0);
        if ((Pbuffer.getCapabilities() & Pbuffer.PBUFFER_SUPPORTED) == 0) {
            System.out.println("No Pbuffer support!");
            System.exit(1);
        }
        System.out.println("Pbuffer support detected");
        glInit();
        initPbuffer();
        Keyboard.create();
        quadPosition = new Vector2f(100f, 100f);
        quadVelocity = new Vector2f(1.0f, 1.0f);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Vector2f(org.lwjgl.util.vector.Vector2f) PixelFormat(org.lwjgl.opengl.PixelFormat) Pbuffer(org.lwjgl.opengl.Pbuffer) LWJGLException(org.lwjgl.LWJGLException)

Example 4 with Pbuffer

use of org.lwjgl.opengl.Pbuffer in project jmonkeyengine by jMonkeyEngine.

the class LwjglCanvas method makePbufferAvailable.

/**
     * Makes sure the pbuffer is available and ready for use
     */
protected void makePbufferAvailable() throws LWJGLException {
    if (pbuffer != null && pbuffer.isBufferLost()) {
        logger.log(Level.WARNING, "PBuffer was lost!");
        pbuffer.destroy();
        pbuffer = null;
    }
    if (pbuffer == null) {
        pbuffer = new Pbuffer(1, 1, acquirePixelFormat(true), null);
        pbuffer.makeCurrent();
        logger.log(Level.FINE, "OGL: Pbuffer has been created");
        // Any created objects are no longer valid
        if (!runningFirstTime) {
            renderer.resetGLObjects();
        }
    }
    pbuffer.makeCurrent();
    if (!pbuffer.isCurrent()) {
        throw new LWJGLException("Pbuffer cannot be made current");
    }
}
Also used : Pbuffer(org.lwjgl.opengl.Pbuffer) LWJGLException(org.lwjgl.LWJGLException)

Example 5 with Pbuffer

use of org.lwjgl.opengl.Pbuffer in project lwjgl by LWJGL.

the class PbufferTest method render.

private void render() {
    if (pbuffer.isBufferLost()) {
        System.out.println("Buffer contents lost - will recreate the buffer");
        pbuffer.destroy();
        try {
            pbuffer = new Pbuffer(512, 512, new PixelFormat(), null, null);
            initPbuffer();
        } catch (LWJGLException e) {
            e.printStackTrace();
        }
    }
    try {
        pbuffer.makeCurrent();
    } catch (LWJGLException e) {
        throw new RuntimeException(e);
    }
    // Pbuffer rendering
    // clear background
    glClear(GL_COLOR_BUFFER_BIT);
    // draw white quad
    glPushMatrix();
    {
        glTranslatef(quadPosition.x, quadPosition.y, 0);
        glRotatef(angle, 0.0f, 0.0f, 1.0f);
        glColor3f(1.0f, 1.0f, 1.0f);
        glBegin(GL_QUADS);
        {
            glVertex2i(-50, -50);
            glVertex2i(50, -50);
            glVertex2i(50, 50);
            glVertex2i(-50, 50);
        }
        glEnd();
    }
    glPopMatrix();
    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 512, 512, 0);
    try {
        Display.makeCurrent();
    } catch (LWJGLException e) {
        throw new RuntimeException(e);
    }
    // OpenGL window rendering
    glClear(GL_COLOR_BUFFER_BIT);
    // draw white quad
    glPushMatrix();
    {
        glTranslatef(quadPosition.x, quadPosition.y, 0);
        glRotatef(angle, 0.0f, 0.0f, 1.0f);
        glColor3f(1.0f, 1.0f, 0.0f);
        glBegin(GL_QUADS);
        {
            glTexCoord2f(0f, 0f);
            glVertex2i(-50, -50);
            glTexCoord2f(1f, 0f);
            glVertex2i(50, -50);
            glTexCoord2f(1f, 1f);
            glVertex2i(50, 50);
            glTexCoord2f(0f, 1f);
            glVertex2i(-50, 50);
        }
        glEnd();
    }
    glPopMatrix();
}
Also used : PixelFormat(org.lwjgl.opengl.PixelFormat) Pbuffer(org.lwjgl.opengl.Pbuffer) LWJGLException(org.lwjgl.LWJGLException)

Aggregations

LWJGLException (org.lwjgl.LWJGLException)5 Pbuffer (org.lwjgl.opengl.Pbuffer)5 PixelFormat (org.lwjgl.opengl.PixelFormat)4 RenderTexture (org.lwjgl.opengl.RenderTexture)1 Vector2f (org.lwjgl.util.vector.Vector2f)1