78 lines
2.0 KiB
Java
78 lines
2.0 KiB
Java
package shootergame.util.gl.texture;
|
|
|
|
import static org.lwjgl.opengl.GL11.GL_NEAREST;
|
|
import static org.lwjgl.opengl.GL11.GL_RGBA;
|
|
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
|
|
import static org.lwjgl.opengl.GL11.GL_TEXTURE_MAG_FILTER;
|
|
import static org.lwjgl.opengl.GL11.GL_TEXTURE_MIN_FILTER;
|
|
import static org.lwjgl.opengl.GL11.GL_UNSIGNED_BYTE;
|
|
import static org.lwjgl.opengl.GL11.glBindTexture;
|
|
import static org.lwjgl.opengl.GL11.glGenTextures;
|
|
import static org.lwjgl.opengl.GL11.glTexImage2D;
|
|
import static org.lwjgl.opengl.GL11.glTexParameteri;
|
|
|
|
import shootergame.resources.Resource;
|
|
|
|
public class TextureMap
|
|
{
|
|
private int texture_gl;
|
|
private int max_x;
|
|
private int max_y;
|
|
private int scale;
|
|
private Resource resource;
|
|
|
|
public TextureMap(int scale, Resource resource) {
|
|
this.scale = scale;
|
|
this.resource = resource;
|
|
}
|
|
|
|
public void init()
|
|
{
|
|
// Generate and bind the texture map
|
|
this.texture_gl = glGenTextures();
|
|
glBindTexture(GL_TEXTURE_2D, this.texture_gl);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
// Load the texture into opengl
|
|
Texture texture = new Texture(resource);
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
|
|
texture.getWidth(), texture.getHeight(),
|
|
0, GL_RGBA, GL_UNSIGNED_BYTE, texture.getByteBuffer());
|
|
|
|
// Store the width and height variables
|
|
this.max_x = texture.getWidth();
|
|
this.max_y = texture.getHeight();
|
|
|
|
System.out.println("texmap: "+texture_gl);
|
|
|
|
// Free the texture
|
|
//texture.free();
|
|
}
|
|
|
|
public TextureReference getTextureReference(int start_x, int end_x, int start_y, int end_y) {
|
|
return new TextureReference(start_x * scale, end_x * scale, start_y * scale, end_y * scale)
|
|
{
|
|
|
|
@Override
|
|
public int getMaxX() {
|
|
return max_x;
|
|
}
|
|
|
|
@Override
|
|
public int getMaxY() {
|
|
return max_y;
|
|
}
|
|
|
|
};
|
|
}
|
|
|
|
public void bindTexture() {
|
|
glBindTexture(GL_TEXTURE_2D, texture_gl);
|
|
}
|
|
|
|
public void unbindTexture() {
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
}
|
|
}
|