|
|
@ -137,11 +137,11 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
GLuint colorBuffer, depthBuffer; |
|
|
|
GLuint fbo = CreateFramebufferObject(colorBuffer, depthBuffer, windowWidth, windowHeight); |
|
|
|
|
|
|
|
glViewport(0, 0, windowWidth, windowHeight); |
|
|
|
|
|
|
|
GL_CALL(glClearColor(0.1f, 0.4f, 0.7f, 1.0f)); |
|
|
|
glEnable(GL_DEPTH_TEST); |
|
|
|
|
|
|
|
glViewport(0,0, windowWidth, windowHeight); |
|
|
|
|
|
|
|
//创建一个单位矩阵和一个投影矩阵,后面用来传递到shader
|
|
|
|
float identify[] = { |
|
|
|
1,0,0,0, |
|
|
@ -171,7 +171,7 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
glUniformMatrix4fv(PLocation, 1, GL_FALSE, glm::value_ptr(projection)); |
|
|
|
glUniformMatrix4fv(NMLocation, 1, GL_FALSE, glm::value_ptr(normalMatrix)); |
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, mainTexture); |
|
|
|
glBindTexture(GL_TEXTURE_2D, colorBuffer); |
|
|
|
glUniform1i(textureLocation, 0); |
|
|
|
|
|
|
|
glUniformMatrix4fv(MLocation, 1, GL_FALSE, glm::value_ptr(model)); |
|
|
@ -182,6 +182,12 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
glUseProgram(0); |
|
|
|
}; |
|
|
|
|
|
|
|
/*使用固定管线绘制一个四边形,并把fbo内容贴上*/ |
|
|
|
glMatrixMode(GL_PROJECTION); |
|
|
|
glLoadMatrixf(glm::value_ptr(projection)); |
|
|
|
glMatrixMode(GL_MODELVIEW); |
|
|
|
glLoadIdentity(); |
|
|
|
|
|
|
|
while (true) { |
|
|
|
if (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)) { |
|
|
|
if (msg.message == WM_QUIT) { |
|
|
@ -191,8 +197,26 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
DispatchMessage(&msg); |
|
|
|
} |
|
|
|
|
|
|
|
//绘制内容到fbo
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
|
|
|
GL_CALL(glClearColor(0.1f, 0.4f, 0.7f, 1.0f)); |
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
what(); |
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0); |
|
|
|
|
|
|
|
//把fbo绘制到一个四边形上
|
|
|
|
GL_CALL(glClearColor(0.5f, 0.4f, 0.7f, 1.0f)); |
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
glEnable(GL_TEXTURE_2D); |
|
|
|
glBindTexture(GL_TEXTURE_2D, colorBuffer); |
|
|
|
|
|
|
|
glBegin(GL_QUADS); |
|
|
|
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, -0.5f, -4.0f); |
|
|
|
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.5f, -0.5f, -4.0f); |
|
|
|
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.5f, 0.5f, -4.0f); |
|
|
|
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, 0.5f, -4.0f); |
|
|
|
glEnd(); |
|
|
|
|
|
|
|
SwapBuffers(dc); |
|
|
|
} |
|
|
|
|
|
|
|