My texture only seems to show up as a black/white box depending on whether GL_TEXTURE_2D is enabled.
My code:
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
public class Fighter {
public boolean gameRunning;
private long lastFrame;
private int fps;
private long lastFPS;
private int width, height;
private TextureBank menuTextures = new TextureBank();
public Fighter() {
gameRunning = true;
}
private void init() {
//Display
try {
DisplayMode[] dm = Display.getAvailableDisplayModes();
for(DisplayMode display : dm) {
if(display == Display.getDesktopDisplayMode()) {
Display.setDisplayMode(display);
}
}
Display.setTitle("Initialising...");
Display.setVSyncEnabled(true);
Display.create();
width = Display.getWidth();
height = Display.getHeight();
getDelta();
lastFPS = getTime();
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, width, height, 0, -1, 0);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glAlphaFunc(GL11.GL_GREATER, 0.4f);
GL11.glEnable(GL11.GL_TEXTURE_2D);
if(!menuTextures.loadTexture("title", "inc/images/menu/title.png")) {
System.out.println("Failed.");
}
} catch(LWJGLException e) {
e.printStackTrace();
System.exit(0);
}
}
private void loop() {
while(gameRunning) {
int delta = getDelta();
//INPUT
if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
gameRunning = false;
if(Display.isCloseRequested())
gameRunning = false;
//UPDATE
updateFPS();
//DRAW
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glLoadIdentity();
menuTextures.getTexture("title").bind();
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0.0f, 0.0f);
GL11.glVertex2f((width - 980)/2, 10f);
GL11.glTexCoord2f(1.0f, 0.0f);
GL11.glVertex2f((width + 980)/2, 10f);
GL11.glTexCoord2f(1.0f, 1.0f);
GL11.glVertex2f((width + 980)/2, 250 + 10);
GL11.glTexCoord2f(0.0f, 1.0f);
GL11.glVertex2f((width - 980)/2, 250 + 10);
GL11.glEnd();
Display.update();
Display.sync(60);
}
Display.destroy();
}
public static void main(String[] args) {
System.setProperty("org.lwjgl.opengl.Window.undecorated", "true");
System.setProperty("org.lwjgl.util.Debug", "true");
Fighter game = new Fighter();
game.init();
game.loop();
}
public long getTime() {
return (Sys.getTime() * 1000) / Sys.getTimerResolution();
}
public int getDelta() {
long time = getTime();
int delta = (int) (time - lastFrame);
lastFrame = time;
return delta;
}
public void updateFPS() {
if (getTime() - lastFPS > 1000) {
Display.setTitle("FPS: " + fps + " & Delta: " + getDelta());
fps = 0;
lastFPS += 1000;
}
fps++;
}
}
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
public class TextureBank {
private HashMap<String, Texture> db = new HashMap<String, Texture>();
public boolean loadTexture(String name, String location) {
Texture texture;
try {
if((texture = TextureLoader.getTexture("PNG", new FileInputStream(location))) != null) {
db.put(name, texture);
System.out.println("Inserted image: " + name + " at " + location);
return true;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Failed inserting image: " + name + " at " + location);
return false;
}
public Texture getTexture(String name) {
if(db.containsKey(name))
return db.get(name);
return null;
}
}
Console output:
[LWJGL] Initial mode: 1360 x 768 x 32 @60Hz
[LWJGL] Found 60 displaymodes
[LWJGL] Removed 24 duplicate displaymodes
[LWJGL] MemoryUtil Accessor: AccessorUnsafe
Sat Dec 15 16:49:44 GMT 2012 INFO:Use Java PNG Loader = true
Inserted image: title at inc/images/menu/title.png
Could not locate symbol glEnableClientStateiEXT
Could not locate symbol glDisableClientStateiEXT
Could not locate symbol glGetFloati_vEXT
Could not locate symbol glGetDoublei_vEXT
Could not locate symbol glGetPointeri_vEXT
Could not locate symbol glVertexWeighthNV
Could not locate symbol glVertexAttrib1hNV
Could not locate symbol glVertexAttrib2hNV
Could not locate symbol glVertexAttrib3hNV
Could not locate symbol glVertexAttrib4hNV
Could not locate symbol glVertexAttribs1hvNV
Could not locate symbol glVertexAttribs2hvNV
Could not locate symbol glVertexAttribs3hvNV
Could not locate symbol glVertexAttribs4hvNV
File is a 512x512 PNG and I have no idea what's going on, can anyone help?
Have you tried it without the following:
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glAlphaFunc(GL11.GL_GREATER, 0.4f);
Everything else looks fine to me (although I'm not actually able to try it ATM).
Quote from: Fool Running on December 17, 2012, 14:48:07
Have you tried it without the following:
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glAlphaFunc(GL11.GL_GREATER, 0.4f);
Everything else looks fine to me (although I'm not actually able to try it ATM).
Doesn't affect it. ???
Don't you need to set the texture coordinates / normals?
Also its hard to see what your texture bind code is and how you load a texture
Quote from: abcdef on December 17, 2012, 16:27:21
Don't you need to set the texture coordinates / normals?
Also its hard to see what your texture bind code is and how you load a texture
Either way I bind the texture, whether it's the default OpenGL function or the function I use in this code it doesn't work.
What is this about texture coordinates?
check out
http://nehe.gamedev.net/tutorial/texture_mapping/12038/
should explain the basics there
Quote from: abcdef on December 17, 2012, 16:27:21
Don't you need to set the texture coordinates / normals?
Also its hard to see what your texture bind code is and how you load a texture
He pasted all of his code. It contains the texture coordinate settings and the texture bind code (which is in Slick Utils' Texture class).
Quote from: robtheamazing on December 17, 2012, 17:51:11
Either way I bind the texture, whether it's the default OpenGL function or the function I use in this code it doesn't work.
I was finally able to try the code myself. It works fine for me. However, I didn't have your image so I substituted my own. Have you tried using a different PNG image?
Quote from: Fool Running on December 18, 2012, 13:53:04
Quote from: abcdef on December 17, 2012, 16:27:21
Don't you need to set the texture coordinates / normals?
Also its hard to see what your texture bind code is and how you load a texture
He pasted all of his code. It contains the texture coordinate settings and the texture bind code (which is in Slick Utils' Texture class).
Quote from: robtheamazing on December 17, 2012, 17:51:11
Either way I bind the texture, whether it's the default OpenGL function or the function I use in this code it doesn't work.
I was finally able to try the code myself. It works fine for me. However, I didn't have your image so I substituted my own. Have you tried using a different PNG image?
You're right, it's the PNG.
Now I feel stupid... It was the black text on the black background OH MY GOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOD
Thanks everyone hahaha