added WriteTexture function to write rendered pixel into a texture

This commit is contained in:
Benjamin Petsch
2016-09-07 13:17:27 +02:00
parent 4f347a6ef5
commit 08776360c2

View File

@@ -148,6 +148,27 @@ GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path
return ProgramID; return ProgramID;
} }
GLuint WriteTexture(int textw, int texth){
// The framebuffer, which regroups 0, 1, or more textures, and 0 or 1 depth buffer.
GLuint FramebufferName = 0;
glGenFramebuffers(1, &FramebufferName);
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
// The texture we're going to render to
GLuint renderedTexture;
glGenTextures(1, &renderedTexture);
// "Bind" the newly created texture : all future texture functions will modify this texture
glBindTexture(GL_TEXTURE_2D, renderedTexture);
// Give an empty image to OpenGL ( the last "0" )
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, textw, texth, 0,GL_RGB, GL_UNSIGNED_BYTE, 0);
// Poor filtering. Needed !
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
int main(int argc, char* args[]) { int main(int argc, char* args[]) {