|
@ -99,6 +99,20 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
reflectProgram.DetectUniform("NM"); |
|
|
reflectProgram.DetectUniform("NM"); |
|
|
reflectProgram.DetectUniform("U_MainTexture"); |
|
|
reflectProgram.DetectUniform("U_MainTexture"); |
|
|
|
|
|
|
|
|
|
|
|
//refract program
|
|
|
|
|
|
GPUProgram refractProgram; |
|
|
|
|
|
refractProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/skybox_refract.vs"); |
|
|
|
|
|
refractProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/skybox_refract.fs"); |
|
|
|
|
|
refractProgram.Link(); |
|
|
|
|
|
refractProgram.DetectAttribute("pos"); |
|
|
|
|
|
refractProgram.DetectAttribute("texcoord"); |
|
|
|
|
|
refractProgram.DetectAttribute("normal"); |
|
|
|
|
|
refractProgram.DetectUniform("M"); |
|
|
|
|
|
refractProgram.DetectUniform("V"); |
|
|
|
|
|
refractProgram.DetectUniform("P"); |
|
|
|
|
|
refractProgram.DetectUniform("NM"); |
|
|
|
|
|
refractProgram.DetectUniform("U_MainTexture"); |
|
|
|
|
|
|
|
|
//init 3d model
|
|
|
//init 3d model
|
|
|
ObjModel cube,sphere; |
|
|
ObjModel cube,sphere; |
|
|
cube.Init("res/model/Cube.obj"); |
|
|
cube.Init("res/model/Cube.obj"); |
|
@ -115,9 +129,12 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
glm::mat4 cubeModelMatrix; |
|
|
glm::mat4 cubeModelMatrix; |
|
|
glm::mat4 projectionMatrix = glm::perspective(50.0f, (float)viewportWidth / (float)viewportHeight, 0.1f, 1000.0f); |
|
|
glm::mat4 projectionMatrix = glm::perspective(50.0f, (float)viewportWidth / (float)viewportHeight, 0.1f, 1000.0f); |
|
|
|
|
|
|
|
|
glm::mat4 sphereModelMatrix = glm::translate(0.0f, 0.0f, -4.0f); |
|
|
|
|
|
|
|
|
glm::mat4 sphereModelMatrix = glm::translate(-1.5f, 0.0f, -4.0f); |
|
|
glm::mat4 sphereNormalMatrix = glm::inverseTranspose(sphereModelMatrix); |
|
|
glm::mat4 sphereNormalMatrix = glm::inverseTranspose(sphereModelMatrix); |
|
|
|
|
|
|
|
|
|
|
|
glm::mat4 sphereModelMatrix2 = glm::translate(1.5f, 0.0f, -4.0f); |
|
|
|
|
|
glm::mat4 sphereNormalMatrix2 = glm::inverseTranspose(sphereModelMatrix2); |
|
|
|
|
|
|
|
|
GLuint mainTexture = SOIL_load_OGL_cubemap( |
|
|
GLuint mainTexture = SOIL_load_OGL_cubemap( |
|
|
"res/image/right.bmp", |
|
|
"res/image/right.bmp", |
|
|
"res/image/left.bmp", |
|
|
"res/image/left.bmp", |
|
@ -169,6 +186,17 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
sphere.Draw(); |
|
|
sphere.Draw(); |
|
|
glUseProgram(0); |
|
|
glUseProgram(0); |
|
|
|
|
|
|
|
|
|
|
|
glUseProgram(refractProgram.mProgram); |
|
|
|
|
|
glUniformMatrix4fv(refractProgram.GetLocation("V"), 1, GL_FALSE, identity); |
|
|
|
|
|
glUniformMatrix4fv(refractProgram.GetLocation("P"), 1, GL_FALSE, glm::value_ptr(projectionMatrix)); |
|
|
|
|
|
glUniformMatrix4fv(refractProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(sphereModelMatrix2)); |
|
|
|
|
|
glUniformMatrix4fv(refractProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(sphereNormalMatrix2)); |
|
|
|
|
|
glBindTexture(GL_TEXTURE_CUBE_MAP, mainTexture); |
|
|
|
|
|
glUniform1i(refractProgram.GetLocation("U_MainTexture"), 0); |
|
|
|
|
|
sphere.Bind(refractProgram.GetLocation("pos"), refractProgram.GetLocation("texcoord"), refractProgram.GetLocation("normal")); |
|
|
|
|
|
sphere.Draw(); |
|
|
|
|
|
glUseProgram(0); |
|
|
|
|
|
|
|
|
glFlush(); |
|
|
glFlush(); |
|
|
SwapBuffers(dc); |
|
|
SwapBuffers(dc); |
|
|
} |
|
|
} |
|
|