hi,guy!
there are some quetions about using user-define framebuffer.
i want to render some graphics to a texture,but when i call glClear(GL_COLOR_BUFFER_BIT),that Framebuffer background color becomes white,and texture is disappeared.this result is wrong if i don’t call glClear(GL_COLOR_BUFFER_BIT).i want that user-define framebuffer’background color to be the texture at begin rendering any times,how should i do?do i need to call glFramebufferTexture2D() at any times rendering?thanks!please view the code as following:
glUseProgram(program2);
glBindFramebuffer(GL_FRAMEBUFFER,myFramebuffer);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0,0,600,600);
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texId);
glutWireTeapot(0.5);
//glDrawArrays(GL_QUADS,0,4);
glUseProgram(program);
glUniform1i(UniformDiffuse,0);
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,texId);
glBindFramebuffer(GL_FRAMEBUFFER,0);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0,0,600,600);
glBindVertexArray(arraybuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,indexbuffer);
glDrawArrays(GL_QUADS,0,4);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 0);