Ok, I have something simple that shows breakage.
Here's a simple single file test that shows a blank white texture in the bottom left corner of the window, the rest in green.
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GLUtil;
import org.lwjgl.system.MemoryUtil;
import org.lwjgl.system.libffi.Closure;
import java.nio.ByteBuffer;
import static org.lwjgl.BufferUtils.createByteBuffer;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
/**
* Created by haplo on 12/20/2015.
*/
public class LWJGLTextureTest {
long windowID;
private GLFWErrorCallback errorCallback;
Closure debugProc;
int texID;
int texWidth;
int texHeight;
final long NULL = MemoryUtil.NULL;
public LWJGLTextureTest(){
// init
if (glfwInit() != GLFW_TRUE) {
throw new RuntimeException("GLFW failed to init!");
}
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
this.windowID = glfwCreateWindow(640, 480, "LWJGLTextureTest", NULL, NULL);
glfwMakeContextCurrent(windowID);
glfwSwapInterval(1);
GL.createCapabilities();
glfwSetErrorCallback(errorCallback = GLFWErrorCallback.createPrint(System.err));
debugProc = GLUtil.setupDebugMessageCallback();
initTexture();
}
private void initTexture(){
texWidth = getPow2(640);
texHeight = getPow2(480);
byte[] rawData = new byte[texWidth * texHeight * 4]; // here 4 is a colormodel constant for RGBA
for (int i = 0; i < rawData.length; i++){
rawData[i] = -1;
}
ByteBuffer imgData = createByteBuffer(rawData.length).put(rawData);
imgData.flip();
glEnable(GL_TEXTURE_2D);
texID = glGenTextures();
glBindTexture(GL_TEXTURE_2D, texID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, imgData);
glDisable(GL_TEXTURE_2D);
}
public void run(){
glClearColor(0, 1, 0, 1); // green
while (glfwWindowShouldClose(windowID) == GLFW_FALSE) {
// clear the window buffer and then draw the texture to it.
glClear(GL_COLOR_BUFFER_BIT);
drawTex();
// update the window
glfwSwapBuffers(windowID);
glfwPollEvents();
}
// clean up
glDeleteTextures(texID);
glfwDestroyWindow(windowID);
}
private void drawTex(){
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texID);
// Set Projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, 640, 480);
glOrtho(0, 640, 0, 480, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// draw at half scale to show the background clear color
int swidth = 320;
int sheight = 240;
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex3f(0, 0, 0);
glTexCoord2f(0, texHeight);
glVertex3f(0, sheight, 0);
glTexCoord2f(texWidth, texHeight);
glVertex3f(swidth, sheight, 0);
glTexCoord2f(texWidth, 0);
glVertex3f(swidth, 0, 0);
glEnd();
glDisable(GL_TEXTURE_2D);
}
private int getPow2(int fold) {
int ret = 2;
while (ret < fold) {
ret *= 2;
}
return ret;
}
public static void main(String[] args)
{
LWJGLTextureTest test = new LWJGLTextureTest();
test.run();
}
}
alright that test wasn't valid because I forgot to set up the projection. I'll have to keep hacking until I get something to actually break.