|
|
@ -91,7 +91,7 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
glewInit(); |
|
|
|
|
|
|
|
/*创建program*/ |
|
|
|
GLuint program = CreateGPUProgram("res/shader/UI FullScreemQuad.vs", "res/shader/SimpleTexture.fs"); |
|
|
|
GLuint program = CreateGPUProgram("res/shader/SimpleTexture.vs", "res/shader/SimpleTexture.fs"); |
|
|
|
|
|
|
|
GLuint posLocation, texcoordLocation, normalLocation, MLocation, VLocation, PLocation, textureLocation; |
|
|
|
posLocation = glGetAttribLocation(program, "pos"); |
|
|
@ -108,7 +108,7 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
int vertexCount = 0, indexCount = 0; |
|
|
|
Timer t; |
|
|
|
t.Start(); |
|
|
|
VertexData* vertexes = LoadObjModel("res/model/Quad.obj", &indexes, vertexCount, indexCount); |
|
|
|
VertexData* vertexes = LoadObjModel("res/model/niutou.obj", &indexes, vertexCount, indexCount); |
|
|
|
printf("load model cost %fs %d\n", t.GetPassedTime(), t.GetPassedTickers()); |
|
|
|
|
|
|
|
if (vertexes == nullptr) { |
|
|
@ -116,18 +116,60 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
} |
|
|
|
|
|
|
|
/*创建vbo*/ |
|
|
|
GLuint vao = CreateVAOWithVBOSettings([&]()->void |
|
|
|
{ |
|
|
|
GLuint vbo = CreateBufferObject(GL_ARRAY_BUFFER, sizeof(VertexData) * vertexCount, GL_STATIC_DRAW, vertexes); |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vbo); |
|
|
|
glEnableVertexAttribArray(posLocation); |
|
|
|
glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)0); |
|
|
|
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));*/ |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0); |
|
|
|
}); |
|
|
|
|
|
|
|
/*创建IBO*/ |
|
|
|
GLuint ibo = CreateBufferObject(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * indexCount, GL_STATIC_DRAW, indexes); |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0); |
|
|
|
|
|
|
|
/*创建fsqprogram*/ |
|
|
|
GLuint fsqprogram = CreateGPUProgram("res/shader/UI FullScreemQuad.vs", "res/shader/RenderDepthBuffer.fs"); |
|
|
|
|
|
|
|
GLuint fsqposLocation, fsqtexcoordLocation, fsqnormalLocation, fsqMLocation, fsqVLocation, fsqPLocation, fsqtextureLocation; |
|
|
|
fsqposLocation = glGetAttribLocation(fsqprogram, "pos"); |
|
|
|
fsqtexcoordLocation = glGetAttribLocation(fsqprogram, "texcoord"); |
|
|
|
fsqnormalLocation = glGetAttribLocation(fsqprogram, "normal"); |
|
|
|
|
|
|
|
fsqMLocation = glGetUniformLocation(fsqprogram, "M"); |
|
|
|
fsqVLocation = glGetUniformLocation(fsqprogram, "V"); |
|
|
|
fsqPLocation = glGetUniformLocation(fsqprogram, "P"); |
|
|
|
textureLocation = glGetUniformLocation(program, "U_MainTexture"); |
|
|
|
|
|
|
|
/*load model*/ |
|
|
|
unsigned int *fsqindexes = nullptr; |
|
|
|
int fsqvertexCount = 0, fsqindexCount = 0; |
|
|
|
Timer t2; |
|
|
|
t2.Start(); |
|
|
|
VertexData* fsqvertexes = LoadObjModel("res/model/Quad.obj", &fsqindexes, fsqvertexCount, fsqindexCount); |
|
|
|
printf("load model cost %fs %d\n", t2.GetPassedTime(), t2.GetPassedTickers()); |
|
|
|
|
|
|
|
if (fsqvertexes == nullptr) { |
|
|
|
printf("load obj model fail\n"); |
|
|
|
} |
|
|
|
|
|
|
|
/*创建fsqvbo*/ |
|
|
|
GLuint fsqvao = CreateVAOWithVBOSettings([&]()->void |
|
|
|
{ |
|
|
|
GLuint fsqvbo = CreateBufferObject(GL_ARRAY_BUFFER, sizeof(VertexData) * fsqvertexCount, GL_STATIC_DRAW, fsqvertexes); |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, fsqvbo); |
|
|
|
glEnableVertexAttribArray(fsqposLocation); |
|
|
|
glVertexAttribPointer(fsqposLocation, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)0); |
|
|
|
glEnableVertexAttribArray(fsqtexcoordLocation); |
|
|
|
glVertexAttribPointer(fsqtexcoordLocation, 2, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)(sizeof(float) * 3)); |
|
|
|
}); |
|
|
|
|
|
|
|
/*创建fsqIBO*/ |
|
|
|
GLuint fsqibo = CreateBufferObject(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * fsqindexCount, GL_STATIC_DRAW, fsqindexes); |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0); |
|
|
|
|
|
|
|
|
|
|
|
/*创建纹理*/ |
|
|
|
GLuint mainTexture = CreateTextureFromFile("res/image/niutou.bmp"); |
|
|
@ -161,7 +203,6 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
MSG msg; |
|
|
|
|
|
|
|
auto what = [&]()->void { |
|
|
|
glm::mat4 normalMatrix = glm::inverseTranspose(model); |
|
|
|
|
|
|
|
glUseProgram(program); |
|
|
|
glUniformMatrix4fv(MLocation, 1, GL_FALSE, glm::value_ptr(model)); |
|
|
@ -171,10 +212,23 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
glBindTexture(GL_TEXTURE_2D, mainTexture); |
|
|
|
glUniform1i(textureLocation, 0); |
|
|
|
|
|
|
|
glBindVertexArray(vao); |
|
|
|
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); |
|
|
|
}; |
|
|
|
|
|
|
|
auto RenderFullScreenQuad = [&]()->void { |
|
|
|
glUseProgram(fsqprogram); |
|
|
|
|
|
|
|
glBindVertexArray(fsqvao); |
|
|
|
glBindTexture(GL_TEXTURE_2D, depthBuffer); |
|
|
|
glUniform1i(fsqtextureLocation, 0); |
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fsqibo); |
|
|
|
glDrawElements(GL_TRIANGLES, fsqindexCount, GL_UNSIGNED_INT, 0); |
|
|
|
glBindVertexArray(0); |
|
|
|
glUseProgram(0); |
|
|
|
}; |
|
|
|
|
|
|
@ -199,15 +253,7 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
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(); |
|
|
|
RenderFullScreenQuad(); |
|
|
|
|
|
|
|
glFlush(); |
|
|
|
SwapBuffers(dc); |
|
|
|