c++ - Rendering a second pass yields a different result -
currently i'm trying render multiple passes different shaders in simple opengl application. here's (simplified) code:
void initscene() { glviewport(0, 0, mwindowwidth, mwindowheight); glmatrixmode(gl_modelview); glloadidentity(); glmatrixmode(gl_projection); glloadidentity(); glortho(0, mwindowwidth, mwindowheight, 0, -1, 1); mframebuffername = createframebuffer(mwindowwidth, mwindowheight); } void drawscene() { glmatrixmode(gl_modelview); glpushmatrix(); if(drawdirectlytoscreen) { // works fine, image fill whole screen // directly draw screen drawfullscreenquad(); } else { // not work. image first pass small quadrat // draw frame buffer instead of screen glbindframebuffer(gl_framebuffer, mframebuffername); drawfullscreenquad(); glbindframebuffer(gl_framebuffer, 0); // ready second pass bindframebuffertextureandactivateanothershader(); // draw screen drawfullscreenquad(); } glpopmatrix(); } void drawfullscreenquad() { glbegin(gl_quads); gltexcoord2f(0.0f, 1.0f); glvertex3f(0.0f, mwindowheight, 0.0f); gltexcoord2f(1.0f, 1.0f); glvertex3f(mwindowwidth, mwindowheight, 0.0f); gltexcoord2f(1.0f, 0.0f); glvertex3f(mwindowwidth, 0.0f, 0.0f); gltexcoord2f(0.0f, 0.0f); glvertex3f(0.0f, 0.0f, 0.0f); glend(); } void createframebuffer(int width, int height) { // generate , bind frame buffer mframebuffername = 0; glgenframebuffers(1, &mframebuffername); glbindframebuffer(gl_framebuffer, mframebuffername); // create , bind render texture glgentextures(1, &msecondpassrendertexture); glbindtexture(gl_texture_2d, msecondpassrendertexture); // give empty image opengl ( last "0" ) glteximage2d(gl_texture_2d, 0, gl_rgb, width, height, 0, gl_rgb, gl_unsigned_byte, null); // set "msecondpassrendertexture" colour attachement #0 glframebuffertexture(gl_framebuffer, gl_color_attachment0, msecondpassrendertexture, 0); // set list of draw buffers. glenum drawbuffers[1] = { gl_color_attachment0 }; gldrawbuffers(1, drawbuffers); // "1" size of drawbuffers }
when rendering 1 pass fine. image covers whole screen. when rendering 2 passes, resulting image cover small square area in top left corner of screen (see attached images).
the problem seems come first pass. texture created in pass wrong (i.e. image in corner, rest of texture black). second pass works correctly (i.e. broken texture drawn correctly whole screen).
so question is: why call drawfullscreenquad() yield different results when
- rendering screen directly
- rendering frame buffer (which has same size window)
Comments
Post a Comment