Note that there are some explanatory texts on larger screens.

plurals
  1. POattach two images to fbo for mrt rendering
    primarykey
    data
    text
    <p>I want to attach two render targets to a fbo, so I can render to two targets at once. I have one function that accepts two render targets.</p> <pre><code>void render(struct glhexbutton *_this, GLuint target0, GLuint target1) { GLenum buffers[2]; GLfloat vertices[] = { -1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0 }; GLubyte indices[] = { 0, 1, 2, 1, 2, 3 }; GLuint fbo; struct { int x; int y; } position; /*Load variables into shader program*/ glUniform4f(glhexbutton_static.uni_address, 1.0, 1.0, 1.0, 1.0); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, _this-&gt;data.texture); glUniform1i(glhexbutton_static.uni_texture, /*GL_TEXTURE*/0); glBindTexture(GL_TEXTURE_2D, 0); glUseProgram(_this-&gt;data.static_data-&gt;program); /*create fbo and attach render targets*/ glGenFramebuffers(1, &amp;fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, target0, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, target1, 0); /*Set the viewport of the fbo*/ position.x = glutGet(GLUT_WINDOW_WIDTH)*_this-&gt;data.position.relative.x+_this-&gt;data.position.offset.x; position.y = glutGet(GLUT_WINDOW_HEIGHT)*_this-&gt;data.position.relative.y+_this-&gt;data.position.offset.y; glViewport(position.x, position.y, _this-&gt;data.size.width, _this-&gt;data.size.height); buffers[0] = GL_COLOR_ATTACHMENT0; buffers[1] = GL_COLOR_ATTACHMENT1; glDrawBuffers(2, buffers); glEnableVertexAttribArray(_this-&gt;data.static_data-&gt;att_coord); glVertexAttribPointer(_this-&gt;data.static_data-&gt;att_coord, 2, GL_FLOAT, GL_FALSE, 0, vertices); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices); glDisableVertexAttribArray(_this-&gt;data.static_data-&gt;att_coord); glBindFramebuffer(GL_FRAMEBUFFER, 0); glDeleteFramebuffers(GL_FRAMEBUFFER, &amp;fbo); } </code></pre> <p>my vertex shader:</p> <pre><code>#version 330 attribute vec2 coord; varying vec2 f_coord; void main() { gl_Position = vec4(coord, 0.0, 1.0); f_coord = (1.0+coord)/2.0; } </code></pre> <p>my pixel/fragment shader:</p> <pre><code>#version 330 uniform sampler2D texture; uniform vec4 address; varying vec2 f_coord; void main() { gl_FragData[0]=texture2D(texture,f_coord); gl_FragData[1]=address; if(texture2D(texture,f_coord).a == 0.0) discard; } </code></pre> <p>When I call</p> <pre><code>render(glhexbutton, 0, texture); </code></pre> <p>or</p> <pre><code>render(glhexbutton, texture, 0); </code></pre> <p>I just get a black blank screen</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload