|
@ -72,6 +72,33 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
|
|
|
|
|
glewInit(); |
|
|
glewInit(); |
|
|
|
|
|
|
|
|
|
|
|
//init fsqgpu program
|
|
|
|
|
|
GPUProgram originalProgram; |
|
|
|
|
|
originalProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); |
|
|
|
|
|
originalProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/fullscreenquad.fs"); |
|
|
|
|
|
originalProgram.Link(); |
|
|
|
|
|
originalProgram.DetectAttribute("pos"); |
|
|
|
|
|
originalProgram.DetectAttribute("texcoord"); |
|
|
|
|
|
originalProgram.DetectUniform("U_MainTexture"); |
|
|
|
|
|
|
|
|
|
|
|
//init erosion program
|
|
|
|
|
|
GPUProgram erosionProgram; |
|
|
|
|
|
erosionProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); |
|
|
|
|
|
erosionProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/fullscreenquad_erosion.fs"); |
|
|
|
|
|
erosionProgram.Link(); |
|
|
|
|
|
erosionProgram.DetectAttribute("pos"); |
|
|
|
|
|
erosionProgram.DetectAttribute("texcoord"); |
|
|
|
|
|
erosionProgram.DetectUniform("U_MainTexture"); |
|
|
|
|
|
|
|
|
|
|
|
//init dilation program
|
|
|
|
|
|
GPUProgram dilationProgram; |
|
|
|
|
|
dilationProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); |
|
|
|
|
|
dilationProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/fullscreenquad_dilation.fs"); |
|
|
|
|
|
dilationProgram.Link(); |
|
|
|
|
|
dilationProgram.DetectAttribute("pos"); |
|
|
|
|
|
dilationProgram.DetectAttribute("texcoord"); |
|
|
|
|
|
dilationProgram.DetectUniform("U_MainTexture"); |
|
|
|
|
|
|
|
|
//init gpu program
|
|
|
//init gpu program
|
|
|
GPUProgram gpuProgram; |
|
|
GPUProgram gpuProgram; |
|
|
gpuProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/test.vs"); |
|
|
gpuProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/test.vs"); |
|
@ -106,6 +133,17 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
glm::mat4 projectionMatrix = glm::perspective(50.0f, 800.0f / 600.0f, 0.1f, 1000.0f); |
|
|
glm::mat4 projectionMatrix = glm::perspective(50.0f, 800.0f / 600.0f, 0.1f, 1000.0f); |
|
|
glm::mat4 normalMatrix = glm::inverseTranspose(model); |
|
|
glm::mat4 normalMatrix = glm::inverseTranspose(model); |
|
|
|
|
|
|
|
|
|
|
|
//³õʼ»¯fsq
|
|
|
|
|
|
FullScreenQuad fsq; |
|
|
|
|
|
fsq.Init(); |
|
|
|
|
|
|
|
|
|
|
|
//³õʼ»¯FBO
|
|
|
|
|
|
FBO fbo; |
|
|
|
|
|
fbo.AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, GL_RGBA, viewportWidth, viewportHeight); |
|
|
|
|
|
fbo.AttachDepthBuffer("depth", viewportWidth, viewportHeight); |
|
|
|
|
|
fbo.Finish(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ShowWindow(hwnd, SW_SHOW); |
|
|
ShowWindow(hwnd, SW_SHOW); |
|
|
UpdateWindow(hwnd); |
|
|
UpdateWindow(hwnd); |
|
|
|
|
|
|
|
@ -128,6 +166,8 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
glEnable(GL_DEPTH_TEST); |
|
|
glEnable(GL_DEPTH_TEST); |
|
|
glUseProgram(gpuProgram.mProgram); |
|
|
glUseProgram(gpuProgram.mProgram); |
|
|
|
|
|
|
|
|
|
|
|
fbo.Bind(); |
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("P"), 1, GL_FALSE, glm::value_ptr(projectionMatrix)); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("P"), 1, GL_FALSE, glm::value_ptr(projectionMatrix)); |
|
|
glUniform3fv(gpuProgram.GetLocation("U_EyePos"), 1, eyePos); |
|
|
glUniform3fv(gpuProgram.GetLocation("U_EyePos"), 1, eyePos); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(model)); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(model)); |
|
@ -135,11 +175,29 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(normalMatrix)); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(normalMatrix)); |
|
|
obj.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
obj.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
obj.Draw(); |
|
|
obj.Draw(); |
|
|
|
|
|
|
|
|
|
|
|
fbo.Unbind(); |
|
|
|
|
|
|
|
|
glUseProgram(0); |
|
|
glUseProgram(0); |
|
|
glFlush(); |
|
|
glFlush(); |
|
|
|
|
|
|
|
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, fbo.GetBuffer("color")); |
|
|
|
|
|
glUniform1i(originalProgram.GetLocation("U_MainTexture"), 0); |
|
|
|
|
|
|
|
|
|
|
|
glUseProgram(originalProgram.mProgram); |
|
|
|
|
|
fsq.DrawToLeftTop(originalProgram.GetLocation("pos"), originalProgram.GetLocation("texcoord")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glUseProgram(erosionProgram.mProgram); |
|
|
|
|
|
fsq.DrawToRightTop(erosionProgram.GetLocation("pos"), erosionProgram.GetLocation("texcoord")); |
|
|
|
|
|
|
|
|
|
|
|
glUseProgram(dilationProgram.mProgram); |
|
|
|
|
|
fsq.DrawToLeftBottom(dilationProgram.GetLocation("pos"), dilationProgram.GetLocation("texcoord")); |
|
|
|
|
|
|
|
|
SwapBuffers(dc); |
|
|
SwapBuffers(dc); |
|
|
} |
|
|
} |
|
|
return 0; |
|
|
return 0; |