|
@ -78,18 +78,31 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
gpuProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/skybox.vs"); |
|
|
gpuProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/skybox.vs"); |
|
|
gpuProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/skybox.fs"); |
|
|
gpuProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/skybox.fs"); |
|
|
gpuProgram.Link(); |
|
|
gpuProgram.Link(); |
|
|
|
|
|
|
|
|
gpuProgram.DetectAttribute("pos"); |
|
|
gpuProgram.DetectAttribute("pos"); |
|
|
gpuProgram.DetectAttribute("texcoord"); |
|
|
gpuProgram.DetectAttribute("texcoord"); |
|
|
gpuProgram.DetectAttribute("normal"); |
|
|
gpuProgram.DetectAttribute("normal"); |
|
|
gpuProgram.DetectUniform("M"); |
|
|
gpuProgram.DetectUniform("M"); |
|
|
gpuProgram.DetectUniform("V"); |
|
|
gpuProgram.DetectUniform("V"); |
|
|
gpuProgram.DetectUniform("P"); |
|
|
gpuProgram.DetectUniform("P"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//reflect program
|
|
|
|
|
|
GPUProgram reflectProgram; |
|
|
|
|
|
reflectProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/skybox_reflect.vs"); |
|
|
|
|
|
reflectProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/skybox_reflect.fs"); |
|
|
|
|
|
reflectProgram.Link(); |
|
|
|
|
|
reflectProgram.DetectAttribute("pos"); |
|
|
|
|
|
reflectProgram.DetectAttribute("texcoord"); |
|
|
|
|
|
reflectProgram.DetectAttribute("normal"); |
|
|
|
|
|
reflectProgram.DetectUniform("M"); |
|
|
|
|
|
reflectProgram.DetectUniform("V"); |
|
|
|
|
|
reflectProgram.DetectUniform("P"); |
|
|
|
|
|
reflectProgram.DetectUniform("NM"); |
|
|
|
|
|
reflectProgram.DetectUniform("U_MainTexture"); |
|
|
|
|
|
|
|
|
//init 3d model
|
|
|
//init 3d model
|
|
|
ObjModel cube; |
|
|
|
|
|
cube.Init("res/model/Sphere.obj"); |
|
|
|
|
|
|
|
|
ObjModel cube,sphere; |
|
|
|
|
|
cube.Init("res/model/Cube.obj"); |
|
|
|
|
|
sphere.Init("res/model/Sphere.obj"); |
|
|
|
|
|
|
|
|
float identity[] = { |
|
|
float identity[] = { |
|
|
1.0f,0,0,0, |
|
|
1.0f,0,0,0, |
|
@ -102,6 +115,9 @@ 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 sphereNormalMatrix = glm::inverseTranspose(sphereModelMatrix); |
|
|
|
|
|
|
|
|
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", |
|
@ -141,6 +157,18 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ |
|
|
cube.Draw(); |
|
|
cube.Draw(); |
|
|
glUseProgram(0); |
|
|
glUseProgram(0); |
|
|
glEnable(GL_DEPTH_TEST); |
|
|
glEnable(GL_DEPTH_TEST); |
|
|
|
|
|
|
|
|
|
|
|
glUseProgram(reflectProgram.mProgram); |
|
|
|
|
|
glUniformMatrix4fv(reflectProgram.GetLocation("V"), 1, GL_FALSE, identity); |
|
|
|
|
|
glUniformMatrix4fv(reflectProgram.GetLocation("P"), 1, GL_FALSE, glm::value_ptr(projectionMatrix)); |
|
|
|
|
|
glUniformMatrix4fv(reflectProgram.GetLocation("M"), 1, GL_FALSE, glm::value_ptr(sphereModelMatrix)); |
|
|
|
|
|
glUniformMatrix4fv(reflectProgram.GetLocation("NM"), 1, GL_FALSE, glm::value_ptr(sphereNormalMatrix)); |
|
|
|
|
|
glBindTexture(GL_TEXTURE_CUBE_MAP, mainTexture); |
|
|
|
|
|
glUniform1i(reflectProgram.GetLocation("U_MainTexture"), 0); |
|
|
|
|
|
sphere.Bind(reflectProgram.GetLocation("pos"), reflectProgram.GetLocation("texcoord"), reflectProgram.GetLocation("normal")); |
|
|
|
|
|
sphere.Draw(); |
|
|
|
|
|
glUseProgram(0); |
|
|
|
|
|
|
|
|
glFlush(); |
|
|
glFlush(); |
|
|
SwapBuffers(dc); |
|
|
SwapBuffers(dc); |
|
|
} |
|
|
} |
|
|