|
|
@ -91,18 +91,16 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
glewInit(); |
|
|
|
|
|
|
|
/*创建program*/ |
|
|
|
GLuint program = CreateGPUProgram("res/shader/MixLightMT.vs", "res/shader/MixLightMT.fs"); |
|
|
|
GLuint program = CreateGPUProgram("res/shader/ViewDepthMap.vs", "res/shader/ViewDepthMap.fs"); |
|
|
|
|
|
|
|
GLuint posLocation, texcoordLocation, normalLocation, MLocation, VLocation, PLocation, NMLocation, textureLocation, offsetLocation; |
|
|
|
GLuint posLocation, texcoordLocation, normalLocation, MLocation, VLocation, PLocation; |
|
|
|
posLocation = glGetAttribLocation(program, "pos"); |
|
|
|
texcoordLocation = glGetAttribLocation(program, "texcoord"); |
|
|
|
normalLocation = glGetAttribLocation(program, "normal"); |
|
|
|
offsetLocation = glGetAttribLocation(program, "offset"); |
|
|
|
|
|
|
|
MLocation = glGetUniformLocation(program, "M"); |
|
|
|
VLocation = glGetUniformLocation(program, "V"); |
|
|
|
PLocation = glGetUniformLocation(program, "P"); |
|
|
|
NMLocation = glGetUniformLocation(program, "NM"); |
|
|
|
textureLocation = glGetUniformLocation(program, "U_MainTexture"); |
|
|
|
|
|
|
|
/*load model*/ |
|
|
|
unsigned int *indexes = nullptr; |
|
|
@ -121,10 +119,10 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vbo); |
|
|
|
glEnableVertexAttribArray(posLocation); |
|
|
|
glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)0); |
|
|
|
glEnableVertexAttribArray(texcoordLocation); |
|
|
|
/*glEnableVertexAttribArray(texcoordLocation);
|
|
|
|
glVertexAttribPointer(texcoordLocation, 2, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)(sizeof(float) * 3)); |
|
|
|
glEnableVertexAttribArray(normalLocation); |
|
|
|
glVertexAttribPointer(normalLocation, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)(sizeof(float) * 5)); |
|
|
|
glVertexAttribPointer(normalLocation, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)(sizeof(float) * 5));*/ |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0); |
|
|
|
|
|
|
|
/*创建IBO*/ |
|
|
@ -133,10 +131,6 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
/*创建纹理*/ |
|
|
|
GLuint mainTexture = CreateTextureFromFile("res/image/niutou.bmp"); |
|
|
|
|
|
|
|
/*创建FBO*/ |
|
|
|
GLuint colorBuffer, depthBuffer, colorBuffer2; |
|
|
|
GLuint fbo = CreateFramebufferObject(colorBuffer, depthBuffer, windowWidth, windowHeight, &colorBuffer2); |
|
|
|
|
|
|
|
glViewport(0, 0, windowWidth, windowHeight); |
|
|
|
|
|
|
|
GL_CALL(glClearColor(0.1f, 0.4f, 0.7f, 1.0f)); |
|
|
@ -150,7 +144,7 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
0,0,0,1 |
|
|
|
}; |
|
|
|
|
|
|
|
glm::mat4 model = glm::translate(0.0f, -0.5f, -3.0f) * glm::rotate(-90.0f, 0.0f, 1.0f, 0.0f)*glm::scale(0.01f,0.01f,0.01f); |
|
|
|
glm::mat4 model = glm::translate(0.0f, -0.5f, -2.0f) * glm::rotate(-90.0f, 0.0f, 1.0f, 0.0f)*glm::scale(0.01f,0.01f,0.01f); |
|
|
|
glm::mat4 projection = glm::perspective(45.0f, (float)windowWidth / (float)windowHeight, 0.1f, 1000.0f); |
|
|
|
glm::mat4 normalMatrix = glm::inverseTranspose(model); |
|
|
|
|
|
|
@ -169,10 +163,6 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
glUniformMatrix4fv(MLocation, 1, GL_FALSE, glm::value_ptr(model)); |
|
|
|
glUniformMatrix4fv(VLocation, 1, GL_FALSE, identify); |
|
|
|
glUniformMatrix4fv(PLocation, 1, GL_FALSE, glm::value_ptr(projection)); |
|
|
|
glUniformMatrix4fv(NMLocation, 1, GL_FALSE, glm::value_ptr(normalMatrix)); |
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, colorBuffer); |
|
|
|
glUniform1i(textureLocation, 0); |
|
|
|
|
|
|
|
glUniformMatrix4fv(MLocation, 1, GL_FALSE, glm::value_ptr(model)); |
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo); |
|
|
@ -198,37 +188,10 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
} |
|
|
|
|
|
|
|
//绘制内容到fbo
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
|
|
|
GL_CALL(glClearColor(0.1f, 0.4f, 0.7f, 1.0f)); |
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
what(); |
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0); |
|
|
|
|
|
|
|
//把fbo绘制到一个四边形上
|
|
|
|
GL_CALL(glClearColor(0.5f, 0.4f, 0.7f, 1.0f)); |
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
glEnable(GL_TEXTURE_2D); |
|
|
|
glEnable(GL_SCISSOR_TEST); |
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, colorBuffer); |
|
|
|
glScissor(0, 0, windowWidth, windowHeight/2); |
|
|
|
glBegin(GL_QUADS); |
|
|
|
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, -0.5f, -1.0f); |
|
|
|
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.5f, -0.5f, -1.0f); |
|
|
|
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.5f, 0.5f, -1.0f); |
|
|
|
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, 0.5f, -1.0f); |
|
|
|
glEnd(); |
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, colorBuffer2); |
|
|
|
glScissor(0, windowHeight / 2, windowWidth, windowHeight / 2); |
|
|
|
glBegin(GL_QUADS); |
|
|
|
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, -0.5f, -1.0f); |
|
|
|
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.5f, -0.5f, -1.0f); |
|
|
|
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.5f, 0.5f, -1.0f); |
|
|
|
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, 0.5f, -1.0f); |
|
|
|
glEnd(); |
|
|
|
|
|
|
|
glDisable(GL_SCISSOR_TEST); |
|
|
|
SwapBuffers(dc); |
|
|
|
} |
|
|
|
|
|
|
|