|
@ -72,7 +72,16 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
|
|
|
|
|
glewInit(); |
|
|
glewInit(); |
|
|
|
|
|
|
|
|
//combine program
|
|
|
|
|
|
|
|
|
//init fsqgpu program
|
|
|
|
|
|
GPUProgram fsqProgram; |
|
|
|
|
|
fsqProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); |
|
|
|
|
|
fsqProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/fullscreenquad.fs"); |
|
|
|
|
|
fsqProgram.Link(); |
|
|
|
|
|
fsqProgram.DetectAttribute("pos"); |
|
|
|
|
|
fsqProgram.DetectAttribute("texcoord"); |
|
|
|
|
|
fsqProgram.DetectUniform("U_MainTexture"); |
|
|
|
|
|
|
|
|
|
|
|
//gpu program
|
|
|
GPUProgram gpuProgram; |
|
|
GPUProgram gpuProgram; |
|
|
gpuProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/forg.vs"); |
|
|
gpuProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/forg.vs"); |
|
|
gpuProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/forg.fs"); |
|
|
gpuProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/forg.fs"); |
|
@ -140,16 +149,26 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
|
|
|
|
|
glm::mat4 cubeModelMatrix3 = glm::translate<float>(-0.4f, 0.0f, -20.0f) * glm::rotate(-30.0f, 1.0f, 1.0f, 1.0f); |
|
|
glm::mat4 cubeModelMatrix3 = glm::translate<float>(-0.4f, 0.0f, -20.0f) * glm::rotate(-30.0f, 1.0f, 1.0f, 1.0f); |
|
|
glm::mat4 cubeNormalMatrix3 = glm::inverseTranspose(cubeModelMatrix); |
|
|
glm::mat4 cubeNormalMatrix3 = glm::inverseTranspose(cubeModelMatrix); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//glm::mat4 viewMatrix = glm::lookAt(glm::vec3(1.0f, 0.5f, -10.0f), glm::vec3(0.0f, 0.0f, -1.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
|
|
//glm::mat4 viewMatrix = glm::lookAt(glm::vec3(1.0f, 0.5f, -10.0f), glm::vec3(0.0f, 0.0f, -1.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
|
|
glm::mat4 projectionMatrix = glm::perspective(50.0f, (float)viewportWidth / (float)viewportHeight, 0.1f, 1000.0f); |
|
|
glm::mat4 projectionMatrix = glm::perspective(50.0f, (float)viewportWidth / (float)viewportHeight, 0.1f, 1000.0f); |
|
|
|
|
|
|
|
|
|
|
|
//³õʼ»¯fsq
|
|
|
|
|
|
FullScreenQuad fsq; |
|
|
|
|
|
fsq.Init(); |
|
|
|
|
|
|
|
|
|
|
|
//³õʼ»¯2¸öfbo
|
|
|
|
|
|
FBO fbo[2]; |
|
|
|
|
|
fbo[0].AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, GL_RGBA, viewportWidth, viewportHeight); |
|
|
|
|
|
fbo[0].AttachDepthBuffer("depth", viewportWidth, viewportHeight); |
|
|
|
|
|
fbo[0].Finish(); |
|
|
|
|
|
fbo[1].AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, GL_RGBA, viewportWidth, viewportHeight); |
|
|
|
|
|
fbo[1].AttachDepthBuffer("depth", viewportWidth, viewportHeight); |
|
|
|
|
|
fbo[1].Finish(); |
|
|
|
|
|
|
|
|
ShowWindow(hwnd, SW_SHOW); |
|
|
ShowWindow(hwnd, SW_SHOW); |
|
|
UpdateWindow(hwnd); |
|
|
UpdateWindow(hwnd); |
|
|
|
|
|
|
|
|
glClearColor(0.6f, 0.6f, 0.6f, 1.0f); |
|
|
|
|
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
|
|
MSG msg; |
|
|
MSG msg; |
|
|
while (true) |
|
|
while (true) |
|
|
{ |
|
|
{ |
|
@ -163,7 +182,6 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
DispatchMessage(&msg); |
|
|
DispatchMessage(&msg); |
|
|
} |
|
|
} |
|
|
glEnable(GL_DEPTH_TEST); |
|
|
glEnable(GL_DEPTH_TEST); |
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
|
|
glUseProgram(gpuProgram.mProgram); |
|
|
glUseProgram(gpuProgram.mProgram); |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -184,25 +202,64 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
glUniform1f(gpuProgram.GetLocation("U_FogStart"), fogStart); |
|
|
glUniform1f(gpuProgram.GetLocation("U_FogStart"), fogStart); |
|
|
glUniform1f(gpuProgram.GetLocation("U_FogEnd"), fogEnd); |
|
|
glUniform1f(gpuProgram.GetLocation("U_FogEnd"), fogEnd); |
|
|
glUniform4fv(gpuProgram.GetLocation("U_FogColor"), 1, fogColor); |
|
|
glUniform4fv(gpuProgram.GetLocation("U_FogColor"), 1, fogColor); |
|
|
glUniform1f(gpuProgram.GetLocation("U_FogDensity"), fogDensity); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fbo[0].Bind(); |
|
|
|
|
|
fogDensity = 0.11; |
|
|
|
|
|
glUniform1f(gpuProgram.GetLocation("U_FogDensity"), fogDensity); |
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(cubeModelMatrix)); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(cubeModelMatrix)); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(cubeNormalMatrix)); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(cubeNormalMatrix)); |
|
|
cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
cube.Draw(); |
|
|
cube.Draw(); |
|
|
|
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(cubeModelMatrix2)); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(cubeModelMatrix2)); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(cubeNormalMatrix2)); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(cubeNormalMatrix2)); |
|
|
cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
cube.Draw(); |
|
|
cube.Draw(); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(cubeModelMatrix3)); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(cubeNormalMatrix3)); |
|
|
|
|
|
cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
|
|
|
cube.Draw(); |
|
|
|
|
|
fbo[0].Unbind(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fbo[1].Bind(); |
|
|
|
|
|
fogDensity = 0.31; |
|
|
|
|
|
glUniform1f(gpuProgram.GetLocation("U_FogDensity"), fogDensity); |
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(cubeModelMatrix)); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(cubeNormalMatrix)); |
|
|
|
|
|
cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
|
|
|
cube.Draw(); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(cubeModelMatrix2)); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(cubeNormalMatrix2)); |
|
|
|
|
|
cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
|
|
|
cube.Draw(); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(cubeModelMatrix3)); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(cubeModelMatrix3)); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(cubeNormalMatrix3)); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(cubeNormalMatrix3)); |
|
|
cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
cube.Draw(); |
|
|
cube.Draw(); |
|
|
|
|
|
fbo[1].Unbind(); |
|
|
glUseProgram(0); |
|
|
glUseProgram(0); |
|
|
glFlush(); |
|
|
glFlush(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glClearColor(0.6f, 0.6f, 0.6f, 1.0f); |
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
|
|
|
|
|
|
|
|
glUseProgram(fsqProgram.mProgram); |
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, fbo[0].GetBuffer("color")); |
|
|
|
|
|
glUniform1i(fsqProgram.GetLocation("U_MainTexture"), 0); |
|
|
|
|
|
fsq.DrawToLeftTop(fsqProgram.GetLocation("pos"), fsqProgram.GetLocation("texcoord")); |
|
|
|
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, fbo[1].GetBuffer("color")); |
|
|
|
|
|
glUniform1i(fsqProgram.GetLocation("U_MainTexture"), 0); |
|
|
|
|
|
fsq.DrawToRightTop(fsqProgram.GetLocation("pos"), fsqProgram.GetLocation("texcoord")); |
|
|
|
|
|
|
|
|
|
|
|
glUseProgram(0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SwapBuffers(dc); |
|
|
SwapBuffers(dc); |
|
|
} |
|
|
} |
|
|
return 0; |
|
|
return 0; |