Results 1 to 3 of 3

Thread: Textures are black.

  1. #1
    Newbie Newbie
    Join Date
    May 2015

    Textures are black.

    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:
    Code :
    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 =;

    Called once:
    Code :
    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.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:
    Code :
    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:
    Code :
    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!

  2. #2
    Junior Member Newbie
    Join Date
    May 2015
    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.

  3. #3
    Newbie Newbie
    Join Date
    May 2015
    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!

Similar Threads

  1. All textures are black
    By neon29 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-18-2016, 01:38 PM
  2. OpenGL 3.3 textures only black
    By toyowski in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 11-03-2015, 02:37 AM
  3. Textures show up black
    By AlexClarke in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-04-2013, 01:04 PM
  4. Textures just black in GL 4
    By TraxMate in forum OpenGL: Windows
    Replies: 4
    Last Post: 10-30-2011, 09:40 PM
  5. Why are my textures black?
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-14-2000, 04:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean