Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.io.File;
- import org.lwjgl.LWJGLException;
- import org.lwjgl.opengl.Display;
- import org.lwjgl.opengl.DisplayMode;
- import static org.lwjgl.opengl.GL11.*;
- import org.newdawn.slick.Color;
- import org.newdawn.slick.opengl.Texture;
- import org.newdawn.slick.opengl.TextureLoader;
- import org.newdawn.slick.util.ResourceLoader;
- public class main {
- private Texture[] texture = new Texture[10];
- private String tilesLocation = System.getProperty("user.dir") + "\\res\\tiles\\";
- public void start()
- {
- initGL(800, 600);
- init();
- while(!Display.isCloseRequested())
- {
- glClear(GL_COLOR_BUFFER_BIT);
- render();
- Display.update();
- Display.sync(100);
- if(Display.isCloseRequested()){
- Display.destroy();
- System.exit(0);
- }
- }
- }
- private void initGL(int width, int height)
- {
- try {
- Display.setDisplayMode(new DisplayMode(width,height));
- Display.create();
- Display.setVSyncEnabled(true);
- } catch (LWJGLException e) {
- e.printStackTrace();
- System.exit(0);
- }
- glEnable(GL_TEXTURE_2D);
- glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- // enable alpha blending
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glViewport(0,0,width,height);
- glMatrixMode(GL_MODELVIEW);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, width, height, 0, 1, -1);
- glMatrixMode(GL_MODELVIEW);
- }
- private void init()
- {
- try
- {
- int curI = 0;
- for(int i = 0; i < 1000; ++i)
- {
- if(new File(tilesLocation + i + ".png").exists())
- {
- texture[curI] = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(tilesLocation + i + ".png"));
- System.out.println("Texture loaded: "+texture[curI]);
- System.out.println(">> Image width: "+texture[curI].getImageWidth());
- System.out.println(">> Image height: "+texture[curI].getImageHeight());
- System.out.println(">> Texture width: "+texture[curI].getTextureWidth());
- System.out.println(">> Texture height: "+texture[curI].getTextureHeight());
- System.out.println(">> Texture ID: "+texture[curI].getTextureID());
- curI++;
- if(curI == 9) break;
- }
- else { System.out.println("false");}
- }
- } catch(IOException e){
- e.printStackTrace();
- }
- }
- private void render()
- {
- Color.white.bind();
- float sx = 32, sy = 100;
- float x, y;
- for(int i = 0; i < texture.length; ++i)
- {
- if(texture[i] != null)
- {
- x = sx * i;
- y = sy;
- texture[i].bind(); // or glBind(texture[i].getTextureID());
- glBegin(GL_QUADS);
- glTexCoord2f(0,0);
- glVertex2f(x, y);
- glTexCoord2f(1,0);
- glVertex2f(x + texture[i].getTextureWidth(), y);
- glTexCoord2f(1, 1);
- glVertex2f(x + texture[i].getTextureWidth(), y + texture[i].getTextureHeight());
- glTexCoord2f(0, 1);
- glVertex2f(x, y + texture[i].getTextureHeight());
- glEnd();
- }
- }
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- main images = new main();
- images.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement