[ad_1]
Presumably the issue is with the interior codecs and my understanding of that, however I have been caught some time, acquired this form of approaching working fantastic on a extra straight ahead color picker, however right here I am choosing pos coordinates saved as information at places.
Could be actually grateful for anybody who will help me throguh this.
So I’ve a fbo, a texture2d attachment in shade 0 and primarily I move my vertices (XYZ) (GLfloat) to the vertex shader in location 0 ‘place’.
Since my terrain is a sq. at all times, 100×100 3000×3000 and many others, I solely want the X and Z since they’ll all be distinctive, so I out a vec2 of the place.XZ to the fragment shader after which within the fragment shader I do that on an if assertion
frag
...
structure(location = 0) out vec4 FragColor;
structure(location = 1 )out vec4 FragColor2;
primary...
if (terrainEditMode == 1)
{
FragColor2 = vec4(vecIDs.x, vecIDs.y, 0.1,0.1);
}
I arrange the attachment like this
glGenFramebuffers(1, &terrainPickFBO);
glBindFramebuffer(GL_FRAMEBUFFER, terrainPickFBO);
glGenTextures(1, &terrainPickTexture);
glBindTexture(GL_TEXTURE_2D, terrainPickTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, window_width, window_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, terrainPickTexture, 0);
and skim pixels on the certain fbo
GLuint pickpixelColor[4];
glReadBuffer(GL_COLOR_ATTACHMENT1);
//glReadPixels(xpos, ypos, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixelColor);
glReadPixels(static_cast<GLint>(xpos), static_cast<GLint>(ypos), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pickpixelColor2);
Then render:
glBindFramebuffer(GL_FRAMEBUFFER, terrain.terrainPickFBO);
GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
glDrawBuffers(1, drawBuffers);
terrain.render();
[ad_2]