opengl - how to get original fragment color in fragment shader -
i writing tile based image viewer application using jogl. image divided in grid of tiles. rendering textures each tile based on current zoom scale. each tile rendering code looks following:
double projectedx = ... //will calculate x location of tile on screen double projectedy = ... //will calculate y location of tile on screen double projectedwidth = ... //calculate width of tile based on scale double projectedheight= ... //calculate height of tile based on scale gl.gltranslated(projectedx, projectedy, 0.0); gl.glscaled( scale, scale, 1.0); texture.bing(gl); //here, texture of tile image created in shared context in background. there several texture created 1 each tile. texture.enable(gl); double s2 = iw * (1.0 / texture.getwidth()); double t2 = ih * ( 1.0 / texture.getheight()); //draw texture gl.glbegin( gl2.gl_quads ); gl.gltexcoord2d( 0, 0 ); gl.glvertex2d( 0, 0 ); gl.gltexcoord2d( 0, t2 ); gl.glvertex2d( 0, ih ); gl.gltexcoord2d( s2, t2 ); gl.glvertex2d( iw, ih ); gl.gltexcoord2d( s2, 0 ); gl.glvertex2d( iw, 0 ); gl.glend(); texture.disable(gl);
now, want add fragment shader in viewer implement brightness, white balancing features. that, in fragment shader, first need original pixel color of texture , apply color correction algorithm. not sure how it. how current texture being rendered , current pixel co-ordinates in fragment shader?
you use immediate mode (glbegin, glend, glvertex, ...) inefficient , obsolete. quake 2 uses retained mode.
using immediate mode wouldn't idea if targeted opengl 1.2. moreover, might bothered unfixed , old bugs occurring when mixing shaders rendering mode. numerous drivers emulate dynamic vbos under hood more or less success :s depends on hardware target please use @ least vbos.
use glsl code "color" of pixel coming texture in fragment shader: texture2d(mysampler2d_1, gl_texcoord[0].st);
texture2d built-in function used retrieve particular texel sampler. declare uniform sample2d per texture unit , use glgetuniformlocation + gluniform1. don't forget call glactivetexture , glbindtexture or texture.bind() each unit.
i advise @ if build-in input variables of fragment shader: https://www.opengl.org/wiki/built-in_variable_%28glsl%29#fragment_shader_inputs
gl_sampleid might useful in case.
Comments
Post a Comment