diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..21026e2
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index cd1564d..7273826 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,10 +2,7 @@
-
-
-
-
+
@@ -21,48 +18,145 @@
-
-
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -88,33 +182,38 @@
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
@@ -191,6 +290,116 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -213,6 +422,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -239,7 +480,7 @@
-
+
@@ -455,16 +696,16 @@
-
+
-
-
+
+
-
+
@@ -494,61 +735,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -593,8 +779,6 @@
-
-
@@ -620,18 +804,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
@@ -688,9 +860,7 @@
-
-
-
+
@@ -744,16 +914,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -782,27 +942,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -846,22 +986,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -881,18 +1005,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
@@ -901,14 +1013,6 @@
-
-
-
-
-
-
-
-
@@ -920,24 +1024,139 @@
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..c968209
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+
+
+ Global-Gam-Jam-2017
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/out/production/Global-Gam-Jam-2017/shaders/main.frag b/out/production/Global-Gam-Jam-2017/shaders/main.frag
index 5fb950e..a0c0b6e 100644
--- a/out/production/Global-Gam-Jam-2017/shaders/main.frag
+++ b/out/production/Global-Gam-Jam-2017/shaders/main.frag
@@ -6,9 +6,11 @@ uniform vec4 color;
in vec2 fragTexCoord;
in vec3 fragVert;
+out vec4 finalColor;
+
//layout(location = 0) out vec4 finalColor;
// https://learnopengl.com/#!Lighting/Multiple-lights pour le lighing en cas de besoin
void main() {
- gl_FragData[0] = texture(materialTex, fragTexCoord) * color;
+ finalColor = texture(materialTex, fragTexCoord) * color;
}
\ No newline at end of file
diff --git a/src/globalgamejam/game/MainGame.java b/src/globalgamejam/game/MainGame.java
index 1e373f0..d33db98 100644
--- a/src/globalgamejam/game/MainGame.java
+++ b/src/globalgamejam/game/MainGame.java
@@ -1,10 +1,16 @@
package globalgamejam.game;
import globalgamejam.math.Vector2f;
+import globalgamejam.gui.ActionGUI;
+import globalgamejam.gui.GUI;
+import globalgamejam.gui.GUILabel;
+import globalgamejam.gui.IActionGUI;
+import globalgamejam.input.Input;
import globalgamejam.render.*;
import globalgamejam.tiles.TestTile;
import globalgamejam.tiles.Tile;
+import java.awt.*;
import java.util.ArrayList;
import java.util.Random;
@@ -19,9 +25,14 @@ public class MainGame extends Game{
private Player player1;
+ private ArrayList guis;
+ private GUILabel label;
+
+
@Override
public void init() {
tiles = new ArrayList();
+ guis = new ArrayList();
TestTile t = new TestTile();
t.getTransform().translate(100,100,0);
t.getTransform().scale(10,10,0);
@@ -31,6 +42,22 @@ public class MainGame extends Game{
tiles.add(player1.getTile());
rand = new Random();
+ label = new GUILabel("Test");
+ label.setX(10);
+ label.setY(10);
+ label.setAction(new ActionGUI() {
+ @Override
+ public void enter(float mouseX, float mouseY) {
+ label.setColor(Color.RED);
+ }
+
+ @Override
+ public void leave(float mouseX, float mouseY) {
+ label.setColor(Color.WHITE);
+ }
+ });
+ guis.add(label);
+
}
@Override
@@ -38,6 +65,8 @@ public class MainGame extends Game{
Camera.transform();
// player1.setPosition((rand.nextFloat() - 0.5f) * 200f, (rand.nextFloat() - 0.5f) * 150f);
// player1.applyTransform();
+ for(GUI g : guis)g.update();
+
}
@Override
@@ -48,12 +77,13 @@ public class MainGame extends Game{
@Override
public void renderGUI() {
-
+ for(GUI g : guis)g.render();
}
@Override
public void destroy() {
tiles.clear();
+ guis.clear();
}
}
diff --git a/src/globalgamejam/gui/ActionGUI.java b/src/globalgamejam/gui/ActionGUI.java
new file mode 100644
index 0000000..7525d76
--- /dev/null
+++ b/src/globalgamejam/gui/ActionGUI.java
@@ -0,0 +1,33 @@
+package globalgamejam.gui;
+
+/**
+ * Created by trexr on 20/01/2017.
+ */
+public class ActionGUI implements IActionGUI{
+
+
+ @Override
+ public void enter(float mouseX, float mouseY) {
+
+ }
+
+ @Override
+ public void leave(float mouseX, float mouseY) {
+
+ }
+
+ @Override
+ public void move(float mouseX, float mouseY) {
+
+ }
+
+ @Override
+ public void hover(float mouseX, float mouseY) {
+
+ }
+
+ @Override
+ public void clicked(float mouseX, float mouseY, int buttonKey, int buttonState) {
+
+ }
+}
diff --git a/src/globalgamejam/gui/GUI.java b/src/globalgamejam/gui/GUI.java
new file mode 100644
index 0000000..69d0ba9
--- /dev/null
+++ b/src/globalgamejam/gui/GUI.java
@@ -0,0 +1,72 @@
+package globalgamejam.gui;
+
+import globalgamejam.input.Input;
+
+/**
+ * Created by trexr on 20/01/2017.
+ */
+public abstract class GUI {
+ private int mouseInGUI = 0;//0 = En dehors, 1 = entrer, 2 = deplacer
+
+ protected int x, y;
+ protected int width,height;
+
+ protected IActionGUI action;
+
+ public GUI(int x,int y){
+ this.x = x;
+ this.y = y;
+ this.width = 0;
+ this.height = 0;
+ }
+
+ public void setAction(IActionGUI action){
+ this.action = action;
+ }
+
+ public void update(){
+ float mouseX = Input.getMousePosition().x;
+ float mouseY = Input.getMousePosition().y;
+ float dMouseX = Input.getDMouse().x;
+ float dMouseY = Input.getDMouse().y;
+ if(mouseX >= this.x && mouseX <= this.x + this.width && mouseY >= this.y && mouseY <= this.y + this.height){
+ for(int i = 0;i < Input.NBRE_BUTTON;i++){
+ if(Input.isButton(i)){
+ action.clicked(mouseX,mouseY,i,Input.getButtonState(i));
+ }
+ }
+ if(mouseInGUI == 0){
+ mouseInGUI = 1;
+ action.enter(mouseX,mouseY);
+ }else if(mouseInGUI == 1 || mouseInGUI == 2){
+ mouseInGUI = 2;
+ action.hover(mouseX,mouseY);
+ if(dMouseX != 0 || dMouseY != 0)action.move(mouseX,mouseY);
+ }
+ }else{
+ if(mouseInGUI == 1 || mouseInGUI == 2){
+ mouseInGUI = 0;
+ action.leave(mouseX,mouseY);
+ }
+ }
+ }
+
+ public abstract void render();
+ public abstract void destroy();
+
+ public int getX() {
+ return x;
+ }
+
+ public void setX(int x) {
+ this.x = x;
+ }
+
+ public int getY() {
+ return y;
+ }
+
+ public void setY(int y) {
+ this.y = y;
+ }
+}
diff --git a/src/globalgamejam/gui/GUILabel.java b/src/globalgamejam/gui/GUILabel.java
new file mode 100644
index 0000000..3b8f68c
--- /dev/null
+++ b/src/globalgamejam/gui/GUILabel.java
@@ -0,0 +1,229 @@
+package globalgamejam.gui;
+import static org.lwjgl.opengl.GL11.*;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.image.BufferedImage;
+import java.nio.ByteBuffer;
+import java.nio.FloatBuffer;
+
+import globalgamejam.math.Color4f;
+import globalgamejam.math.Matrix4f;
+import globalgamejam.render.Camera;
+import globalgamejam.render.DisplayManager;
+import globalgamejam.render.Shaders;
+import globalgamejam.render.Texture;
+import org.lwjgl.BufferUtils;
+import org.lwjgl.opengl.*;
+
+/**
+ * usefull to print 2D text in openGL LWJGL application
+ * @author Jean-Baptiste Pommeret (Fiesta)
+ * @version 1.0
+ */
+public class GUILabel extends GUI {
+
+ private Texture texture;
+ private String text;
+ private Color color;
+ private int size;
+ private String font;
+ private int vbo,numberOfVertices;
+
+ /**
+ * Full constructor of a Label
+ * @param text (String) : the text to print
+ * @param xC (float) : the x coordonnate of the frame where start printing the Label (upper left corner)
+ * @param yC (float) : the y coordonnate of the frame where start printing the Label (upper left corner)
+ * @param color (java.awt.Color) : the Color you wish for the text
+ * @param font (String) : the font (i.e. "Arial" or "Times new roman")
+ * @param size (int) : the font size
+ */
+ public GUILabel(String text, int xC, int yC, Color color, String font, int size){
+ super(xC,yC);
+ this.font = font;
+ this.color = color;
+ this.text = text;
+ this.size = size;
+ if(this.texture != null)this.texture.destroy();
+ this.texture = Texture.loadFont(text,color,font,size);
+ super.width = this.texture.width;
+ super.height = this.texture.height;
+ this.vbo = GL15.glGenBuffers();
+ float[] a = new float[]{
+ 0,0, 0.0f,0.0f,
+ this.texture.width,0, 1.0f,0.0f,
+ this.texture.width,this.texture.height, 1.0f,1.0f,
+ 0,this.texture.height, 0.0f,1.0f
+ };
+ FloatBuffer buff = BufferUtils.createFloatBuffer(a.length);
+ buff.put(a).flip();
+ this.numberOfVertices = a.length/(2+2);
+
+ GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo);
+ GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buff, GL15.GL_STATIC_DRAW);
+ GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
+ }
+
+ public void render(){
+ Shaders.MAIN_SHADERS.bind();
+ Shaders.MAIN_SHADERS.uniform("camera", Camera.matrix);
+ Matrix4f transform = new Matrix4f();
+ transform.translate(super.x,super.y,0);
+ Shaders.MAIN_SHADERS.uniform("transform", transform);
+ Shaders.MAIN_SHADERS.uniform("projection", DisplayManager.projection);
+ Shaders.MAIN_SHADERS.uniform("color", Color4f.WHITE);
+
+ texture.bind();
+ GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo);
+ GL20.glEnableVertexAttribArray(Shaders.MAIN_SHADERS.getAttribLocation("vert"));
+ GL20.glVertexAttribPointer(Shaders.MAIN_SHADERS.getAttribLocation("vert"), 2, GL11.GL_FLOAT, false, (2+2)*4, 0);
+
+ GL20.glEnableVertexAttribArray(Shaders.MAIN_SHADERS.getAttribLocation("vertTexCoord"));
+ GL20.glVertexAttribPointer(Shaders.MAIN_SHADERS.getAttribLocation("vertTexCoord"), 2, GL11.GL_FLOAT, true, (2+2)*4, 2*4);
+
+ GL11.glDrawArrays(GL11.GL_QUADS, 0, numberOfVertices);
+ GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
+ texture.unbind();
+ Shaders.MAIN_SHADERS.unbind();
+ }
+
+ /**
+ * Default constructor of a Label. Call the full constructor -> Label("", 100, 100, Color.white, "Arial", 30)
+ */
+ public GUILabel(){
+ this("");
+ }
+
+ /**
+ * Construct a Label from the text param and default statement.
+ * Call the full constructor -> Label(text, 100, 100, Color.white, "Arial", 30)
+ * @param text (String) : the text to print
+ */
+ public GUILabel(String text){
+ this(text, 100, 100, Color.white, "Arial", 30);
+ }
+
+ /**
+ * Return the actual Color of the Label
+ * @return color (java.awt.Color) : the Color of the Label
+ */
+ public Color getColor() {
+ return color;
+ }
+
+ /**
+ * Set the Color of the Label. Automaticaly update the Label to use the new Color
+ * @param color (java.awt.Color) : the new Color of the Label
+ */
+ public void setColor(Color color) {
+ this.color = color;
+ if(this.texture != null)this.texture.destroy();
+ this.texture = Texture.loadFont(text,color,font,size);
+ }
+
+ /**
+ * Return the text of the Label
+ * @return text (String) : the text of the Label
+ */
+ public String getText() {
+ return text;
+ }
+
+ /**
+ * Set the text of the Label. Automaticaly update the Label to use the new text
+ * @param text (String) : the new text to display
+ */
+ public void setText(String text) {
+ this.text = text;
+ if(this.texture != null)this.texture.destroy();
+ this.texture = Texture.loadFont(text,color,font,size);
+ }
+
+
+
+ /**
+ * Return the x coordonnate of the Label (upper left corner)
+ * @return x (float) : the x coordonnate of the Label
+ */
+ public int getX() {
+ return x;
+ }
+
+ /**
+ * Set the x coordonnate of the Label (upper left corner)
+ * @param x (float) : the new x coordonnate of the Label
+ */
+ public void setX(int x) {
+ super.setX(x);
+ }
+
+ /**
+ * Return the y coordonnate of the Label (upper left corner)
+ * @return y (float) : the y coordonnate of the Label
+ */
+ public int getY() {
+ return y;
+ }
+
+ /**
+ * Set the y coordonnate of the Label (upper left corner)
+ * @param y (float) : the new y coordonnate of the Label
+ */
+ public void setY(int y) {
+ super.setY(y);
+ }
+
+ /**
+ * Set both x and y coordonnate of the Label
+ * @param x (float) : the new x coordonnate of the Label
+ * @param y (float) : the new y coordonnate of the Label
+ */
+ public void setPosition(int x, int y){
+ this.setX(x);
+ this.setY(y);
+ }
+
+ /**
+ * Return the witdh of the Label
+ * @return witdh (int) : the width
+ */
+ public int getWitdh() {
+ return super.width;
+ }
+
+ /**
+ * Return the height of the Label
+ * @return height (int) : the height
+ */
+ public int getHeight() {
+ return super.height;
+ }
+
+ public void destroy(){
+ GL15.glDeleteBuffers(vbo);
+ texture.destroy();
+ }
+
+ /**
+ * make the image transparent
+ * @param obj_img (BufferedImage) : the BufferedImage to make transparent
+ */
+/* private void makeTransparent(BufferedImage obj_img){
+ byte alpha = (byte)255;
+ alpha %= 0xff;
+ for (int cx=0;cx> 16) & 0xFF)); // Red component
- buffer.put((byte) ((pixel >> 8) & 0xFF)); // Green component
- buffer.put((byte) (pixel & 0xFF)); // Blue component
- buffer.put((byte) ((pixel >> 24) & 0xFF)); // Alpha component. Only for RGBA
- }
- }
-
- buffer.flip(); //FOR THE LOVE OF GOD DO NOT FORGET THIS
-
- // You now have a ByteBuffer filled with the color data of each pixel.
- // Now just create a texture ID and bind it. Then you can load it using
- // whatever OpenGL method you want, for example:
-
- int textureID = glGenTextures(); //Generate texture ID
- glBindTexture(GL_TEXTURE_2D, textureID); //Bind texture ID
-
- //Setup wrap mode
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
-
- //Setup texture scaling filtering
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
- //Send texel data to OpenGL
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
-
- glBindTexture(GL_TEXTURE_2D, 0);
-
- this.label = new Image(xC, yC, image.getWidth(), image.getHeight(), textureID);
- }
-
- /**
- * Default constructor of a Label. Call the full constructor -> Label("", 100, 100, Color.white, "Arial", 30)
- */
- public Label(){
- this("");
- }
-
- /**
- * Construct a Label from the text param and default statement.
- * Call the full constructor -> Label(text, 100, 100, Color.white, "Arial", 30)
- * @param text (String) : the text to print
- */
- public Label(String text){
- this(text, 100, 100, Color.white, "Arial", 30);
- }
-
- /**
- * Return the actual Color of the Label
- * @return color (java.awt.Color) : the Color of the Label
- */
- public Color getColor() {
- return color;
- }
-
- /**
- * Set the Color of the Label. Automaticaly update the Label to use the new Color
- * @param color (java.awt.Color) : the new Color of the Label
- */
- public void setColor(Color color) {
- this.color = color;
-
- Font f_font = new Font(font, Font.PLAIN, size);
-
- // to get the width of the text
- BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
- FontMetrics fm = img.getGraphics().getFontMetrics(f_font);
-
- this.witdh = fm.stringWidth(this.text);
- this.height = fm.getHeight();
-
- final BufferedImage image = new BufferedImage(this.witdh, this.height, BufferedImage.TYPE_INT_ARGB);
-// makeTransparent(image);
-
- Graphics g = image.getGraphics();
- g.setFont(f_font);
- g.setColor(this.color);
- g.drawString(this.text, 0, size);
- g.dispose();
-
- int[] pixels = new int[image.getWidth() * image.getHeight()];
- image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());
-
- ByteBuffer buffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * BYTES_PER_PIXEL); //4 for RGBA, 3 for RGB
-
- for(int y = 0; y < image.getHeight(); y++){
- for(int x = 0; x < image.getWidth(); x++){
- int pixel = pixels[y * image.getWidth() + x];
- buffer.put((byte) ((pixel >> 16) & 0xFF)); // Red component
- buffer.put((byte) ((pixel >> 8) & 0xFF)); // Green component
- buffer.put((byte) (pixel & 0xFF)); // Blue component
- buffer.put((byte) ((pixel >> 24) & 0xFF)); // Alpha component. Only for RGBA
- }
- }
-
- buffer.flip(); //FOR THE LOVE OF GOD DO NOT FORGET THIS
-
- // You now have a ByteBuffer filled with the color data of each pixel.
- // Now just create a texture ID and bind it. Then you can load it using
- // whatever OpenGL method you want, for example:
-
- int textureID = glGenTextures(); //Generate texture ID
- glBindTexture(GL_TEXTURE_2D, textureID); //Bind texture ID
-
- //Setup wrap mode
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
-
- //Setup texture scaling filtering
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
- //Send texel data to OpenGL
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
-
- glBindTexture(GL_TEXTURE_2D, 0);
-
- this.label = new Image(this.x, this.y, image.getWidth(), image.getHeight(), textureID);
- }
-
- /**
- * Return the text of the Label
- * @return text (String) : the text of the Label
- */
- public String getText() {
- return text;
- }
-
- /**
- * Set the text of the Label. Automaticaly update the Label to use the new text
- * @param text (String) : the new text to display
- */
- public void setText(String text) {
- this.text = text;
-
- Font f_font = new Font(font, Font.PLAIN, size);
-
- // to get the width of the text
- BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
- FontMetrics fm = img.getGraphics().getFontMetrics(f_font);
-
- this.witdh = fm.stringWidth(this.text);
- this.height = fm.getHeight();
-
- final BufferedImage image = new BufferedImage(this.witdh, this.height, BufferedImage.TYPE_INT_ARGB);
-// makeTransparent(image);
-
- Graphics g = image.getGraphics();
- g.setFont(f_font);
- g.setColor(this.color);
- g.drawString(this.text, 0, size);
- g.dispose();
-
- int[] pixels = new int[image.getWidth() * image.getHeight()];
- image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());
-
- ByteBuffer buffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * BYTES_PER_PIXEL); //4 for RGBA, 3 for RGB
-
- for(int y = 0; y < image.getHeight(); y++){
- for(int x = 0; x < image.getWidth(); x++){
- int pixel = pixels[y * image.getWidth() + x];
- buffer.put((byte) ((pixel >> 16) & 0xFF)); // Red component
- buffer.put((byte) ((pixel >> 8) & 0xFF)); // Green component
- buffer.put((byte) (pixel & 0xFF)); // Blue component
- buffer.put((byte) ((pixel >> 24) & 0xFF)); // Alpha component. Only for RGBA
- }
- }
-
- buffer.flip(); //FOR THE LOVE OF GOD DO NOT FORGET THIS
-
- // You now have a ByteBuffer filled with the color data of each pixel.
- // Now just create a texture ID and bind it. Then you can load it using
- // whatever OpenGL method you want, for example:
-
- int textureID = glGenTextures(); //Generate texture ID
- glBindTexture(GL_TEXTURE_2D, textureID); //Bind texture ID
-
- //Setup wrap mode
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
-
- //Setup texture scaling filtering
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
- //Send texel data to OpenGL
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
-
- glBindTexture(GL_TEXTURE_2D, 0);
-
- this.label = new Image(this.x, this.y, image.getWidth(), image.getHeight(), textureID);
- }
-
- /**
- * Return the x coordonnate of the Label (upper left corner)
- * @return x (float) : the x coordonnate of the Label
- */
- public float getX() {
- return x;
- }
-
- /**
- * Set the x coordonnate of the Label (upper left corner)
- * @param x (float) : the new x coordonnate of the Label
- */
- public void setX(float x) {
- this.x = x;
- label.setX(x);
- }
-
- /**
- * Return the y coordonnate of the Label (upper left corner)
- * @return y (float) : the y coordonnate of the Label
- */
- public float getY() {
- return y;
- }
-
- /**
- * Set the y coordonnate of the Label (upper left corner)
- * @param y (float) : the new y coordonnate of the Label
- */
- public void setY(float y) {
- this.y = y;
- label.setY(y);
- }
-
- /**
- * Set both x and y coordonnate of the Label
- * @param x (float) : the new x coordonnate of the Label
- * @param y (float) : the new y coordonnate of the Label
- */
- public void setPosition(float x, float y){
- this.setX(x);
- this.setY(y);
- }
-
- /**
- * Return the Image of the Label
- * @return label (Image) : the Image of the Label
- */
- public Image getLabel(){
- return this.label;
- }
-
- /**
- * Return the witdh of the Label
- * @return witdh (int) : the width
- */
- public int getWitdh() {
- return witdh;
- }
-
- /**
- * Return the height of the Label
- * @return height (int) : the height
- */
- public int getHeight() {
- return height;
- }
-
- /**
- * make the image transparent
- * @param obj_img (BufferedImage) : the BufferedImage to make transparent
- */
-/* private void makeTransparent(BufferedImage obj_img){
- byte alpha = (byte)255;
- alpha %= 0xff;
- for (int cx=0;cx> 16) & 0xFF)); // Red component
+ buffer.put((byte) ((pixel >> 8) & 0xFF)); // Green component
+ buffer.put((byte) (pixel & 0xFF)); // Blue component
+ buffer.put((byte) ((pixel >> 24) & 0xFF)); // Alpha component. Only for RGBA
+ }
+ }
+
+ buffer.flip(); //FOR THE LOVE OF GOD DO NOT FORGET THIS
+
+ // You now have a ByteBuffer filled with the color data of each pixel.
+ // Now just create a texture ID and bind it. Then you can load it using
+ // whatever OpenGL method you want, for example:
+
+ int textureID = glGenTextures(); //Generate texture ID
+ glBindTexture(GL_TEXTURE_2D, textureID); //Bind texture ID
+
+ //Setup wrap mode
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
+
+ //Setup texture scaling filtering
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+
+ //Send texel data to OpenGL
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
+
+ glBindTexture(GL_TEXTURE_2D, 0);
+ System.out.println("Texture loaded ! " + width + "x" + height + " id:" + textureID);
+
+ return new Texture(image.getWidth(),image.getHeight(),textureID);
+ }
public static Texture loadTexture(String path){
try {
@@ -60,8 +123,6 @@ public class Texture {
glBindTexture(GL_TEXTURE_2D, 0);
- System.out.println("Texture loaded ! " + width + "x" + height + " id:" + id);
-
return new Texture(width, height, id);
} catch (IOException e) {
e.printStackTrace();
@@ -82,6 +143,7 @@ public class Texture {
}
public void bind(){
+ if(!glIsEnabled(GL_TEXTURE_2D))glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, id);
}
diff --git a/src/globalgamejam/tiles/Tile.java b/src/globalgamejam/tiles/Tile.java
index 87faea3..dbd6e63 100644
--- a/src/globalgamejam/tiles/Tile.java
+++ b/src/globalgamejam/tiles/Tile.java
@@ -44,13 +44,6 @@ public abstract class Tile {
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
-
- GL20.glEnableVertexAttribArray(Shaders.MAIN_SHADERS.getAttribLocation("vert"));
- GL20.glVertexAttribPointer(Shaders.MAIN_SHADERS.getAttribLocation("vert"), 2, GL11.GL_FLOAT, false, (2+2)*4, 0);
-
- GL20.glEnableVertexAttribArray(Shaders.MAIN_SHADERS.getAttribLocation("vertTexCoord"));
- GL20.glVertexAttribPointer(Shaders.MAIN_SHADERS.getAttribLocation("vertTexCoord"), 2, GL11.GL_FLOAT, true, (2+2)*4, 2*4);
-
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}
@@ -62,10 +55,17 @@ public abstract class Tile {
Shaders.MAIN_SHADERS.uniform("projection", DisplayManager.projection);
Shaders.MAIN_SHADERS.uniform("color", this.color);
- GL13.glActiveTexture(GL13.GL_TEXTURE0);
+// GL13.glActiveTexture(GL13.GL_TEXTURE0);
texture.bind();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
+
+ GL20.glEnableVertexAttribArray(Shaders.MAIN_SHADERS.getAttribLocation("vert"));
+ GL20.glVertexAttribPointer(Shaders.MAIN_SHADERS.getAttribLocation("vert"), 2, GL11.GL_FLOAT, false, (2+2)*4, 0);
+
+ GL20.glEnableVertexAttribArray(Shaders.MAIN_SHADERS.getAttribLocation("vertTexCoord"));
+ GL20.glVertexAttribPointer(Shaders.MAIN_SHADERS.getAttribLocation("vertTexCoord"), 2, GL11.GL_FLOAT, true, (2+2)*4, 2*4);
+
GL11.glDrawArrays(GL11.GL_QUADS, 0, size);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
texture.unbind();