Λοιπον, εβαλα internet στο λαπτοπ.... Aaaaaaaaaaaaaaaaaand it's code time!
OpenGLRenders: καλω απο main τον constructor της.
Code: Select all
package jscroller;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
//import java.lang.IndexOutOfBoundsException;
import java.util.ArrayList;
import static org.lwjgl.opengl.GL11.*;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.input.Keyboard;
//import org.lwjgl.input.Mouse.*;
//import org.lwjgl.input.Keyboard.*;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
public class OpenGLRenders {
ArrayList<Texture> texture = new ArrayList<Texture>();
public OpenGLRenders() {
try{
Display.setDisplayMode(new DisplayMode(800,600)); //Size of the primary window.
Display.setTitle("Dreamland Engine"); //Name of the Window
Display.create(); //Generates window.
}
catch (LWJGLException e){
e.printStackTrace(); //Things are bad...
}
//OpenGl parameters...
glMatrixMode(GL_PROJECTION); //Enabling the Canvas
glLoadIdentity(); //??? Does not seem to work without this... I have no idea what it does...
glOrtho(0,800,600,0,1,-1); //(x,y,z,0,1,-1) for 2D
glMatrixMode(GL_MODELVIEW);
while (!Display.isCloseRequested()){
glClear(GL_COLOR_BUFFER_BIT);
texture.add(LoadTexture("PNG","tiles1")); //0
ObjGen.Tile(400,400,500,500,texture.get(0));
ObjGen.Tile(100,100,300,300,texture.get(0));
ObjGen.Tile(300,300,400,400,texture.get(0));
Display.update();
Display.sync(60); //FPS
}
Display.destroy();
}
private Texture LoadTexture(String format, String filename){
try {
return TextureLoader.getTexture("PNG", new FileInputStream(new File("res/"+filename+".png")));
} catch (FileNotFoundException e) {
//yaw
e.printStackTrace();
} catch (IOException e) {
//yaw
e.printStackTrace();
}
return null;
}
}
Και ενα δειγμα του κωδικα της ObjGen, οπως ειναι τωρα που δεν δημιουργει αντικειμενα αλλα εχει static μεθοδους!
Code: Select all
package jscroller;
import static org.lwjgl.opengl.GL11.*;
import org.newdawn.slick.opengl.Texture;
public class ObjGen {
public static void Tile(int pointAi, int pointAj, int pointBi, int pointBj, Texture texture){
if (texture == null){
ObjGen.PrTile(pointAi, pointAj, pointBi, pointBj);
}
else{
texture.bind();
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2i(pointAi,pointAj);
glTexCoord2f(0,1);
glVertex2i(pointAi,pointBj);
glTexCoord2f(1,1);
glVertex2i(pointBi,pointBj);
glTexCoord2f(1,0);
glVertex2i(pointBi,pointAj);
glEnd();
}
}
}
Για πειτε? Τι εξωφρενικα ηληθιο λαθος εχω κανει και τα παιζει τοσο ασχημα...?