-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTexture.java
More file actions
41 lines (34 loc) · 989 Bytes
/
Texture.java
File metadata and controls
41 lines (34 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
/**
* File: Texture.java
* Created on 30.12.2023, 4:18:41
*
* @author LWJGL2
*/
public class Texture {
public int[] pixelData;
public final int width, height;
public Texture(BufferedImage base) {
BufferedImage image = new BufferedImage(base.getWidth(), base.getHeight(), BufferedImage.TYPE_INT_ARGB);
{
image.getGraphics().drawImage(base, 0, 0, null);
}
width = image.getWidth();
height = image.getHeight();
pixelData = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
}
public int getPixel(float x, float y) {
return getPixel((int) x, (int) y);
}
public int getPixel(int x, int y) {
int index = x + y * width;
if (index > pixelData.length - 1) {
return 0;
}
if (index < 0) {
return 0;
}
return pixelData[index];
}
}