|
|
@ -44,8 +44,8 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
RECT rect; |
|
|
|
rect.left = 0; |
|
|
|
rect.top = 0; |
|
|
|
rect.right = 256; |
|
|
|
rect.bottom = 256; |
|
|
|
rect.right = 512; |
|
|
|
rect.bottom = 512; |
|
|
|
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); |
|
|
|
|
|
|
|
HWND hwnd = CreateWindowEx(NULL, "OpenGL", "RenderWindow", WS_OVERLAPPEDWINDOW, 100, 100, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, hInstance, NULL); |
|
|
@ -72,33 +72,45 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
|
|
|
|
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"); |
|
|
|
|
|
|
|
//¸ß˹ģºý
|
|
|
|
GPUProgram gaussianProgram; |
|
|
|
gaussianProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); |
|
|
|
gaussianProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/fullscreenquad_gaussian.fs"); |
|
|
|
gaussianProgram.Link(); |
|
|
|
gaussianProgram.DetectAttribute("pos"); |
|
|
|
gaussianProgram.DetectAttribute("texcoord"); |
|
|
|
gaussianProgram.DetectUniform("U_MainTexture"); |
|
|
|
//combine program
|
|
|
|
GPUProgram combineProgram1; |
|
|
|
combineProgram1.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); |
|
|
|
combineProgram1.AttachShader(GL_FRAGMENT_SHADER, "res/shader/zpdd.fs"); |
|
|
|
combineProgram1.Link(); |
|
|
|
combineProgram1.DetectAttribute("pos"); |
|
|
|
combineProgram1.DetectAttribute("texcoord"); |
|
|
|
combineProgram1.DetectUniform("U_BaseTexture"); |
|
|
|
combineProgram1.DetectUniform("U_BlendTexture"); |
|
|
|
|
|
|
|
//combine program
|
|
|
|
GPUProgram combineProgram2; |
|
|
|
combineProgram2.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); |
|
|
|
combineProgram2.AttachShader(GL_FRAGMENT_SHADER, "res/shader/zpdd_inverse.fs"); |
|
|
|
combineProgram2.Link(); |
|
|
|
combineProgram2.DetectAttribute("pos"); |
|
|
|
combineProgram2.DetectAttribute("texcoord"); |
|
|
|
combineProgram2.DetectUniform("U_BaseTexture"); |
|
|
|
combineProgram2.DetectUniform("U_BlendTexture"); |
|
|
|
|
|
|
|
//combine program
|
|
|
|
GPUProgram combineProgram3; |
|
|
|
combineProgram3.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); |
|
|
|
combineProgram3.AttachShader(GL_FRAGMENT_SHADER, "res/shader/zpdd_dark.fs"); |
|
|
|
combineProgram3.Link(); |
|
|
|
combineProgram3.DetectAttribute("pos"); |
|
|
|
combineProgram3.DetectAttribute("texcoord"); |
|
|
|
combineProgram3.DetectUniform("U_BaseTexture"); |
|
|
|
combineProgram3.DetectUniform("U_BlendTexture"); |
|
|
|
|
|
|
|
//combine program
|
|
|
|
GPUProgram combineProgram; |
|
|
|
combineProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); |
|
|
|
combineProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/normal_blend.fs"); |
|
|
|
combineProgram.Link(); |
|
|
|
combineProgram.DetectAttribute("pos"); |
|
|
|
combineProgram.DetectAttribute("texcoord"); |
|
|
|
combineProgram.DetectUniform("U_BaseTexture"); |
|
|
|
combineProgram.DetectUniform("U_BlendTexture"); |
|
|
|
GPUProgram combineProgram4; |
|
|
|
combineProgram4.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); |
|
|
|
combineProgram4.AttachShader(GL_FRAGMENT_SHADER, "res/shader/zpdd_light.fs"); |
|
|
|
combineProgram4.Link(); |
|
|
|
combineProgram4.DetectAttribute("pos"); |
|
|
|
combineProgram4.DetectAttribute("texcoord"); |
|
|
|
combineProgram4.DetectUniform("U_BaseTexture"); |
|
|
|
combineProgram4.DetectUniform("U_BlendTexture"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -127,16 +139,9 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
FullScreenQuad fsq; |
|
|
|
fsq.Init(); |
|
|
|
|
|
|
|
//³õʼ»¯FBO
|
|
|
|
FBO fbo[2]; |
|
|
|
fbo[0].AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, GL_RGBA, viewportWidth, viewportHeight); |
|
|
|
fbo[0].AttachDepthBuffer("depth", viewportWidth, viewportHeight); |
|
|
|
fbo[1].AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, GL_RGBA, viewportWidth, viewportHeight); |
|
|
|
fbo[1].AttachDepthBuffer("depth", viewportWidth, viewportHeight); |
|
|
|
|
|
|
|
|
|
|
|
GLuint head = CreateTextureFromFile("res/image/head.png"); |
|
|
|
GLuint grass = CreateTextureFromFile("res/image/grass.png"); |
|
|
|
GLuint head = CreateTextureFromFile("res/image/wood.bmp"); |
|
|
|
GLuint grass = CreateTextureFromFile("res/image/earth.bmp"); |
|
|
|
|
|
|
|
ShowWindow(hwnd, SW_SHOW); |
|
|
|
UpdateWindow(hwnd); |
|
|
@ -161,24 +166,41 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
|
|
|
|
glUseProgram(originalProgram.mProgram); |
|
|
|
glUseProgram(combineProgram1.mProgram); |
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
glBindTexture(GL_TEXTURE_2D, head); |
|
|
|
glUniform1i(originalProgram.GetLocation("U_MainTexture"), 0); |
|
|
|
fsq.DrawToLeftTop(originalProgram.GetLocation("pos"), originalProgram.GetLocation("texcoord")); |
|
|
|
glUniform1i(combineProgram1.GetLocation("U_BaseTexture"), 0); |
|
|
|
glActiveTexture(GL_TEXTURE1); |
|
|
|
glBindTexture(GL_TEXTURE_2D, grass); |
|
|
|
glUniform1i(combineProgram1.GetLocation("U_BlendTexture"), 1); |
|
|
|
fsq.DrawToLeftTop(combineProgram1.GetLocation("pos"), combineProgram1.GetLocation("texcoord")); |
|
|
|
|
|
|
|
glUseProgram(originalProgram.mProgram); |
|
|
|
glUseProgram(combineProgram2.mProgram); |
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
glBindTexture(GL_TEXTURE_2D, head); |
|
|
|
glUniform1i(combineProgram2.GetLocation("U_BaseTexture"), 0); |
|
|
|
glActiveTexture(GL_TEXTURE1); |
|
|
|
glBindTexture(GL_TEXTURE_2D, grass); |
|
|
|
glUniform1i(combineProgram2.GetLocation("U_BlendTexture"), 1); |
|
|
|
fsq.DrawToRightTop(combineProgram2.GetLocation("pos"), combineProgram2.GetLocation("texcoord")); |
|
|
|
|
|
|
|
glUseProgram(combineProgram3.mProgram); |
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
glBindTexture(GL_TEXTURE_2D, head); |
|
|
|
glUniform1i(combineProgram3.GetLocation("U_BaseTexture"), 0); |
|
|
|
glActiveTexture(GL_TEXTURE1); |
|
|
|
glBindTexture(GL_TEXTURE_2D, grass); |
|
|
|
glUniform1i(originalProgram.GetLocation("U_MainTexture"), 0); |
|
|
|
fsq.DrawToRightTop(originalProgram.GetLocation("pos"), originalProgram.GetLocation("texcoord")); |
|
|
|
glUniform1i(combineProgram3.GetLocation("U_BlendTexture"), 1); |
|
|
|
fsq.DrawToLeftBottom(combineProgram3.GetLocation("pos"), combineProgram3.GetLocation("texcoord")); |
|
|
|
|
|
|
|
glUseProgram(combineProgram.mProgram); |
|
|
|
glUseProgram(combineProgram4.mProgram); |
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
glBindTexture(GL_TEXTURE_2D, head); |
|
|
|
glUniform1i(combineProgram.GetLocation("U_BaseTexture"), 0); |
|
|
|
glUniform1i(combineProgram4.GetLocation("U_BaseTexture"), 0); |
|
|
|
glActiveTexture(GL_TEXTURE1); |
|
|
|
glBindTexture(GL_TEXTURE_2D, grass); |
|
|
|
glUniform1i(combineProgram.GetLocation("U_BlendTexture"), 1); |
|
|
|
fsq.DrawToRightBottom(combineProgram.GetLocation("pos"), combineProgram.GetLocation("texcoord")); |
|
|
|
glUniform1i(combineProgram4.GetLocation("U_BlendTexture"), 1); |
|
|
|
fsq.DrawToRightBottom(combineProgram4.GetLocation("pos"), combineProgram4.GetLocation("texcoord")); |
|
|
|
|
|
|
|
glDisable(GL_BLEND); |
|
|
|
glFlush(); |
|
|
|