Created
December 23, 2011 08:33
-
-
Save macalinao/1513589 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this template, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package org.opencraft.render; | |
import org.lwjgl.opengl.GL11; | |
import org.lwjgl.util.vector.Vector3f; | |
import org.opencraft.Opencraft; | |
import org.royawesome.renderer.BatchVertexRenderer; | |
import org.royawesome.renderer.shader.BasicShader; | |
import org.royawesome.util.MatrixUtils; | |
/** | |
* | |
* @author simplyianm | |
*/ | |
public class RenderEngine { | |
private final Opencraft opencraft; | |
private BatchVertexRenderer batcher; | |
public RenderEngine(Opencraft opencraft) { | |
this.opencraft = opencraft; | |
batcher = BatchVertexRenderer.constructNewBatch(GL11.GL_POLYGON); | |
} | |
public void initialize() { | |
/* | |
* Pre-Initialization | |
*/ | |
//Enable 2D textures | |
GL11.glEnable(GL11.GL_TEXTURE_2D); | |
GL11.glShadeModel(GL11.GL_SMOOTH); | |
//Clear stuff | |
GL11.glClearDepth(1.0f); | |
//Depth test | |
GL11.glEnable(GL11.GL_DEPTH_TEST); | |
GL11.glDepthFunc(GL11.GL_LEQUAL); | |
//Alpha test | |
GL11.glEnable(GL11.GL_ALPHA_TEST); | |
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1f); | |
/* | |
* Game initialization | |
*/ | |
//Create the screen | |
GL11.glMatrixMode(GL11.GL_PROJECTION); | |
GL11.glLoadIdentity(); | |
GL11.glOrtho(0, opencraft.getWidth(), opencraft.getHeight(), 0, -1000, 1000); | |
GL11.glMatrixMode(GL11.GL_MODELVIEW); | |
GL11.glLoadIdentity(); | |
GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_DEPTH_BUFFER_BIT); | |
BasicShader shader = new BasicShader(); | |
shader.setProjectionMatrix(MatrixUtils.createPerspective(45, 4.f / 3.f, .0f, 100f)); | |
shader.setViewMatrix(MatrixUtils.createLookAt(new Vector3f(5, 0, 5), new Vector3f(0, 0, 0), new Vector3f(0, 1, 0))); | |
//shader.SetUniform("texture", tex); | |
batcher.setShader(shader); | |
batcher.enableColors(); | |
batcher.begin(); | |
batcher.AddColor(1.0f, 0.0f, 0.0f); | |
batcher.AddVertex(200, 400); | |
batcher.AddColor(0.0f, 1.0f, 0.0f); | |
batcher.AddVertex(200, 200); | |
batcher.AddColor(0.0f, 0.0f, 1.0f); | |
batcher.AddVertex(400, 200); | |
batcher.AddColor(0.0f, 0.0f, 1.0f); | |
batcher.AddVertex(400, 400); | |
batcher.end(); | |
} | |
public void render() { | |
System.out.println("Rendering"); | |
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); | |
GL11.glLoadIdentity(); | |
batcher.render(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment