Hello guys.
I’m having a problem: My texture is rendering plain white. Even the parts of it, which should be transparent are rendered white…
This is the texture it SHOULD render:
This is a screenshot:
This is gl-initialization code: (EDIT: unfolded “setupViewport(…)”)
try {
Display.setDisplayMode(new DisplayMode(
world.getViewPixelWidth(),
world.getViewPixelHeight()));
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
}
glEnable(GL_LINE_SMOOTH);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glClearColor(0.3f, 0.3f, 0.3f, 1f);
glViewport(0, 0, Display.getWidth(), Display.getHeight());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, Display.getWidth(), Display.getHeight(), 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
Display.setVSyncEnabled(true);
Display.setResizable(true);
This is the code, which loads the texture and binds it, simply a Tex.java class:
package org.matheusdev.gol.utils;
import static org.lwjgl.opengl.GL11.GL_RGBA;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_MAG_FILTER;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_MIN_FILTER;
import static org.lwjgl.opengl.GL11.GL_UNSIGNED_BYTE;
import static org.lwjgl.opengl.GL11.glBindTexture;
import static org.lwjgl.opengl.GL11.glEnable;
import static org.lwjgl.opengl.GL11.glGenTextures;
import static org.lwjgl.opengl.GL11.glTexImage2D;
import static org.lwjgl.opengl.GL11.glTexParameteri;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import de.matthiasmann.twl.utils.PNGDecoder;
import de.matthiasmann.twl.utils.PNGDecoder.Format;
/**
* @author matheusdev
*
*/
public class Tex {
public static final Tex NOTEX = new Tex(0);
private static int bound = 0;
public final int id;
public Tex(InputStream resource, int filter) {
int tid = 0;
try {
PNGDecoder decoder = new PNGDecoder(resource);
ByteBuffer bufData = ByteBuffer.allocateDirect(4*decoder.getWidth()*decoder.getHeight());
decoder.decode(bufData, decoder.getWidth()*4, Format.RGBA);
bufData.flip();
glEnable(GL_TEXTURE_2D);
tid = glGenTextures();
if (tid == 0) {
throw new IllegalStateException("glGenTextures() returned 0.");
}
bind();
if (filter != -1) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, bufData);
unbind();
} catch (IOException e) {
e.printStackTrace();
}
id = tid;
}
public Tex(int id) {
this.id = id;
}
public void bind() {
if (id != bound) {
glBindTexture(GL_TEXTURE_2D, id);
bound = id;
}
}
public void unbind() {
NOTEX.bind();
}
}
And finally this is the code to render the texture:
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPushMatrix();
{
gridTex.bind();
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// glTranslatef(xbegin, ybegin, 0);
glColor3f(1f, 1f, 1f);
glBegin(GL_QUADS);
{
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(1, 0);
glVertex2f(512, 0);
glTexCoord2f(1, 1);
glVertex2f(512, 512);
glTexCoord2f(0, 1);
glVertex2f(0, 512);
}
glEnd();
}
glPopMatrix();
I already tested the values, the ByteBuffer upon loading contains. It IS complete, including alpha bytes…
Yes… propably not needed to be mentioned, but I also pressed F5 on the Eclipse Project… (happens pretty often to me but not the source of the problem here).
I dunno what to do