|
|
@ -90,13 +90,14 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
/*创建program*/ |
|
|
|
GLuint program = CreateGPUProgram("res/shader/test.vs", "res/shader/test.fs"); |
|
|
|
|
|
|
|
GLuint posLocation, texcoordLocation, normalLocation, MLocation, VLocation, PLocation; |
|
|
|
GLuint posLocation, texcoordLocation, normalLocation, MLocation, VLocation, PLocation, NMLocation; |
|
|
|
posLocation = glGetAttribLocation(program, "pos"); |
|
|
|
texcoordLocation = glGetAttribLocation(program, "texcoord"); |
|
|
|
normalLocation = glGetAttribLocation(program, "normal"); |
|
|
|
MLocation = glGetUniformLocation(program, "M"); |
|
|
|
VLocation = glGetUniformLocation(program, "V"); |
|
|
|
PLocation = glGetUniformLocation(program, "P"); |
|
|
|
NMLocation = glGetUniformLocation(program, "NM"); |
|
|
|
|
|
|
|
/*load model*/ |
|
|
|
unsigned int *indexes = nullptr; |
|
|
@ -113,7 +114,8 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
/*创建IBO*/ |
|
|
|
GLuint ibo = CreateBufferObject(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * indexCount, GL_STATIC_DRAW, indexes); |
|
|
|
|
|
|
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f); |
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
|
|
|
//glEnable(GL_DEPTH_TEST);
|
|
|
|
|
|
|
|
//创建一个单位矩阵和一个投影矩阵,后面用来传递到shader
|
|
|
|
float identify[] = { |
|
|
@ -122,8 +124,9 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
0,0,1,0, |
|
|
|
0,0,0,1 |
|
|
|
}; |
|
|
|
glm::mat4 model = glm::translate(0.0f, 0.0f, -5.0f); |
|
|
|
glm::mat4 model = glm::translate(0.0f, 0.0f, -3.0f); |
|
|
|
glm::mat4 projection = glm::perspective(45.0f, 800.0f/600.0f, 0.1f, 1000.0f); |
|
|
|
glm::mat4 normalMatrix = glm::inverseTranspose(model); |
|
|
|
|
|
|
|
/*显示窗口*/ |
|
|
|
ShowWindow(hwnd, SW_SHOW); |
|
|
@ -146,6 +149,7 @@ 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)); |
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vbo); |
|
|
|
glEnableVertexAttribArray(posLocation); |
|
|
|