off-screen rendering for the framebuffer-related texture object of the framebuffer should be so trivial, but I have a problem, I can’t wrap it around me.
My complete program (2D just now!) Is here:
http://pastebin.com/hSvXzhJT
Below are some descriptions.
I create a rgba 512x512 texture object, bind it to FBO. At this point, depth or other rendering buffers, strictly 2D, are not required.
The following extremely simple shaders render this texture:
Vertex shader:
varying vec2 vPos; attribute vec2 aPos; void main (void) { vPos = (aPos + 1) / 2; gl_Position = vec4(aPos, 0.0, 1.0); }
In aPos, it just gets a VBO containing 4 xy coordinates for the square (-1, -1 :: 1, -1 :: 1, 1 :: -1, 1)
So, although the resolution of the framebuffer should theoretically be at 512x512, obviously, the shader maps its “texture” to the “full-screen” screen square, following the cluster paradigm GLs -1.1.
Fragment Shader:
varying vec2 vPos; void main (void) { gl_FragColor = vec4(0.25, vPos, 1); }
Thus, it sets a fully opaque color with red fixed at 0.25 and green / blue, depending on x / y somewhere between 0 and 1.
At this point, my assumption is that a 512x512 texture is rendered, showing only the square of the screen with a full (off) screen -1..1, shaded by a fragment for green / blue from 0..1.
So this is my off-screen setup. On the screen, I have another real visible full-screen quad-core processor with 4 xyz coordinates {-1, -1, 1: 1, -1, 1: 1, 1, 1: -1, 1, 1}. Again, at the moment this is 2D, so no matrices and therefore z is always 1.
This square is drawn by another shader, simply visualizing the given texture, style GL-101 in a text book. In my sample program linked above, I have a simple boolean toggle doRtt, when this value is false (the default), rendering in the text does not work at all, and this shader just shows the use of texture.jpg from the current directory.
This doRtt = false mode shows that the second screen quad-core rendering is “correct” for my current requirements and performs texturing as I wish: it repeats twice vertically and twice horizontally (it will be clamped later, repeat just for testing here), otherwise Scaling with no texture filtering or mipmapping.
Thus, regardless of how the window is resized (and, consequently, the type of port), we always see a full-screen quad-core block with one texture, repeated twice horizontally, twice vertically.
Now, when doRtt = true, the second shader is still doing its job, but the texture never scales properly - or is drawn, I'm not sure, because, unfortunately, we can’t just say: “hey, hl, save this FBO to disk for debugging purposes. "
The RTT shader performs partial rendering (or maybe full, again, can’t be sure what is happening outside the screen ...) Especially when you resize the viewport much less than the default size, you see gaps between the repeats textures, and not all the colors expected from our very simple RTT fragment shader, are really shown.
(A): the 512x512 texture is created correctly, but not correctly matched by my code (but then why with doRtt = false any texture.jpg file using the same simple textured square-shader, showing just fine?)
(B) or: the 512x512 texture does not display correctly, and somehow the rtt frag shader changes its output depending on the resolution of the window - but why? The off-screen square is always -1.1 for x and y, the vertex shader always maps this to the fragment coordinates 0..1, for this simple test, the RTT texture is always at 512x512!
Please note that the off-screen square AND on-screen ATVs never change their coordinates and are always “full-screen” (-1.1 in both dimensions).
Again, it should be that simple. What am I missing?
Features: OpenGL 4.2 (but no 4.2 features are needed for this code!), Nvidia Quadro 5010M, openSuse 12.1 64bit, Golang Weekly 22-Feb-2012.