Trouble with Textures

I am trying to do a skyBox, but as soon as I put a texture on it the thing goes wonky! It looks like the base color of the texture is bleeding into the rest of the scene. Here are some pictures of what I mean:

Before Textures (I made the SkyBox gray so the spheres would show up!)

First texture I tried broke in a couple different ways!
Here is the Texture:

Here is the result:

Texture 2:

Result: (The spheres are there I promise!)

Texture 3:

Result:

Here’s the code I use for loading images:


private void loadTextures()
{
    rust = loadTexture("Box.jpg");
    night = loadTexture("cloud-02.jpg");
}

private int loadTexture(String path)
{
    IntBuffer image = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
    IL.ilGenImages(image);
    IL.ilBindImage(image.get(0));
    IL.ilLoadImage(path);
    IL.ilConvertImage(IL.IL_RGB, IL.IL_BYTE);
    ByteBuffer scratch = ByteBuffer.allocateDirect(IL.ilGetInteger(IL.IL_IMAGE_WIDTH) * IL.ilGetInteger(IL.IL_IMAGE_HEIGHT) * 3);
    IL.ilCopyPixels(0, 0, 0, IL.ilGetInteger(IL.IL_IMAGE_WIDTH), IL.ilGetInteger(IL.IL_IMAGE_HEIGHT), 1, IL.IL_RGB, IL.IL_BYTE, scratch);
    
    // Create A IntBuffer For Image Address In Memory
    IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
    GL11.glGenTextures(buf); // Create Texture In OpenGL
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0));
    // Typical Texture Generation Using Data From The Image
     // Linear Filtering
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    // Linear Filtering
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    // Generate The Texture
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, IL.ilGetInteger(IL.IL_IMAGE_WIDTH), 
    IL.ilGetInteger(IL.IL_IMAGE_HEIGHT), 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, scratch);
    return buf.get(0); // Return Image Address In Memory
}

Any idea what I’m doing wrong? ???

Try drawing those eggs with texturing disabled.

Yes, openGL is state machine. It will remember latest texture used and it will be your current texture until you either disable it or enable another texture (for egg).

HAHA Beautiful!!! Thank you!!! ;D

-=EDIT=-
So even though I was not setting and Texture Coords it still effected the scene?! Weird!, BUt disabling textrures worked perfectly!! Thanks again!

Yes, you set the TexCoord, when you were rendering the skybox. As OpenGL is a state-machine is still has the last texcoord in it’s memory and will use it.

Good to know! ;D That’s why I love this place! Everyone is so helpful!! Now I just need to get my posterier in gear and come up with something good to give back!!! :stuck_out_tongue:

The scewed rusty texture output looks like you loaded RGB pixels (the image) into RGBA pixels (the texture).

That’s very possible! I just started playing with GIMP so I am not sure what what’s going on with that yet! I’ll pull it into Photoshop and look at it! Thanks!!

:-[ The trouble was that it was not a power of 2 and mu graphics card didn’t like it! I meant it to be 512x512, but somehow it came out to be 410x410! It was late…Yeah, that’s the ticket!! :wink:

Noe I am having another Texture issue. There is blurring of the texture, I know it has to have something to do with the kind of filtering I am enabling, or not, but I am not sure which one it is. Here is a pic of the problem!

It only happens when viewed from an extreme angle.

You definitly need to mipmap your textures, then apply the correct MIN/MAG filters


boolean useMipmaps = true;

      if(useMipmaps)
      {
         MipMap.gluBuild2DMipmaps(GL_TEXTURE_2D, bpp, dim, dim, format, GL_UNSIGNED_BYTE, bb);
      }
      else
      {
         glTexImage2D(GL_TEXTURE_2D, 0, format, dim, dim, 0, format, GL_UNSIGNED_BYTE, bb);
      }

      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, useMipmaps ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

Very cool! I will look into that!! Thank you! ;D