2

Im currently learning Open GL ES in order to build an iOS app. I am trying to add a texture to my model with no success. I downloaded a sample project from

link

and have been examining it. the question I have is: When I run the project unchanged I get the following:

image with working texture

as you can see its a basic cube with a texture. I decided to change the .png file to a different image. but when I did I was met with:

image not rendering texture

I dont know why my .png file is not rendering to the cube?

heres my texture: my texture

and the original: original

Just to confirm Im getting no errors and I have made no change to the code.

geminiCoder
  • 2,918
  • 2
  • 29
  • 50

3 Answers3

3

If you are using non-power-of-two textures you can't use mipmaps and you need to set up you filtering correct.

Filtering:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

Clamp:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

But this comes with a drawback, on 3D-objects the texture quality will be bad if the distance is to far. So stay to power-of-two textures in this case and use mipmaps.

Felix K.
  • 6,201
  • 2
  • 38
  • 71
1

For this particular tutorial you can fix your problem with a texture of square, power-of-two dimensions. The one you posted is 135x134, so you need to convert it to 128X128 or 256x256.

See this post for a related discussion: iphone opengl es 2.0 non power of two

Community
  • 1
  • 1
Ricardo RendonCepeda
  • 3,271
  • 4
  • 23
  • 30
  • 1
    I just converted a 128x128 texture to 128x129, and it is simply gone when I run my project. So try a texture with power-of-two dimensions before anything else. – KK. Jan 15 '13 at 11:29
  • -1 Textures on iOS don't need to be power of two! I use NPOT textures every day! – Felix K. Jan 15 '13 at 11:58
  • That's true, but this is clearly the case with this *beginners* tutorial and the obvious reason for the unexpected result. NPOT textures are a more advanced subject in OpenGL ES. Learn to crawl before you walk and all that. – Ricardo RendonCepeda Jan 15 '13 at 12:06
0

How have you changed your image file? Have you only replaced the file in the folder or included it in the project too? Just in case, you should include the file in the project by dragging in into XCode and either rename it to tile_floor.png, or change the (texture) image file name in the initWithFrame method to whatever it is for your texture file.

If this does not work, then maybe the color format or the bits-per-pixel information in your two image files are different.

KK.
  • 783
  • 8
  • 20
  • I added the image to the project then renamed the images (swapped the names) as you suggested. How do I check the bits-per-pixel? they are both RGB according to the info – geminiCoder Jan 15 '13 at 10:52
  • If the images you are using are the ones you copied here, then this should not be a problem. Both are 24 bpp. (To check, I opened them using GIMP, but get-info on right clicking should do the same). Does running the project after renaming images not work? – KK. Jan 15 '13 at 10:55
  • The tutorial and your images show two textures over each other. Which texture are you replacing. For the moment, remove the fish texture from the code so that you only have to deal with the tile texture. Also remove/comment any code that is dealing with the fish texture, like the alpha blending. – KK. Jan 15 '13 at 11:03
  • Ok. Are you sure you did not change any code? Does the old texture still show properly when you use it? – KK. Jan 15 '13 at 11:11
  • Also, try using some other image as the texture. Maybe the uv's in this one are not right. Normally, the uv's are both in the range (0,1), just like the tutorial assumes. But sometimes they may not be. I once faced a problem with the uv's inverted (so that 0 is 1 and 1 is 0) – KK. Jan 15 '13 at 11:22