Search in sources :

Example 6 with PixelFormat

use of org.lwjgl.opengl.PixelFormat 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

PixelFormat (org.lwjgl.opengl.PixelFormat)6 LWJGLException (org.lwjgl.LWJGLException)5 Pbuffer (org.lwjgl.opengl.Pbuffer)4 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)1 ContextAttribs (org.lwjgl.opengl.ContextAttribs)1 RenderTexture (org.lwjgl.opengl.RenderTexture)1 Vector2f (org.lwjgl.util.vector.Vector2f)1