|
|
@ -44,8 +44,8 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
RECT rect; |
|
|
|
rect.left = 0; |
|
|
|
rect.top = 0; |
|
|
|
rect.right = 512; |
|
|
|
rect.bottom = 512; |
|
|
|
rect.right = 800; |
|
|
|
rect.bottom = 600; |
|
|
|
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); |
|
|
@ -73,47 +73,35 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
glewInit(); |
|
|
|
|
|
|
|
//combine program
|
|
|
|
GPUProgram combineProgram1; |
|
|
|
combineProgram1.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); |
|
|
|
combineProgram1.AttachShader(GL_FRAGMENT_SHADER, "res/shader/fullscreenquad.fs"); |
|
|
|
combineProgram1.Link(); |
|
|
|
combineProgram1.DetectAttribute("pos"); |
|
|
|
combineProgram1.DetectAttribute("texcoord"); |
|
|
|
combineProgram1.DetectUniform("U_MainTexture"); |
|
|
|
|
|
|
|
//combine program
|
|
|
|
GPUProgram combineProgram2; |
|
|
|
combineProgram2.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); |
|
|
|
combineProgram2.AttachShader(GL_FRAGMENT_SHADER, "res/shader/smooth.fs"); |
|
|
|
combineProgram2.Link(); |
|
|
|
combineProgram2.DetectAttribute("pos"); |
|
|
|
combineProgram2.DetectAttribute("texcoord"); |
|
|
|
combineProgram2.DetectUniform("U_MainTexture"); |
|
|
|
|
|
|
|
//combine program
|
|
|
|
GPUProgram combineProgram3; |
|
|
|
combineProgram3.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); |
|
|
|
combineProgram3.AttachShader(GL_FRAGMENT_SHADER, "res/shader/sharpen.fs"); |
|
|
|
combineProgram3.Link(); |
|
|
|
combineProgram3.DetectAttribute("pos"); |
|
|
|
combineProgram3.DetectAttribute("texcoord"); |
|
|
|
combineProgram3.DetectUniform("U_MainTexture"); |
|
|
|
|
|
|
|
//combine program
|
|
|
|
GPUProgram combineProgram4; |
|
|
|
combineProgram4.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); |
|
|
|
combineProgram4.AttachShader(GL_FRAGMENT_SHADER, "res/shader/edge_detect.fs"); |
|
|
|
combineProgram4.Link(); |
|
|
|
combineProgram4.DetectAttribute("pos"); |
|
|
|
combineProgram4.DetectAttribute("texcoord"); |
|
|
|
combineProgram4.DetectUniform("U_MainTexture"); |
|
|
|
|
|
|
|
GPUProgram gpuProgram; |
|
|
|
gpuProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/forg.vs"); |
|
|
|
gpuProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/forg.fs"); |
|
|
|
gpuProgram.Link(); |
|
|
|
|
|
|
|
gpuProgram.DetectAttribute("pos"); |
|
|
|
gpuProgram.DetectAttribute("texcoord"); |
|
|
|
gpuProgram.DetectAttribute("normal"); |
|
|
|
gpuProgram.DetectUniform("M"); |
|
|
|
gpuProgram.DetectUniform("V"); |
|
|
|
gpuProgram.DetectUniform("P"); |
|
|
|
gpuProgram.DetectUniform("NM"); |
|
|
|
gpuProgram.DetectUniform("U_AmbientLightColor"); |
|
|
|
gpuProgram.DetectUniform("U_AmbientMaterial"); |
|
|
|
gpuProgram.DetectUniform("U_DiffuseLightColor"); |
|
|
|
gpuProgram.DetectUniform("U_DiffuseMaterial"); |
|
|
|
gpuProgram.DetectUniform("U_DiffuseIntensity"); |
|
|
|
gpuProgram.DetectUniform("U_LightPos"); |
|
|
|
gpuProgram.DetectUniform("U_LightDirection"); |
|
|
|
gpuProgram.DetectUniform("U_Cutoff"); |
|
|
|
gpuProgram.DetectUniform("U_SpecularLightColor"); |
|
|
|
gpuProgram.DetectUniform("U_SpecularMaterial"); |
|
|
|
gpuProgram.DetectUniform("U_EyePos"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//init 3d model
|
|
|
|
ObjModel quad; |
|
|
|
quad.Init("res/model/Quad.obj"); |
|
|
|
ObjModel cube; |
|
|
|
cube.Init("res/model/Cube.obj"); |
|
|
|
|
|
|
|
float identity[] = { |
|
|
|
1.0f,0,0,0, |
|
|
@ -122,23 +110,25 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
0,0,0,1.0f |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glm::mat4 quadModel = glm::translate<float>(0.0f, 0.0f, -2.0f) * glm::rotate(-90.0f, 1.0f, 0.0f, 0.0f) * glm::scale(8.0f, 8.0f, 8.0f); |
|
|
|
glm::mat4 quadNormalMatrix = glm::inverseTranspose(quadModel); |
|
|
|
|
|
|
|
float ambientLightColor[] = { 0.4f,0.4f,0.4f,1.0f }; |
|
|
|
float ambientMaterial[] = { 0.2f,0.2f,0.2f,1.0f }; |
|
|
|
float diffuseLightColor[] = { 1.0f,1.0f,1.0f,1.0f }; |
|
|
|
float diffuseMaterial[] = { 0.6f, 0.6f, 0.6f, 1.0f }; |
|
|
|
float lightPos[] = { 0.0f,1.0f,0.0f,0.0f }; |
|
|
|
float diffuseIntensity = 2.5f; |
|
|
|
|
|
|
|
float spotLightDirection[] = { 0.0f, -1.0f, 0.0f, 628.0f }; |
|
|
|
float spotLightCutoff = 5.0f; |
|
|
|
float specularLightColor[] = { 1.0f,1.0f,1.0f,1.0f }; |
|
|
|
float specularMaterial[] = { 1.0f,1.0f,1.0f,1.0f }; |
|
|
|
float eyePos[] = { 0.0f,0.0f,0.0f }; |
|
|
|
|
|
|
|
glm::mat4 cubeModelMatrix = glm::translate<float>(-2.0f, 0.0f, -6.0f) * glm::rotate(-30.0f, 1.0f, 1.0f, 1.0f); |
|
|
|
glm::mat4 cubeNormalMatrix = 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 projectionMatrix = glm::perspective(50.0f, 800.0f / 600.0f, 0.1f, 1000.0f); |
|
|
|
|
|
|
|
|
|
|
|
//³õʼ»¯fsq
|
|
|
|
FullScreenQuad fsq; |
|
|
|
fsq.Init(); |
|
|
|
|
|
|
|
|
|
|
|
GLuint head = CreateTextureFromFile("res/image/wood.bmp"); |
|
|
|
GLuint grass = CreateTextureFromFile("res/image/earth.bmp"); |
|
|
|
|
|
|
|
ShowWindow(hwnd, SW_SHOW); |
|
|
|
UpdateWindow(hwnd); |
|
|
|
|
|
|
@ -156,37 +146,30 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
|
DispatchMessage(&msg); |
|
|
|
} |
|
|
|
glEnable(GL_DEPTH_TEST); |
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
glEnable(GL_BLEND); |
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
|
|
|
|
glUseProgram(combineProgram1.mProgram); |
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
glBindTexture(GL_TEXTURE_2D, head); |
|
|
|
glUniform1i(combineProgram1.GetLocation("U_MainTexture"), 0); |
|
|
|
fsq.DrawToLeftTop(combineProgram1.GetLocation("pos"), combineProgram1.GetLocation("texcoord")); |
|
|
|
|
|
|
|
glUseProgram(combineProgram2.mProgram); |
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
glBindTexture(GL_TEXTURE_2D, head); |
|
|
|
glUniform1i(combineProgram2.GetLocation("U_MainTexture"), 0); |
|
|
|
fsq.DrawToRightTop(combineProgram2.GetLocation("pos"), combineProgram2.GetLocation("texcoord")); |
|
|
|
|
|
|
|
glUseProgram(combineProgram3.mProgram); |
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
glBindTexture(GL_TEXTURE_2D, head); |
|
|
|
glUniform1i(combineProgram3.GetLocation("U_MainTexture"), 0); |
|
|
|
fsq.DrawToLeftBottom(combineProgram3.GetLocation("pos"), combineProgram3.GetLocation("texcoord")); |
|
|
|
|
|
|
|
glUseProgram(combineProgram4.mProgram); |
|
|
|
glActiveTexture(GL_TEXTURE0); |
|
|
|
glBindTexture(GL_TEXTURE_2D, head); |
|
|
|
glUniform1i(combineProgram4.GetLocation("U_MainTexture"), 0); |
|
|
|
fsq.DrawToRightBottom(combineProgram4.GetLocation("pos"), combineProgram4.GetLocation("texcoord")); |
|
|
|
|
|
|
|
glDisable(GL_BLEND); |
|
|
|
glUseProgram(gpuProgram.mProgram); |
|
|
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(cubeModelMatrix)); |
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("V"), 1, GL_FALSE, identity); |
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("P"), 1, GL_FALSE, glm::value_ptr(projectionMatrix)); |
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(cubeNormalMatrix)); |
|
|
|
|
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_AmbientLightColor"), 1, ambientLightColor); |
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_AmbientMaterial"), 1, ambientMaterial); |
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_DiffuseLightColor"), 1, diffuseLightColor); |
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_DiffuseMaterial"), 1, diffuseMaterial); |
|
|
|
glUniform1f(gpuProgram.GetLocation("U_DiffuseIntensity"), diffuseIntensity); |
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_LightPos"), 1, lightPos); |
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_LightDirection"), 1, spotLightDirection); |
|
|
|
glUniform1f(gpuProgram.GetLocation("U_Cutoff"), spotLightCutoff); |
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_SpecularLightColor"), 1, specularLightColor); |
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_SpecularMaterial"), 1, specularMaterial); |
|
|
|
glUniform3fv(gpuProgram.GetLocation("U_EyePos"), 1, eyePos); |
|
|
|
|
|
|
|
cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
|
cube.Draw(); |
|
|
|
|
|
|
|
glUseProgram(0); |
|
|
|
glFlush(); |
|
|
|
SwapBuffers(dc); |
|
|
|
} |
|
|
|