Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there anything wrong with my texture loading method?
    text
    copied!<p>I'm a noob in openGL and trying to learn as much as possible. I'm using this method to load my openGL textures, loading every .png as RGBA4444. I'm doing anything incorrect ?</p> <pre><code>- (void)loadTexture:(NSString*)nombre { CGImageRef textureImage =[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:nombre ofType:nil]].CGImage; if (textureImage == nil) { NSLog(@"Failed to load texture image"); return; } textureWidth = NextPowerOfTwo(CGImageGetWidth(textureImage)); textureHeight = NextPowerOfTwo(CGImageGetHeight(textureImage)); imageSizeX= CGImageGetWidth(textureImage); imageSizeY= CGImageGetHeight(textureImage); GLubyte *textureData = (GLubyte *)calloc(1,textureWidth * textureHeight * 4); // Por 4 pues cada pixel necesita 4 bytes, RGBA CGContextRef textureContext = CGBitmapContextCreate(textureData, textureWidth,textureHeight,8, textureWidth * 4,CGImageGetColorSpace(textureImage),kCGImageAlphaPremultipliedLast ); CGContextDrawImage(textureContext, CGRectMake(0.0, 0.0, (float)textureWidth, (float)textureHeight), textureImage); //Convert "RRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRGGGGBBBBAAAA" void *tempData = malloc(textureWidth * textureHeight * 2); unsigned int* inPixel32 = (unsigned int*)textureData; unsigned short* outPixel16 = (unsigned short*)tempData; for(int i = 0; i &lt; textureWidth * textureHeight ; ++i, ++inPixel32) *outPixel16++ = ((((*inPixel32 &gt;&gt; 0) &amp; 0xFF) &gt;&gt; 4) &lt;&lt; 12) | // R ((((*inPixel32 &gt;&gt; 8) &amp; 0xFF) &gt;&gt; 4) &lt;&lt; 8) | // G ((((*inPixel32 &gt;&gt; 16) &amp; 0xFF) &gt;&gt; 4) &lt;&lt; 4) | // B ((((*inPixel32 &gt;&gt; 24) &amp; 0xFF) &gt;&gt; 4) &lt;&lt; 0); // A free(textureData); textureData = tempData; CGContextRelease(textureContext); glGenTextures(1, &amp;textures[0]); glBindTexture(GL_TEXTURE_2D, textures[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 , textureData); free(textureData); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } </code></pre> <p>And this is my dealloc method:</p> <pre><code>- (void)dealloc { glDeleteTextures(1,textures); [super dealloc]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload