iphone - How to disable or configure clipping when rendering to texture using FBO in OpenGL? -
i have question way fbo clips visible scene. happens in iphone's opengl es.
i'm rendering in 2d , using render-to-texture fbo.
i find when part of scene passes side of rectangle of screen size (480*320) appears clipped fbo generated texture.
why that? how disable or configure it?
i've tried disabling scissor test
ldisable(gl_scissor_test);
i've tried set needed section by
`glenable(gl_scissor_test); glscissor(0, 0, 100, 100);`
i've tried adjust viewport by
glviewport(0,0, 512,512);
it doesn't work needed. instead of extending render area needed 512*512 looks still clips area 480*320 , stretches afterwards 512*512
all these didn't bring needed result.
in code: create texture
gluint textureid; glenable(gl_texture_2d); glenable(gl_blend); glgentextures(1, &textureid); glbindtexture(gl_texture_2d, textureid); gltexparameteri(gl_texture_2d,gl_texture_min_filter,gl_linear); gltexparameteri(gl_texture_2d,gl_texture_mag_filter, gl_nearest); glteximage2d(gl_texture_2d, 0, gl_rgba, 512, 512, 0, gl_rgba, gl_unsigned_byte, nil);`
create fbo , attach texture it
gluint textureframebuffer; glint prevfbo; glgetintegerv(gl_framebuffer_binding_oes, &prevfbo); // create framebuffer glgenframebuffersoes(1, &textureframebuffer); glbindframebufferoes(gl_framebuffer_oes, textureframebuffer); // attach renderbuffer glframebuffertexture2does(gl_framebuffer_oes, gl_color_attachment0_oes, gl_texture_2d, textureid, 0); if(glcheckframebufferstatusoes(gl_framebuffer_oes) != gl_framebuffer_complete_oes) nslog(@"error - while creating fbo"); // unbind frame buffer glbindframebufferoes(gl_framebuffer_oes, prevfbo);
and then, when draw stuff fbo , render square texture,
static const float textcoords[] = { 0, 1, 1, 1, 0, 0, 1, 0, }; static const float quadverts[] = { 0, 320, 320, 320, 0, 0, 320, 0, }; glenable(gl_texture_2d); glbindtexture(gl_texture_2d, textureid); glvertexpointer(2, gl_float, 0, quadverts); gltexcoordpointer(2, gl_float, 0, textcoords); gldrawarrays(gl_triangle_strip, 0, 4);
to opinion should see square filled stuff had drawn fbo. whereas, see part of – clipped rectangle of size 480x320 @ lower left corner. so, question steel actual
you need change viewport doing:
glviewport(0,0,texturewidth,textureheight);
edit: , don't forget switch normal value after rendering onto fbo.
/// save viewport glint vp[4]; glgetintegerv(gl_viewport, vp); /// restore viewport glviewport(vp[0], vp[1], vp[2], vp[3]);
Comments
Post a Comment