Ask for example of rendering to texture and then sample using shader

I have tried to code in such case, render to texture and then sample using shader but failed due to missing something I guess.
Can anyone provide an example of this case, as simple as possible or give a linkage to such source for downloading.

for the render-to-texture. For instance, here's a random hit from the discussion boards on this site: link.

For the sampler-using-shader piece, just glBindTexture the texture handle to a texture unit, set the texture unit number on the sampler2D, sampler2D, or other sampler uniform with glUniform1i, and sample in the shader with texture(), texelFetch(), or whatever your favorite GLSL texture sampling function is.

Note that if you use an old pre-GLSL 1.3 version (via "#version ###" in your shader, or by not even specifying a #version that's >= 130), then your texture sampling functions will have the sampler type in them (e.g. texture2D(), shadow2D(), etcetc.), but in GLSL 1.3 this was all simplified to texture().

Take a good stab at, and if questions, post your code -- we'll help you out. When doing this the first time, don't forget to check for GL errors after each call -- that can find many problems. For instance, call this periodically to see if a GL error was tripped sometime since the last check:

What's the bug? You need to do the analysis and give us some details. What works -- what doesn't -- what have you discovered in trying to find the bug -- etc.

Also, are these shaders you posted for 1) rendering to the texture via FBO, or 2) reading back from it in the shader? They certainly don't go with your drawing code, which does not set any varying texture coordinates -- they only set vertex positions.

What's the bug? You need to do the analysis and give us some details. What works -- what doesn't -- what have you discovered in trying to find the bug -- etc.

Also, are these shaders you posted for 1) rendering to the texture via FBO, or 2) reading back from it in the shader? They certainly don't go with your drawing code, which does not set any varying texture coordinates -- they only set vertex positions.

Well, beyond the fact that it's holiday break and probably fewer folks are reading the forums, I think it has a lot to do with that you don't seem to have tried to figure out the problem yourself at all. Seems like you just pasted some code and asked folks to fix your bug(s). You need to do some digging yourself -- try some things, read, see if you can make progress. Ask specific questions about OpenGL and how to use it -- don't just ask folks to fix your code.

The code you did paste isn't even a stand-alone test prog so the bug could be in code you didn't provide. Also, it uses Cg, whereas most folks here use OpenGL's shading language (GLSL). There is an NVidia Cg/CgFX forum here for questions related to their NVidia's shading language.