PDA

View Full Version : Textures are black.



ThePLG
05-25-2015, 01:31 PM
Hello OpenGL'ers.

I've been Googling for ages now and I can't see to find my problem. I would really appreciate some help.
I'm altering someone else's code. They used PNG's which are loaded via BufferedImage. I need to load a TGA instead, which is just simply a 18 byte header and BGR codes. I have the textures loaded and running, but I get a black box instead of the texture. I don't even know how to DEBUG this.

Textures are loaded in a ByteBuffer:


final static int datasize = (WIDTH*HEIGHT*3) *2; // Double buffer size for OpenGL // not +18 no header
static ByteBuffer buffer = ByteBuffer.allocateDirect(datasize);

FileInputStream fin = new FileInputStream("/Volumes/RAMDisk/shot00021.tga");
FileChannel inc = fin.getChannel();

inc.position(18); // skip header

buffer.clear(); // prepare for read
int ret = inc.read(buffer);
fin.close();


Called once:


bindTexture(textureID);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);

GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, width, height, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null);
assert(GL11.GL_NO_ERROR == GL11.glGetError());


Called repeatedly:


bindTexture(textureID);

GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, width, height, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, byteBuffer);
assert(GL11.GL_NO_ERROR == GL11.glGetError());

return textureID;


The render code hasn't changed and is based on:


GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, this.vertexCount);


If you require any more additional code to help me with this, I am glad to offer it.

Would really appreciate a helping hand. Thank you!

flagrant2
05-26-2015, 04:40 PM
I'm not sure how that GL11 library works, but speaking as a total greenhorn noob with working textures, I just use fread on an rgb file I pre-converted from png or whatever, then I call glu build 2d mipmaps. Many of the tutorials you find online make use of some fancy library to load a fancy file format like png or jpeg, but if you convert by hand to rgb (using gimp or a converter website) you'll have less opengl to think about, then you can figure out the image libraries later.

Sorry I can't be more helpful about the png.

ThePLG
05-28-2015, 07:15 AM
Thanks for your response flagrant2. I do create the images by hand and as far as I know, I do everything by the books to create the texture, but it simply is black. I will have to do some serious debugging to find out what is wrong, because no one seems to be able to give me tips. Cheers!