I have changed the texture and vertex order, thanks for pointing that out. I have also put the glEnable(GL_TEXTURE_2D) call in the loop, just in case, but it hasn't helped. I have also put in calls to Util.checkGLError() but that hasn't thrown any errors.
I have just checked with the buffer order being to BIG_ENDIAN and LITTLE_ENDIAN and both didn't throw any errors and gave the same result as before.
I shall make a new project with just this functionality and nothing else to try and narrow down the possibilities.
EDIT:
Here is a self contained project which shows everything I am doing. In a hopefully readable fashion. Help would be appreciated, as I still cannot see what is wrong. Only thing I know I'm not sure is right is the position of glBindTexture related to glTexImage2D..
import static org.lwjgl.opengl.GL11.*;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
public class Main
{
public static int screenwidth = 1024;
public static int screenheight = 1024;
private int textureid;
private ByteBuffer texturebuffer;
public void start()
{
try
{
Display.setDisplayModeAndFullscreen(new DisplayMode(screenwidth, screenheight));
Display.create();
}
catch(LWJGLException e)
{
e.printStackTrace();
System.exit(0);
}
//initiate OpenGL
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2, 2, 2, -2, -5, 500);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
setTexture();
glLoadIdentity();
while(!Display.isCloseRequested())
{
if(Display.isActive())
{
render();
}
Display.update();
}
}
public void setTexture() //Should make an entirely yellow texture?
{
textureid = glGenTextures();
texturebuffer = BufferUtils.createByteBuffer(screenwidth*screenheight*3/4);
texturebuffer.order(ByteOrder.nativeOrder());
for(int i=0; i<screenwidth*screenheight/4; i++)
{
texturebuffer.put((byte) 255);
texturebuffer.put((byte) 255);
texturebuffer.put((byte) 0);
}
texturebuffer.flip();
glBindTexture(GL_TEXTURE_2D, textureid);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screenwidth/2, screenheight/2, 0, GL_RGB, GL_UNSIGNED_BYTE, texturebuffer);
}
public void render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1.0f, 0.0f, 1.0f, 1.0f);
glBindTexture(GL_TEXTURE_2D, textureid);
glBegin(GL_QUADS);
glTexCoord2f(0.0f,0.0f);
glVertex3f(-1f,-1f,-10.0f);
glTexCoord2f(0.0f,1.0f);
glVertex3f(1f,-1f,-10.0f);
glTexCoord2f(1.0f,1.0f);
glVertex3f(1f,1f,-10.0f);
glTexCoord2f(1.0f,0.0f);
glVertex3f(-1f,1f,-10.0f);
glEnd();
}
public static void main(String[] args)
{
Main screen = new Main();
screen.start();
}
}