Kód: Vybrať všetko
//boot.java
package data;
import org.lwjgl.opengl.Display;
import org.newdawn.slick.opengl.Texture;
import static helpers.Artist.*;
public class Boot {
public Boot() {
BeginSession();
Texture tex1 = LoadTexture("src/res/dirt.png", "PNG");
Texture tex2 = LoadTexture("src/res/grass.png", "PNG");
while(!Display.isCloseRequested()){
DrawQuadTex(tex1, 0, 0, 64, 64);
DrawQuadTex(tex2, 64, 0, 64, 64);
Display.update();
Display.sync(30);
}
Display.destroy();
}
public static void main(String[] args){
new Boot();
}
}
Kód: Vybrať všetko
//artist.java
package helpers;
import static org.lwjgl.opengl.GL11.GL_MODELVIEW;
import static org.lwjgl.opengl.GL11.GL_PROJECTION;
import static org.lwjgl.opengl.GL11.GL_QUADS;
import static org.lwjgl.opengl.GL11.glBegin;
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.glVertex2f;
import java.io.IOException;
import java.io.InputStream;
import static org.lwjgl.opengl.GL11.*;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
public class Artist {
public static final int WIDTH = 800, HEIGHT = 600;
public static void BeginSession(){
Display.setTitle("Game (Test Alpha)");
try {
Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, WIDTH, HEIGHT, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
}
public static void DrawQuad(float x, float y, float width, float height){
glBegin(GL_QUADS);
glVertex2f(x, y);//top left
glVertex2f(x + width, y);//top right
glVertex2f(x + width, y + height);//bottom right
glVertex2f(x, y + height);//bottom left
glEnd();
}
public static void DrawQuadTex(Texture tex, float x, float y, float width, float height){
tex.bind();
glTranslatef(x, y, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(1, 0);
glVertex2f(width, 0);
glTexCoord2f(1, 1);
glVertex2f(width, height);
glTexCoord2f(0, height);
glEnd();
glLoadIdentity();
}
public static Texture LoadTexture(String path, String fileType){
Texture tex = null;
InputStream in = ResourceLoader.getResourceAsStream(path);
try {
tex = TextureLoader.getTexture(fileType, in);
} catch (IOException e) {
e.printStackTrace();
}
return tex;
}
}Kód: Vybrať všetko
//tile.java
package data;
import org.newdawn.slick.opengl.Texture;
public class Tile {
private float x, y, width, height;
private Texture texture;
public Tile(float x, float y, float width, float height, Texture texture){
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
}