Problem with tga textures

Started by wallnuss, June 26, 2010, 19:47:46

Previous topic - Next topic

wallnuss

Hi there,

I created a TextureLoader like explaint in the Tutorial http://lwjgl.org/wiki/doku.php/lwjgl/tutorials/textures/tga .
But when I try to display a texture I only get the conture without any color like you can see here (also as attachment) http://img4host.net/upload/262130214c26554d4f951.png
The circle should be withe and the LWJGL logo should also have some colors ;-)
that's my init code
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glPushMatrix();
GL11.glLoadIdentity();
GL11.glOrtho(0, bounds.width, 0,bounds.height, 0, 1); // Left Hand lower corner 0,0 Right Hand upper corner MAX,MAX
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glPushMatrix();
GL11.glLoadIdentity();
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glEnable (GL11.GL_LINE_SMOOTH);
GL11.glEnable (GL11.GL_TEXTURE_2D);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA,GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glClearColor(0.89f, 0.72f, 0.37f, 1.0f); //Hintergrund Farbe Setzen

and here I'm loading the texture
//Load Texture
TextureLoader tl = new TextureLoader();
Texture black = null;
Texture white = null;
try {
	black = tl.loadTexture("data/images/lwjgl_logo_rle.tga");
	white = tl.loadTexture("data/images/white.tga");
	} catch (Exception e) {
		System.out.println("Texture Load failed");
		e.printStackTrace();
	}

and here I'm using the texture
GL11.glEnable(GL11.GL_BLEND);
GL11.glBindTexture(GL11.GL_TEXTURE_2D,white.name);
GL11.glBegin (GL11.GL_QUADS);
GL11.glTexCoord2d (0.0, 0.0);
GL11.glVertex2d (offset_w+(i*wx)-wx/2, offset_h+(j*hx)-hx/2);
GL11.glTexCoord2d (1.0, 0.0);
GL11.glVertex2d (offset_w+(i*wx)+wx/2, offset_h+(j*hx)-hx/2);
GL11.glTexCoord2d (1.0, 1.0);
GL11.glVertex2d (offset_w+(i*wx)+wx/2, offset_h+(j*hx)+hx/2);
GL11.glTexCoord2d (0.0, 1.0);
GL11.glVertex2d (offset_w+(i*wx)-wx/2, offset_h+(j*hx)+hx/2);
GL11.glEnd ();
GL11.glDisable(GL11.GL_BLEND);


I'm totally new to LWJGL and Opengl, do I need to activate some more ogl functions ?

thanks a lot

Valentin

kappa

are your texture sizes powers of two?

wallnuss

Quote from: javalwjgl on June 26, 2010, 19:53:45
are your texture sizes powers of two?

Yes the circle texture is 64x64 px and the lwjgl logo is 512x256 px . And if I don't enable GL11.GL_BLEND the texture is schon as a black quader.

And here is the Code of the Texture Creation.
private Texture loadUncompressedData() throws IOException {
		byte[] TGAHEADER = new byte[6];
		Texture tex = new Texture();
	 
		dis.readFully(TGAHEADER);		
		setTextureInfo(TGAHEADER,tex);
	 
		final byte[] textureData = new byte[tex.width * tex.height * tex.bpp];
	 
		dis.readFully(textureData);
	 
		tex = createTexture(tex, textureData);
	 
		return tex;
	}

private Texture createTexture(Texture tex, byte[] textureData) {		
    	final ByteBuffer textureBuffer = ByteBuffer.allocateDirect(textureData.length).order(ByteOrder.nativeOrder());
 
    	textureBuffer.clear();
    	textureBuffer.put(textureData);
    	textureBuffer.flip();
 
    	final IntBuffer glName = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
 
    	GL11.glGenTextures(glName);
    	tex.name = glName.get(0);
 
    	GL11.glBindTexture(GL11.GL_TEXTURE_2D,tex.name);
 
    	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
 
    	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
    	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
 
        // RGB OR RGBA - We assume that it is at least 24 bit
    	int glColor = tex.bitdepth == 32 ? GL12.GL_BGRA : GL12.GL_BGR;
    	int glColor2 = tex.bitdepth == 32 ? GL11.GL_RGBA : GL11.GL_RGB;
    	GL11.glTexImage2D(GL11.GL_TEXTURE_2D,0,glColor2,tex.width,tex.height,0,glColor,GL11.GL_UNSIGNED_BYTE,textureBuffer);    	
 
    	return tex;
}

Ciardhubh

Did you enable lighting and the polygons are in an unlit area?
Does the TGA loader return correct data? Maybe print the colours to the console to see if the data is correct.

wallnuss

So I found my error, sorry that I did bother you ;-) I just called GL11.glColor3f(0.0f,0.0f,0.0f); global so everything was black ...

nevertheless thanks a lot.


Evil-Devil

Well, at least someone used the tutorial :) *Happy*