Moved to a different thread as this is actually a different issue. The code provided is mine. This work is licensed under MIT.
main_class class:
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL12.*;
import static org.lwjgl.opengl.GL21.*;
import static org.lwjgl.opengl.GL42.*;
import static org.lwjgl.system.MemoryUtil.*;
import static org.lwjgl.glfw.GLFW.*;
import org.lwjgl.opengl.GL;
import org.lwjgl.glfw.GLFWImage;
/*
* Created by Cinder SD on 2/19/2017.
*/
public class main_class implements Runnable {
private final resource_parser_01 resource_04 = resource_parser_01.loads_images("res\\roguelike_cave_pack\\icon_04.png");
private final resource_parser_01 resource_06 = resource_parser_01.loads_images("res\\roguelike_cave_pack\\icon_06.png");
private int texture_ID;
public boolean running = true;
private long window;
public static void main(String args[]) {
main_class run = new main_class();
run.start();
}
private void start() {
Thread thread_00 = new Thread(this, "Dungeons Heart");
thread_00.start(); running = true;
}
private void init() {
if (!glfwInit()) System.out.println("Could not initialise opengl4.5. [FWERROR]");
glfwWindowHint(GLFW_RESIZABLE, 0);
glfwWindowHint(GLFW_DECORATED, 0);
int wind_width = 1200;
int wind_height = 800;
window = glfwCreateWindow(wind_width, wind_height, "Dungeons Heart", NULL, NULL);
if (window == NULL) System.out.println("Could not create our window. [FWERROR]");
glfwSetWindowPos(window, 100, 100);
glfwShowWindow(window);
glfwMakeContextCurrent(window);
GLFWImage image = GLFWImage.malloc(); GLFWImage.Buffer imagebf = GLFWImage.malloc(2);
image.set(resource_04.get_width(), resource_04.get_heigh(), resource_04.get_image());
imagebf.put(0, image);
image.set(resource_06.get_width(), resource_06.get_heigh(), resource_06.get_image());
imagebf.put(1, image);
glfwSetWindowIcon(window, imagebf);
glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> {
if (action == GLFW_RELEASE)
return;
switch (key) {
case GLFW_KEY_ESCAPE:
glfwSetWindowShouldClose(window, true); running = false;
break;
}
});
glfwSetMouseButtonCallback(window,(window, button, action, mods) -> {
if (action == GLFW_RELEASE)
return;
switch (button) {
case GLFW_MOUSE_BUTTON_1:
System.out.println("MOUSE_1");
break;
case GLFW_MOUSE_BUTTON_2:
System.out.println("MOUSE_2");
break;
case GLFW_MOUSE_BUTTON_3:
System.out.println("MOUSE_3");
break;
}
});
maze_generator.create_maze();
GL.createCapabilities();
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION); glLoadIdentity();
glOrtho(0, wind_width, wind_height, 0, 1, -1);
texture_ID = resource_parser_02.parse_texture(1, 1);
}
private void loop() {
while (!glfwWindowShouldClose(window)) {
update();
render();
}
}
private void update() {
glfwPollEvents();
}
private void render() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, texture_ID);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glTexCoord2f(0, 1); glVertex2f(16, 48);
glTexCoord2f(1, 1); glVertex2f(48, 48);
glTexCoord2f(1, 0); glVertex2f(48, 16);
glTexCoord2f(0, 0); glVertex2f(16, 16);
glEnd();
glfwSwapBuffers(window);
}
public void run() {
try {
init();
loop();
} finally { destroy(); }
}
private void destroy() {
glfwDestroyWindow(window);
glfwTerminate();
}
}
resource_parser_01 class:
import static org.lwjgl.stb.STBImage.stbi_load;
import org.lwjgl.system.MemoryStack;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
/*
* Created by Cinder SD on 2/27/2017.
*/
public class resource_parser_01 {
public ByteBuffer get_image() {
return this.image;
}
public int get_width() {
return this.width;
}
public int get_heigh() {
return this.heigh;
}
private ByteBuffer image;
private int width, heigh;
resource_parser_01(int width, int heigh, ByteBuffer image) {
this.image = image;
this.heigh = heigh;
this.width = width;
}
public static resource_parser_01 loads_images(String path) {
ByteBuffer image;
int width, heigh;
try (MemoryStack stack = MemoryStack.stackPush()){
IntBuffer comp = stack.mallocInt(1);
IntBuffer w = stack.mallocInt(1);
IntBuffer h = stack.mallocInt(1);
image = stbi_load(path, w, h, comp, 4);
if (image == null) System.out.println("Could not load image resources. [STERROR]");
width = w.get();
heigh = h.get();
}
return new resource_parser_01(width, heigh, image);
}
}
resource_parser_02 class:
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL12.*;
import static org.lwjgl.opengl.GL21.*;
import static org.lwjgl.opengl.GL42.*;
import java.nio.ByteBuffer;
/*
* Created by Cinder SD on 2/28/2017.
*/
public class resource_parser_02 {
private static resource_parser_01 tex_resources_01 = resource_parser_01.loads_images("res\\sprite1.png");
public static int parse_texture(int row, int col) {
ByteBuffer sprite_sheet = tex_resources_01.get_image();
int texture_ID = glGenTextures();
int width = tex_resources_01.get_width();
int heigh = tex_resources_01.get_heigh();
int xoffset = (col != 1 && col != 29) ? (col - 1) * 32 + 2 : (col - 1) * 32;
int yoffset = (row != 1 && col != 18) ? (row - 1) * 32 + 2 : (row - 1) * 32;
glBindTexture(GL_TEXTURE_2D, texture_ID);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexStorage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, width, heigh);
glTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset, 32, 32, GL_RGBA, GL_UNSIGNED_BYTE, sprite_sheet);
System.out.println("" + texture_ID); return texture_ID;
}
}
Any insight is much appreciated, thank you for your time!