|
|
@ -122,8 +122,21 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
printf("load obj model fail\n"); |
|
|
|
} |
|
|
|
|
|
|
|
/*创建vbo*/ |
|
|
|
GLuint vbo = CreateBufferObject(GL_ARRAY_BUFFER, sizeof(VertexData) * vertexCount, GL_STATIC_DRAW, vertexes); |
|
|
|
|
|
|
|
/*创建vao*/ |
|
|
|
GLuint vao = CreateVAOWithVBOSettings([&]()->void { |
|
|
|
/*创建vbo*/ |
|
|
|
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); |
|
|
@ -131,7 +144,7 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
/*创建纹理*/ |
|
|
|
GLuint mainTexture = CreateTextureFromFile("res/image/niutou.bmp"); |
|
|
|
|
|
|
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f); |
|
|
|
GL_CALL(glClearColor(0.1f, 0.4f, 0.7f, 1.0f)); |
|
|
|
glEnable(GL_DEPTH_TEST); |
|
|
|
|
|
|
|
glViewport(0,0, windowWidth, windowHeight); |
|
|
@ -168,15 +181,8 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
glBindTexture(GL_TEXTURE_2D, mainTexture); |
|
|
|
glUniform1i(textureLocation, 0); |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
glBindVertexArray(vao); |
|
|
|
|
|
|
|
model = glm::translate(-1.0f, -0.5f, -3.0f) * glm::rotate(-90.0f, 0.0f, 1.0f, 0.0f)*glm::scale(0.01f, 0.01f, 0.01f); |
|
|
|
glUniformMatrix4fv(MLocation, 1, GL_FALSE, glm::value_ptr(model)); |
|
|
@ -199,6 +205,7 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, 0); |
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
|
|
|
|
|
|
|
glBindVertexArray(0); |
|
|
|
glUseProgram(0); |
|
|
|
}; |
|
|
|
|
|
|
|