Texture rendering appears Dull (openGL ES 2.0 iOS) -
ive started opengles2.0 on ios , im trying render texture onto screen.
the problem texture appears different (dull , monochromatic) compared real image supposed render. in sense true colors of texture image isnt reflected while rendering using opengl
the shader program quite simple:
fragment shader
varying lowp vec4 destinationcolor; varying lowp vec2 texcoordout; uniform sampler2d texture; void main(void) { gl_fragcolor = texture2d(texture, texcoordout); }
vertex shader
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; }
the same texturing worked fine on opengl es 1.0, colors showing correctly!
edit:
opengl context setup code:
- (void)setupcontext { eaglrenderingapi api = keaglrenderingapiopengles2; _context = [[eaglcontext alloc] initwithapi:api]; if (!_context) { dlog(@"failed initialize opengles 2.0 context"); exit(1); } if (![eaglcontext setcurrentcontext:_context]) { dlog(@"failed set current opengl context"); exit(1); } }
texture loading code:
- (gluint)setuptexture:(uiimage *)image { glgentextures(1, &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;
}
second edit: layer setup
- (void)setuplayer { _eagllayer = (caeagllayer*) self.layer; _eagllayer.opaque = yes; _eagllayer.drawableproperties = [nsdictionary dictionarywithobjectsandkeys: [nsnumber numberwithbool:no], keagldrawablepropertyretainedbacking, keaglcolorformatrgba8, keagldrawablepropertycolorformat, nil]; }
ive added piece code layer setup. still no luck!
to preserve colors should initialize opengl 24 or 32 bit color (request config 888 rgb instead of 565 configs). should use 8-bit per channel textures.
does resulting image has green tint? noticeable color distortion in 16-bit color.
Comments
Post a Comment