|
|
@ -91,9 +91,9 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
glewInit(); |
|
|
|
|
|
|
|
/*创建program*/ |
|
|
|
GLuint program = CreateGPUProgram("res/shader/ViewDepthMap.vs", "res/shader/ViewDepthMap.fs"); |
|
|
|
GLuint program = CreateGPUProgram("res/shader/UI FullScreemQuad.vs", "res/shader/SimpleTexture.fs"); |
|
|
|
|
|
|
|
GLuint posLocation, texcoordLocation, normalLocation, MLocation, VLocation, PLocation; |
|
|
|
GLuint posLocation, texcoordLocation, normalLocation, MLocation, VLocation, PLocation, textureLocation; |
|
|
|
posLocation = glGetAttribLocation(program, "pos"); |
|
|
|
texcoordLocation = glGetAttribLocation(program, "texcoord"); |
|
|
|
normalLocation = glGetAttribLocation(program, "normal"); |
|
|
@ -101,13 +101,14 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
MLocation = glGetUniformLocation(program, "M"); |
|
|
|
VLocation = glGetUniformLocation(program, "V"); |
|
|
|
PLocation = glGetUniformLocation(program, "P"); |
|
|
|
textureLocation = glGetUniformLocation(program, "U_MainTexture"); |
|
|
|
|
|
|
|
/*load model*/ |
|
|
|
unsigned int *indexes = nullptr; |
|
|
|
int vertexCount = 0, indexCount = 0; |
|
|
|
Timer t; |
|
|
|
t.Start(); |
|
|
|
VertexData* vertexes = LoadObjModel("res/model/niutou.obj", &indexes, vertexCount, indexCount); |
|
|
|
VertexData* vertexes = LoadObjModel("res/model/Quad.obj", &indexes, vertexCount, indexCount); |
|
|
|
printf("load model cost %fs %d\n", t.GetPassedTime(), t.GetPassedTickers()); |
|
|
|
|
|
|
|
if (vertexes == nullptr) { |
|
|
@ -119,9 +120,9 @@ 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); |
|
|
|
/*glEnableVertexAttribArray(normalLocation);
|
|
|
|
glVertexAttribPointer(normalLocation, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)(sizeof(float) * 5));*/ |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0); |
|
|
|
|
|
|
@ -131,6 +132,9 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
/*创建纹理*/ |
|
|
|
GLuint mainTexture = CreateTextureFromFile("res/image/niutou.bmp"); |
|
|
|
|
|
|
|
GLuint colorBuffer, depthBuffer; |
|
|
|
GLuint fbo = CreateFramebufferObject(colorBuffer, depthBuffer, windowWidth, windowHeight); |
|
|
|
|
|
|
|
glViewport(0, 0, windowWidth, windowHeight); |
|
|
|
|
|
|
|
GL_CALL(glClearColor(0.1f, 0.4f, 0.7f, 1.0f)); |
|
|
@ -164,11 +168,13 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
glUniformMatrix4fv(VLocation, 1, GL_FALSE, identify); |
|
|
|
glUniformMatrix4fv(PLocation, 1, GL_FALSE, glm::value_ptr(projection)); |
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, mainTexture); |
|
|
|
glUniform1i(textureLocation, 0); |
|
|
|
|
|
|
|
glUniformMatrix4fv(MLocation, 1, GL_FALSE, glm::value_ptr(model)); |
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo); |
|
|
|
glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, 0); |
|
|
|
|
|
|
|
glBindVertexArray(0); |
|
|
|
glUseProgram(0); |
|
|
|
}; |
|
|
|
|
|
|
@ -187,11 +193,23 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
DispatchMessage(&msg); |
|
|
|
} |
|
|
|
|
|
|
|
//绘制内容到fbo
|
|
|
|
GL_CALL(glClearColor(0.1f, 0.4f, 0.7f, 1.0f)); |
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
what(); |
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0); |
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
|
|
|
|
glEnable(GL_TEXTURE_2D); |
|
|
|
glBindTexture(GL_TEXTURE_2D, colorBuffer); |
|
|
|
|
|
|
|
glBegin(GL_QUADS); |
|
|
|
glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, -0.5f, -2.0f); |
|
|
|
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.5f, -0.5f, -2.0f); |
|
|
|
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.5f, 0.5f, -2.0f); |
|
|
|
glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, 0.5f, -2.0f); |
|
|
|
glEnd(); |
|
|
|
|
|
|
|
glFlush(); |
|
|
|
SwapBuffers(dc); |
|
|
|
} |
|
|
|
|
|
|
|