Is loading openGL textures right like this?

I started a few months ago with the OpenGL project, which got bigger and bigger ... I started with the crashLanding sample and I use Texture2D.

I also use a singleton class to load my textures, and here is what the texture load looks like:

//Load the background texture and configure it
_textures[kTexture_Background] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"fond.png"]];
glBindTexture(GL_TEXTURE_2D, [_textures[kTexture_Background] name]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

// Load the textures
_textures[kTexture_Batiment] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"batiment_Ext.png"]];
_textures[kTexture_Balcon] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"balcon.png"]];
_textures[kTexture_Devanture] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"devanture.png"]];
_textures[kTexture_Cactus_Troncs] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"cactus-troncs.png"]];
_textures[kTexture_Cactus_Gauche] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"cactus1.png"]];
_textures[kTexture_Cactus_Droit] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"cactus2.png"]];
_textures[kTexture_Pierre] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"pierre.png"]];
_textures[kTexture_Enseigne] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"enseigne.png"]];
_textures[kTexture_Menu] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"saloonIntro.jpg"]];
_textures[kTexture_GameOver] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"gameOver.jpg"]];

for (int i = 0 ; i < kNumTexturesScene ; i ++)
{
    [arrayOfText addObject:[[[NSData alloc] init] autorelease]];    
}
// sort my array
for (int i = 0 ; i < kNumTexturesScene ; i ++)
{
    [arrayOfText replaceObjectAtIndex:i withObject:_textures[i]];
}

[dictionaryOfTexture setObject:[arrayOfText copy] forKey:kTextureDecor];
[arrayOfText removeAllObjects];

etc. for almost 50 images

It works well on 3GS, but sometimes there are problems with 3G.

Am I mistaken with all this?

thank

+3
source share
2 answers

You may have a lack of texture memory, which is not surprising if you think that the class you are using probably overlays the image in 2 sizes.

, .

+1

, :

  • iPhone , 2 - , , , - .
  • iPhone 3 1024x1024 - .
  • ... . , - 3 3 .
  • To achieve this, you need to learn a technique called atlasing texturing.
+3
source

Source: https://habr.com/ru/post/1730374/


All Articles