|
@ -44,8 +44,8 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
RECT rect; |
|
|
RECT rect; |
|
|
rect.left = 0; |
|
|
rect.left = 0; |
|
|
rect.top = 0; |
|
|
rect.top = 0; |
|
|
rect.right = 800; |
|
|
|
|
|
rect.bottom = 600; |
|
|
|
|
|
|
|
|
rect.right = 1280; |
|
|
|
|
|
rect.bottom = 720; |
|
|
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); |
|
|
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); |
|
|
HWND hwnd = CreateWindowEx(NULL, "OpenGL", "RenderWindow", WS_OVERLAPPEDWINDOW, 100, 100, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, hInstance, NULL); |
|
@ -95,13 +95,16 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
gpuProgram.DetectUniform("U_Cutoff"); |
|
|
gpuProgram.DetectUniform("U_Cutoff"); |
|
|
gpuProgram.DetectUniform("U_SpecularLightColor"); |
|
|
gpuProgram.DetectUniform("U_SpecularLightColor"); |
|
|
gpuProgram.DetectUniform("U_SpecularMaterial"); |
|
|
gpuProgram.DetectUniform("U_SpecularMaterial"); |
|
|
gpuProgram.DetectUniform("U_EyePos"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gpuProgram.DetectUniform("U_FogStart"); |
|
|
|
|
|
gpuProgram.DetectUniform("U_FogEnd"); |
|
|
|
|
|
gpuProgram.DetectUniform("U_FogColor"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//init 3d model
|
|
|
//init 3d model
|
|
|
ObjModel cube; |
|
|
ObjModel cube; |
|
|
cube.Init("res/model/Cube.obj"); |
|
|
|
|
|
|
|
|
cube.Init("res/model/Sphere.obj"); |
|
|
|
|
|
|
|
|
float identity[] = { |
|
|
float identity[] = { |
|
|
1.0f,0,0,0, |
|
|
1.0f,0,0,0, |
|
@ -112,10 +115,10 @@ 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[] = { 0.1f,0.4f,0.7f,1.0f }; |
|
|
float diffuseMaterial[] = { 0.6f, 0.6f, 0.6f, 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 lightPos[] = { 1.0f,1.0f,0.0f,0.0f }; |
|
|
|
|
|
float diffuseIntensity = 1.0f; |
|
|
|
|
|
|
|
|
float spotLightDirection[] = { 0.0f, -1.0f, 0.0f, 628.0f }; |
|
|
float spotLightDirection[] = { 0.0f, -1.0f, 0.0f, 628.0f }; |
|
|
float spotLightCutoff = 5.0f; |
|
|
float spotLightCutoff = 5.0f; |
|
@ -123,16 +126,28 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
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 cubeModelMatrix = glm::translate<float>(-2.0f, 0.0f, -6.0f) * glm::rotate(-30.0f, 1.0f, 1.0f, 1.0f); |
|
|
|
|
|
|
|
|
float fogStart = 2.0f; |
|
|
|
|
|
float fogEnd = 23.0f; |
|
|
|
|
|
float fogColor[] = { 0.6f, 0.6f, 0.6f, 1.0f }; |
|
|
|
|
|
|
|
|
|
|
|
glm::mat4 cubeModelMatrix = glm::translate<float>(-2.2f, 0.0f, -4.0f) * glm::rotate(-30.0f, 1.0f, 1.0f, 1.0f); |
|
|
glm::mat4 cubeNormalMatrix = glm::inverseTranspose(cubeModelMatrix); |
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glm::mat4 cubeModelMatrix2 = glm::translate<float>(-2.0f, 0.0f, -12.0f) * glm::rotate(-30.0f, 1.0f, 1.0f, 1.0f); |
|
|
|
|
|
glm::mat4 cubeNormalMatrix2 = glm::inverseTranspose(cubeModelMatrix); |
|
|
|
|
|
|
|
|
|
|
|
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 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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ShowWindow(hwnd, SW_SHOW); |
|
|
ShowWindow(hwnd, SW_SHOW); |
|
|
UpdateWindow(hwnd); |
|
|
UpdateWindow(hwnd); |
|
|
|
|
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
|
|
|
|
|
|
|
|
glClearColor(0.6f, 0.6f, 0.6f, 1.0f); |
|
|
MSG msg; |
|
|
MSG msg; |
|
|
while (true) |
|
|
while (true) |
|
|
{ |
|
|
{ |
|
@ -149,10 +164,9 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
glUseProgram(gpuProgram.mProgram); |
|
|
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("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(cubeNormalMatrix)); |
|
|
|
|
|
|
|
|
|
|
|
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); |
|
@ -165,10 +179,25 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
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); |
|
|
|
|
|
glUniform1f(gpuProgram.GetLocation("U_FogStart"), fogStart); |
|
|
|
|
|
glUniform1f(gpuProgram.GetLocation("U_FogEnd"), fogEnd); |
|
|
|
|
|
glUniform4fv(gpuProgram.GetLocation("U_FogColor"), 1, fogColor); |
|
|
|
|
|
|
|
|
|
|
|
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.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(); |
|
|
glUseProgram(0); |
|
|
glUseProgram(0); |
|
|
glFlush(); |
|
|
glFlush(); |
|
|
SwapBuffers(dc); |
|
|
SwapBuffers(dc); |
|
|