|
|
@ -26,6 +26,44 @@ GLuint CreateVAOWithVBOSettings(std::function<void()> settings) |
|
|
|
return vao; |
|
|
|
} |
|
|
|
|
|
|
|
GLuint CreateFramebufferObject(GLuint & colorBuffer, GLuint & depthBuffer, int width, int height) |
|
|
|
{ |
|
|
|
GLuint fbo; |
|
|
|
glGenFramebuffers(1, &fbo); |
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
|
|
|
|
|
|
|
//colorbuffer
|
|
|
|
glGenTextures(1, &colorBuffer); |
|
|
|
glBindTexture(GL_TEXTURE_2D, colorBuffer); |
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); |
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); |
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
|
|
|
glBindTexture(GL_TEXTURE_2D, 0); |
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorBuffer, 0);//°ó¶¨¸Õ²ÅÉú³ÉµÄtextureµ½GL_COLOR_ATTACHMENT0
|
|
|
|
|
|
|
|
//depthbuffer
|
|
|
|
glGenTextures(1, &depthBuffer); |
|
|
|
glBindTexture(GL_TEXTURE_2D, depthBuffer); |
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); |
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); |
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_RGBA, GL_DEPTH_COMPONENT, nullptr); |
|
|
|
glBindTexture(GL_TEXTURE_2D, 0); |
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthBuffer, 0); |
|
|
|
|
|
|
|
//check
|
|
|
|
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); |
|
|
|
if (status != GL_FRAMEBUFFER_COMPLETE) { |
|
|
|
printf("create framebuffer object fail\n"); |
|
|
|
} |
|
|
|
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0); |
|
|
|
return GLuint(); |
|
|
|
} |
|
|
|
|
|
|
|
char* LoadFileContent(const char *path) { |
|
|
|
FILE* pFile = fopen(path, "rb"); |
|
|
|
if (pFile) { |
|
|
|