package slim.test.example;
import static org.lwjgl.opengl.GL11.GL_BLEND;
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_DEPTH_TEST;
import static org.lwjgl.opengl.GL11.GL_MODELVIEW;
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.GL_PROJECTION;
import static org.lwjgl.opengl.GL11.GL_QUADS;
import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
import static org.lwjgl.opengl.GL11.glBegin;
import static org.lwjgl.opengl.GL11.glBlendFunc;
import static org.lwjgl.opengl.GL11.glClear;
import static org.lwjgl.opengl.GL11.glClearColor;
import static org.lwjgl.opengl.GL11.glDisable;
import static org.lwjgl.opengl.GL11.glEnable;
import static org.lwjgl.opengl.GL11.glEnd;
import static org.lwjgl.opengl.GL11.glLoadIdentity;
import static org.lwjgl.opengl.GL11.glMatrixMode;
import static org.lwjgl.opengl.GL11.glOrtho;
import static org.lwjgl.opengl.GL11.glTexCoord2f;
import static org.lwjgl.opengl.GL11.glVertex2f;
import static org.lwjgl.opengl.GL11.glViewport;
import java.io.IOException;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
public class VertexArrayExample {
public static void main(String[] args) throws LWJGLException {
new VertexArrayExample().start();
}
public void start() throws LWJGLException {
Display.setTitle("Vertex Array Example");
Display.setResizable(false);
Display.setDisplayMode(new DisplayMode(800, 600));
Display.setVSyncEnabled(true);
Display.create();
create();
while (!Display.isCloseRequested()) {
render();
Display.update();
Display.sync(60);
}
Display.destroy();
}
Texture tex;
ShaderProgram shader;
protected void create() {
glEnable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClearColor(0f, 0f, 0f, 0f);
glViewport(0, 0, Display.getWidth(), Display.getHeight());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, Display.getWidth(), Display.getHeight(), 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Load some textures
try {
tex = new Texture(VertexArrayExample.class.getResource("/res/small.png"));
} catch (IOException e) {
throw new RuntimeException("couldn't load texture");
}
}
protected void render() {
glClear(GL_COLOR_BUFFER_BIT);
draw(tex, 20, 20);
}
public void draw(Texture tex, int x, int y) {
tex.bind();
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(x, y);
glTexCoord2f(1, 0);
glVertex2f(x+tex.width, y);
glTexCoord2f(1, 1);
glVertex2f(x+tex.width, y+tex.height);
glTexCoord2f(0, 1);
glVertex2f(x, y+tex.height);
glEnd();
}
}