[DEV] correct loading of Images
This commit is contained in:
parent
cb9c625ac2
commit
7c879b3922
@ -47,11 +47,17 @@ public class MainGameLoop {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
RawModel model = OBJLoader.loadObjModel("tree", loader);
|
TexturedModel staticModel = new TexturedModel(OBJLoader.loadObjModel("tree", loader),
|
||||||
TexturedModel staticModel = new TexturedModel(model, new ModelTexture(loader.loadTexture("tree")));
|
new ModelTexture(loader.loadTexture("tree")));
|
||||||
ModelTexture texture = staticModel.getTexture();
|
//ModelTexture texture = staticModel.getTexture();
|
||||||
texture.setShineDamper(10);
|
//texture.setShineDamper(10);
|
||||||
texture.setReflectivity(1);
|
//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));
|
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>();
|
List<Entity> entities = new ArrayList<Entity>();
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
|
|
||||||
for (int iii=0; iii<2000; iii++) {
|
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(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();
|
MasterRenderer renderer = new MasterRenderer();
|
||||||
|
@ -86,6 +86,7 @@ public class Loader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int loadPNGTexture(String filename, int textureUnit) {
|
private int loadPNGTexture(String filename, int textureUnit) {
|
||||||
|
ByteBuffer bufIn = null;
|
||||||
ByteBuffer buf = null;
|
ByteBuffer buf = null;
|
||||||
int tWidth = 0;
|
int tWidth = 0;
|
||||||
int tHeight = 0;
|
int tHeight = 0;
|
||||||
@ -98,9 +99,8 @@ public class Loader {
|
|||||||
tWidth = decoder.getWidth();
|
tWidth = decoder.getWidth();
|
||||||
tHeight = decoder.getHeight();
|
tHeight = decoder.getHeight();
|
||||||
// Decode the PNG file in a ByteBuffer
|
// Decode the PNG file in a ByteBuffer
|
||||||
buf = ByteBuffer.allocateDirect(
|
buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
|
||||||
4 * decoder.getWidth() * decoder.getHeight());
|
decoder.decodeFlipped(buf, decoder.getWidth() * 4, Format.RGBA);
|
||||||
decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA);
|
|
||||||
buf.flip();
|
buf.flip();
|
||||||
in.close();
|
in.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -117,8 +117,7 @@ public class Loader {
|
|||||||
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
|
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
|
||||||
|
|
||||||
// Upload the texture data and generate mip maps (for scaling)
|
// Upload the texture data and generate mip maps (for scaling)
|
||||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, tWidth, tHeight, 0,
|
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, tWidth, tHeight, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf);
|
||||||
GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf);
|
|
||||||
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
|
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
|
||||||
|
|
||||||
// Setup the ST coordinate system
|
// 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);
|
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
|
// Setup what to do when the texture has to be scaled
|
||||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER,
|
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
||||||
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_MIN_FILTER,
|
|
||||||
GL11.GL_LINEAR_MIPMAP_LINEAR);
|
|
||||||
|
|
||||||
this.exitOnGLError("loadPNGTexture");
|
this.exitOnGLError("loadPNGTexture");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user