|
|
|
|
@@ -148,6 +148,48 @@ GLuint LoadShaders(const char * vertex_file_path,const char * fragment_file_path
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
// The depth buffer -- OPTIONAL, REMOVE WHEN NOT NEEDED
|
|
|
|
|
GLuint depthrenderbuffer;
|
|
|
|
|
glGenRenderbuffers(1, &depthrenderbuffer);
|
|
|
|
|
glBindRenderbuffer(GL_RENDERBUFFER, depthrenderbuffer);
|
|
|
|
|
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, 1024, 768);
|
|
|
|
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthrenderbuffer);
|
|
|
|
|
|
|
|
|
|
// Set "renderedTexture" as our colour attachement #0
|
|
|
|
|
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexture, 0);
|
|
|
|
|
|
|
|
|
|
// Set the list of draw buffers.
|
|
|
|
|
GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
|
|
|
|
|
glDrawBuffers(1, DrawBuffers); // "1" is the size of DrawBuffers
|
|
|
|
|
|
|
|
|
|
// Always check that our framebuffer is ok
|
|
|
|
|
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Render to our framebuffer
|
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
|
|
|
|
|
glViewport(0, 0, textw, texth);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* args[]) {
|
|
|
|
|
|