title: Texture rendering appears Dull (openGL ES 2.0 iOS)
body: <p>Ive just started with openGLES2.0 on iOS and im trying to render a texture onto screen. </p>
  
  <p>The problem is that the texture appears different (dull and almost monochromatic) as compared to the real image it is supposed to render. In a sense the true colors of the texture image isnt reflected while rendering using openGL</p>
  
  <p>The shader program is quite simple:</p>
  
  <p>Fragment Shader</p>
  
  <pre><code>varying lowp vec4 DestinationColor;
  varying lowp vec2 TexCoordOut; 
  uniform sampler2D Texture; 
  
  void main(void) {
      gl_FragColor = texture2D(Texture, TexCoordOut); 
  }
  </code></pre>
  
  <p>Vertex Shader</p>
  
  <pre><code>attribute vec4 Position; 
  
  
  uniform mat4 Projection;
  uniform mat4 Modelview;
  
  attribute vec2 TexCoordIn;
  varying vec2 TexCoordOut; 
  
  void main(void) { 
  
      gl_Position = Projection * Modelview * Position;
      TexCoordOut = TexCoordIn;
  }
  </code></pre>
  
  <p>The same texturing worked fine on openGL ES 1.0, with the colors showing up correctly!</p>
  
  <p>EDIT:</p>
  
  <p>OpenGL context setup Code:</p>
  
  <pre><code>- (void)setupContext {   
      EAGLRenderingAPI api = kEAGLRenderingAPIOpenGLES2;
      _context = [[EAGLContext alloc] initWithAPI:api];
  
      if (!_context) {
          DLog(@"Failed to initialize OpenGLES 2.0 context");
          exit(1);
      }
  
      if (![EAGLContext setCurrentContext:_context]) {
          DLog(@"Failed to set current OpenGL context");
          exit(1);
       }
  }
  </code></pre>
  
  <p>Texture Loading Code:</p>
  
  <pre><code>- (GLuint)setupTexture:(UIImage *)image {
      glGenTextures(1, &amp;Texture1);
      glBindTexture(GL_TEXTURE_2D, Texture1);
      glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
      glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  
      GLuint width = CGImageGetWidth(image.CGImage);
      GLuint height = CGImageGetHeight(image.CGImage);
      CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
      void *imageData = malloc( height * width * 4 );
      CGContextRef imgContext = CGBitmapContextCreate( imageData, width, height, 8, 4 *   width, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big );
      CGContextTranslateCTM (imgContext, 0, height);
      CGContextScaleCTM (imgContext, 1.0, -1.0);
      CGContextSetBlendMode(imgContext, kCGBlendModeCopy);
      CGColorSpaceRelease( colorSpace );
      CGContextClearRect( imgContext, CGRectMake( 0, 0, width, height ) );
      CGContextTranslateCTM( imgContext, 0, height - height );
      CGContextDrawImage( imgContext, CGRectMake( 0, 0, width, height ), image.CGImage );
  
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
  
      CGContextRelease(imgContext);
  
      free(imageData);
  
  return Texture1;
  </code></pre>
  
  <p>}</p>
  
  <p>SECOND EDIT:
  Layer Setup</p>
  
  <pre><code> - (void)setupLayer {
      _eaglLayer = (CAEAGLLayer*) self.layer;
      _eaglLayer.opaque = YES;
      _eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                  [NSNumber numberWithBool:NO],  kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
  
   }
  </code></pre>
  
  <p>Ive added this piece code to the layer setup. Still no luck!</p>