|
@ -78,6 +78,7 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
gpuProgram.DetectUniform("U_AmbientMaterial"); |
|
|
gpuProgram.DetectUniform("U_AmbientMaterial"); |
|
|
gpuProgram.DetectUniform("U_DiffuseLightColor"); |
|
|
gpuProgram.DetectUniform("U_DiffuseLightColor"); |
|
|
gpuProgram.DetectUniform("U_DiffuseMaterial"); |
|
|
gpuProgram.DetectUniform("U_DiffuseMaterial"); |
|
|
|
|
|
gpuProgram.DetectUniform("U_DiffuseIntensity"); |
|
|
gpuProgram.DetectUniform("U_LightPos"); |
|
|
gpuProgram.DetectUniform("U_LightPos"); |
|
|
gpuProgram.DetectUniform("U_LightDirection"); |
|
|
gpuProgram.DetectUniform("U_LightDirection"); |
|
|
gpuProgram.DetectUniform("U_Cutoff"); |
|
|
gpuProgram.DetectUniform("U_Cutoff"); |
|
@ -86,8 +87,8 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
gpuProgram.DetectUniform("U_EyePos"); |
|
|
gpuProgram.DetectUniform("U_EyePos"); |
|
|
|
|
|
|
|
|
//init 3d model
|
|
|
//init 3d model
|
|
|
ObjModel model; |
|
|
|
|
|
model.Init("res/model/Sphere.obj"); |
|
|
|
|
|
|
|
|
ObjModel cube; |
|
|
|
|
|
cube.Init("res/model/Cube.obj"); |
|
|
|
|
|
|
|
|
float identity[] = { |
|
|
float identity[] = { |
|
|
1.0f,0,0,0, |
|
|
1.0f,0,0,0, |
|
@ -98,19 +99,26 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
float ambientLightColor[] = {0.4f,0.4f,0.4f,1.0f}; |
|
|
float ambientLightColor[] = {0.4f,0.4f,0.4f,1.0f}; |
|
|
float ambientMaterial[] = { 0.2f,0.2f,0.2f,1.0f }; |
|
|
float ambientMaterial[] = { 0.2f,0.2f,0.2f,1.0f }; |
|
|
float diffuseLightColor[] = { 1.0f,1.0f,1.0f,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,3.0f,-2.5f,1.0f}; |
|
|
|
|
|
|
|
|
float diffuseMaterial[] = { 0.8f, 0.8f, 0.8f, 1.0f }; |
|
|
|
|
|
float lightPos[] = {0.0f,1.0f,0.0f,0.0f}; |
|
|
|
|
|
float diffuseIntensity = 1.0f; |
|
|
|
|
|
|
|
|
|
|
|
float spotLightDirection[] = {0.0f, -1.0f, 0.0f, 128.0f};//把最后一位改成......
|
|
|
|
|
|
float spotLightCutoff = 0.0f; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 specularLightColor[] = { 1.0f,1.0f,1.0f,1.0f }; |
|
|
float specularMaterial[] = { 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 }; |
|
|
float eyePos[] = { 0.0f,0.0f,0.0f }; |
|
|
|
|
|
|
|
|
glm::mat4 modelMatrix = glm::translate<float>(0.0f, 0.0f, -3.0f) * glm::rotate(-30.0f, 1.0f, 1.0f, 1.0f); |
|
|
|
|
|
|
|
|
glm::mat4 model1 = glm::translate<float>(-2.0f, 0.0f, -6.0f) * glm::rotate(-30.0f , 1.0f, 1.0f, 1.0f); |
|
|
|
|
|
glm::mat4 model2 = glm::translate<float>(0.0f, 0.0f, -6.0f) * glm::rotate(-30.0f, 1.0f, 1.0f, 1.0f); |
|
|
|
|
|
glm::mat4 model3 = glm::translate<float>(2.0f, 0.0f, -6.0f) * glm::rotate(-30.0f, 1.0f, 1.0f, 1.0f); |
|
|
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(modelMatrix); |
|
|
|
|
|
|
|
|
glm::mat4 normalMatrix1 = glm::inverseTranspose(model1); |
|
|
|
|
|
glm::mat4 normalMatrix2 = glm::inverseTranspose(model2); |
|
|
|
|
|
glm::mat4 normalMatrix3 = glm::inverseTranspose(model3); |
|
|
|
|
|
|
|
|
glClearColor(41.0f/255.0f, 71.0f/255.0f, 121.0f / 255.0f, 1.0f); |
|
|
glClearColor(41.0f/255.0f, 71.0f/255.0f, 121.0f / 255.0f, 1.0f); |
|
|
ShowWindow(hwnd, SW_SHOW); |
|
|
ShowWindow(hwnd, SW_SHOW); |
|
@ -133,24 +141,64 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
glEnable(GL_DEPTH_TEST); |
|
|
glEnable(GL_DEPTH_TEST); |
|
|
glUseProgram(gpuProgram.mProgram); |
|
|
glUseProgram(gpuProgram.mProgram); |
|
|
|
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1,GL_FALSE, glm::value_ptr(modelMatrix)); |
|
|
|
|
|
|
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("V"), 1, GL_FALSE, identity); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("V"), 1, GL_FALSE, identity); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("P"), 1, GL_FALSE, glm::value_ptr(projectionMatrix)); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("P"), 1, GL_FALSE, glm::value_ptr(projectionMatrix)); |
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(normalMatrix)); |
|
|
|
|
|
|
|
|
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_AmbientLightColor"), 1,ambientLightColor); |
|
|
glUniform4fv(gpuProgram.GetLocation("U_AmbientLightColor"), 1,ambientLightColor); |
|
|
glUniform4fv(gpuProgram.GetLocation("U_AmbientMaterial"), 1, ambientMaterial); |
|
|
glUniform4fv(gpuProgram.GetLocation("U_AmbientMaterial"), 1, ambientMaterial); |
|
|
glUniform4fv(gpuProgram.GetLocation("U_DiffuseLightColor"), 1, diffuseLightColor); |
|
|
glUniform4fv(gpuProgram.GetLocation("U_DiffuseLightColor"), 1, diffuseLightColor); |
|
|
glUniform4fv(gpuProgram.GetLocation("U_DiffuseMaterial"), 1, diffuseMaterial); |
|
|
glUniform4fv(gpuProgram.GetLocation("U_DiffuseMaterial"), 1, diffuseMaterial); |
|
|
glUniform4fv(gpuProgram.GetLocation("U_LightPos"), 1, lightPos); |
|
|
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_LightDirection"), 1, spotLightDirection); |
|
|
glUniform4fv(gpuProgram.GetLocation("U_LightDirection"), 1, spotLightDirection); |
|
|
glUniform1f(gpuProgram.GetLocation("U_Cutoff"), spotLightCutoff); |
|
|
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_SpecularLightColor"), 1, specularLightColor); |
|
|
glUniform4fv(gpuProgram.GetLocation("U_SpecularLightColor"), 1, specularLightColor); |
|
|
glUniform4fv(gpuProgram.GetLocation("U_SpecularMaterial"), 1, specularMaterial); |
|
|
glUniform4fv(gpuProgram.GetLocation("U_SpecularMaterial"), 1, specularMaterial); |
|
|
glUniform3fv(gpuProgram.GetLocation("U_EyePos"), 1, eyePos); |
|
|
glUniform3fv(gpuProgram.GetLocation("U_EyePos"), 1, eyePos); |
|
|
|
|
|
|
|
|
model.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
|
|
|
model.Draw(); |
|
|
|
|
|
|
|
|
//left
|
|
|
|
|
|
lightPos[0] = 0.0f; |
|
|
|
|
|
lightPos[1] = 1.5f; |
|
|
|
|
|
lightPos[2] = 0.0f; |
|
|
|
|
|
lightPos[3] = 0.0f; |
|
|
|
|
|
diffuseIntensity = 1.0f; |
|
|
|
|
|
spotLightCutoff = 0.0f; |
|
|
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_LightPos"), 1, lightPos); |
|
|
|
|
|
glUniform1f(gpuProgram.GetLocation("U_DiffuseIntensity"), diffuseIntensity); |
|
|
|
|
|
glUniform1f(gpuProgram.GetLocation("U_Cutoff"), spotLightCutoff); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(model1)); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(normalMatrix1)); |
|
|
|
|
|
cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
|
|
|
cube.Draw(); |
|
|
|
|
|
|
|
|
|
|
|
//middle
|
|
|
|
|
|
lightPos[0] = 0.0f; |
|
|
|
|
|
lightPos[1] = 3.0f; |
|
|
|
|
|
lightPos[2] = -6.0f; |
|
|
|
|
|
lightPos[3] = 1.0f; |
|
|
|
|
|
diffuseIntensity = 3.0f; |
|
|
|
|
|
spotLightCutoff = 0.0f; |
|
|
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_LightPos"), 1, lightPos); |
|
|
|
|
|
glUniform1f(gpuProgram.GetLocation("U_DiffuseIntensity"), diffuseIntensity); |
|
|
|
|
|
glUniform1f(gpuProgram.GetLocation("U_Cutoff"), spotLightCutoff); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(model2)); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(normalMatrix2)); |
|
|
|
|
|
cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
|
|
|
cube.Draw(); |
|
|
|
|
|
|
|
|
|
|
|
//right
|
|
|
|
|
|
lightPos[0] = 2.0f; |
|
|
|
|
|
lightPos[1] = 3.0f; |
|
|
|
|
|
lightPos[2] = -6.0f; |
|
|
|
|
|
lightPos[3] = 1.0f; |
|
|
|
|
|
diffuseIntensity = 4.0f; |
|
|
|
|
|
spotLightCutoff = 15.0f; |
|
|
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_LightPos"), 1, lightPos); |
|
|
|
|
|
glUniform1f(gpuProgram.GetLocation("U_DiffuseIntensity"), diffuseIntensity); |
|
|
|
|
|
glUniform1f(gpuProgram.GetLocation("U_Cutoff"), spotLightCutoff); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(model3)); |
|
|
|
|
|
glUniformMatrix4fv(gpuProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(normalMatrix3)); |
|
|
|
|
|
cube.Bind(gpuProgram.GetLocation("pos"), gpuProgram.GetLocation("texcoord"), gpuProgram.GetLocation("normal")); |
|
|
|
|
|
cube.Draw(); |
|
|
|
|
|
|
|
|
glUseProgram(0); |
|
|
glUseProgram(0); |
|
|
glFinish(); |
|
|
glFinish(); |
|
|
SwapBuffers(dc); |
|
|
SwapBuffers(dc); |
|
|