de.ikosa.mars.viewer.glviewer.engine.GLRendererForward.java Source code

Java tutorial

Introduction

Here is the source code for de.ikosa.mars.viewer.glviewer.engine.GLRendererForward.java

Source

/*
 * Copyright (C) 2013 Clemens-Alexander Brust IT-Dienstleistungen
 *
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.ikosa.mars.viewer.glviewer.engine;

import de.ikosa.mars.util.ML;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30;

public class GLRendererForward {
    private GLScene scene;
    private GLSSQScene ssqScene;
    private GLCamera camera;
    private int fbAId;
    private int fbATexId;
    private int dbATexId;

    private int fbBId;
    private int fbBTexId;
    private int width, height;

    public GLRendererForward(GLScene scene, GLResources resourceManager, GLCamera camera, int width, int height) {
        this.scene = scene;
        this.camera = camera;
        this.width = width;
        this.height = height;

        // setup opengl
        GL11.glViewport(0, 0, width, height);
    }

    public static void clientSetup() {
        // setup opengl
        GL11.glEnable(GL11.GL_DEPTH_TEST);
        errorCheck("setting up client state GL_DEPTH_TEST");

        GL11.glDepthFunc(GL11.GL_LEQUAL);
        errorCheck("setting depth test function");

        GL11.glEnable(GL11.GL_CULL_FACE);
        GL11.glCullFace(GL11.GL_BACK);
        errorCheck("enabling back face culling");
    }

    public static void errorCheck(String message) {
        int error = GL11.glGetError();
        if (error != GL11.GL_NO_ERROR)
            ML.f(String.format("OpenGL Error while %s. (0x%04x)", message, error));
    }

    public static void errorCheck() {
        errorCheck("doing something");
    }

    public void Draw() {
        // forward pass
        GL20.glDrawBuffers(GL30.GL_COLOR_ATTACHMENT0);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

        scene.Pass(GLScene.PassType.Forward, camera);
    }
}