[DEV] correct loading of Images
This commit is contained in:
parent
cb9c625ac2
commit
7c879b3922
@ -45,13 +45,19 @@ public class MainGameLoop {
|
||||
Loader loader = new Loader();
|
||||
manager.init();
|
||||
|
||||
|
||||
|
||||
TexturedModel staticModel = new TexturedModel(OBJLoader.loadObjModel("tree", loader),
|
||||
new ModelTexture(loader.loadTexture("tree")));
|
||||
//ModelTexture texture = staticModel.getTexture();
|
||||
//texture.setShineDamper(10);
|
||||
//texture.setReflectivity(1);
|
||||
|
||||
RawModel model = OBJLoader.loadObjModel("tree", loader);
|
||||
TexturedModel staticModel = new TexturedModel(model, new ModelTexture(loader.loadTexture("tree")));
|
||||
ModelTexture texture = staticModel.getTexture();
|
||||
texture.setShineDamper(10);
|
||||
texture.setReflectivity(1);
|
||||
TexturedModel grassModel = new TexturedModel(OBJLoader.loadObjModel("grassModel", loader),
|
||||
new ModelTexture(loader.loadTexture("grassTexture")));
|
||||
|
||||
TexturedModel fernModel = new TexturedModel(OBJLoader.loadObjModel("fern", loader),
|
||||
new ModelTexture(loader.loadTexture("fern")));
|
||||
|
||||
Light light = new Light(new Vector3f(3000,2000,2000), new Vector3f(1,1,1));
|
||||
|
||||
@ -63,8 +69,16 @@ public class MainGameLoop {
|
||||
List<Entity> entities = new ArrayList<Entity>();
|
||||
Random random = new Random();
|
||||
|
||||
for (int iii=0; iii<2000; iii++) {
|
||||
entities.add(new Entity(staticModel, new Vector3f(random.nextFloat()*800 - 400,0,random.nextFloat() * -600),new Vector3f(0,0,0),3));
|
||||
for (int iii=0; iii<500; iii++) {
|
||||
entities.add(new Entity(staticModel,
|
||||
new Vector3f(random.nextFloat()*800 - 400, 0, random.nextFloat() * -600),
|
||||
new Vector3f(0,0,0),3));
|
||||
entities.add(new Entity(grassModel,
|
||||
new Vector3f(random.nextFloat()*800 - 400, 0, random.nextFloat() * -600),
|
||||
new Vector3f(0,0,0),1));
|
||||
entities.add(new Entity(fernModel,
|
||||
new Vector3f(random.nextFloat()*800 - 400, 0, random.nextFloat() * -600),
|
||||
new Vector3f(0,0,0),0.6f));
|
||||
}
|
||||
|
||||
MasterRenderer renderer = new MasterRenderer();
|
||||
|
@ -86,7 +86,8 @@ public class Loader {
|
||||
}
|
||||
|
||||
private int loadPNGTexture(String filename, int textureUnit) {
|
||||
ByteBuffer buf = null;
|
||||
ByteBuffer bufIn = null;
|
||||
ByteBuffer buf = null;
|
||||
int tWidth = 0;
|
||||
int tHeight = 0;
|
||||
try {
|
||||
@ -98,9 +99,8 @@ public class Loader {
|
||||
tWidth = decoder.getWidth();
|
||||
tHeight = decoder.getHeight();
|
||||
// Decode the PNG file in a ByteBuffer
|
||||
buf = ByteBuffer.allocateDirect(
|
||||
4 * decoder.getWidth() * decoder.getHeight());
|
||||
decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA);
|
||||
buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
|
||||
decoder.decodeFlipped(buf, decoder.getWidth() * 4, Format.RGBA);
|
||||
buf.flip();
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
@ -117,8 +117,7 @@ public class Loader {
|
||||
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
// Upload the texture data and generate mip maps (for scaling)
|
||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, tWidth, tHeight, 0,
|
||||
GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf);
|
||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, tWidth, tHeight, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf);
|
||||
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
|
||||
|
||||
// Setup the ST coordinate system
|
||||
@ -126,10 +125,8 @@ public class Loader {
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
|
||||
|
||||
// Setup what to do when the texture has to be scaled
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER,
|
||||
GL11.GL_NEAREST);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER,
|
||||
GL11.GL_LINEAR_MIPMAP_LINEAR);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
|
||||
|
||||
this.exitOnGLError("loadPNGTexture");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user