|
@ -90,7 +90,7 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
/*创建program*/ |
|
|
/*创建program*/ |
|
|
GLuint program = CreateGPUProgram("res/shader/test.vs", "res/shader/test.fs"); |
|
|
GLuint program = CreateGPUProgram("res/shader/test.vs", "res/shader/test.fs"); |
|
|
|
|
|
|
|
|
GLuint posLocation, texcoordLocation, normalLocation, MLocation, VLocation, PLocation, NMLocation; |
|
|
|
|
|
|
|
|
GLuint posLocation, texcoordLocation, normalLocation, MLocation, VLocation, PLocation, NMLocation, textureLocation; |
|
|
posLocation = glGetAttribLocation(program, "pos"); |
|
|
posLocation = glGetAttribLocation(program, "pos"); |
|
|
texcoordLocation = glGetAttribLocation(program, "texcoord"); |
|
|
texcoordLocation = glGetAttribLocation(program, "texcoord"); |
|
|
normalLocation = glGetAttribLocation(program, "normal"); |
|
|
normalLocation = glGetAttribLocation(program, "normal"); |
|
@ -98,6 +98,8 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
VLocation = glGetUniformLocation(program, "V"); |
|
|
VLocation = glGetUniformLocation(program, "V"); |
|
|
PLocation = glGetUniformLocation(program, "P"); |
|
|
PLocation = glGetUniformLocation(program, "P"); |
|
|
NMLocation = glGetUniformLocation(program, "NM"); |
|
|
NMLocation = glGetUniformLocation(program, "NM"); |
|
|
|
|
|
textureLocation = glGetUniformLocation(program, "U_MainTexture"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*load model*/ |
|
|
/*load model*/ |
|
|
unsigned int *indexes = nullptr; |
|
|
unsigned int *indexes = nullptr; |
|
@ -114,8 +116,11 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
/*创建IBO*/ |
|
|
/*创建IBO*/ |
|
|
GLuint ibo = CreateBufferObject(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * indexCount, GL_STATIC_DRAW, indexes); |
|
|
GLuint ibo = CreateBufferObject(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * indexCount, GL_STATIC_DRAW, indexes); |
|
|
|
|
|
|
|
|
|
|
|
/*创建纹理*/ |
|
|
|
|
|
GLuint mainTexture = CreateTextureFromFile("res/image/stone.jpg"); |
|
|
|
|
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
|
|
//glEnable(GL_DEPTH_TEST);
|
|
|
|
|
|
|
|
|
glEnable(GL_DEPTH_TEST); |
|
|
|
|
|
|
|
|
//创建一个单位矩阵和一个投影矩阵,后面用来传递到shader
|
|
|
//创建一个单位矩阵和一个投影矩阵,后面用来传递到shader
|
|
|
float identify[] = { |
|
|
float identify[] = { |
|
@ -124,7 +129,7 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
0,0,1,0, |
|
|
0,0,1,0, |
|
|
0,0,0,1 |
|
|
0,0,0,1 |
|
|
}; |
|
|
}; |
|
|
glm::mat4 model = glm::translate(0.0f, 0.0f, -3.0f); |
|
|
|
|
|
|
|
|
glm::mat4 model = glm::translate(0.0f, 0.0f, -4.0f); |
|
|
glm::mat4 projection = glm::perspective(45.0f, 800.0f/600.0f, 0.1f, 1000.0f); |
|
|
glm::mat4 projection = glm::perspective(45.0f, 800.0f/600.0f, 0.1f, 1000.0f); |
|
|
glm::mat4 normalMatrix = glm::inverseTranspose(model); |
|
|
glm::mat4 normalMatrix = glm::inverseTranspose(model); |
|
|
|
|
|
|
|
@ -134,6 +139,8 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
|
|
|
|
|
/*监听并处理用户请求*/ |
|
|
/*监听并处理用户请求*/ |
|
|
MSG msg; |
|
|
MSG msg; |
|
|
|
|
|
|
|
|
|
|
|
float angle = 0.0; |
|
|
while (true) { |
|
|
while (true) { |
|
|
if (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)) { |
|
|
if (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)) { |
|
|
if (msg.message == WM_QUIT) { |
|
|
if (msg.message == WM_QUIT) { |
|
@ -143,7 +150,16 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
DispatchMessage(&msg); |
|
|
DispatchMessage(&msg); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT); |
|
|
|
|
|
|
|
|
if (angle > 360) { |
|
|
|
|
|
angle = 0; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
angle += 0.01f; |
|
|
|
|
|
} |
|
|
|
|
|
model = glm::translate(0.0f, 0.0f, -4.0f) * glm::rotate(angle, 0.0f, 1.0f, 0.0f); |
|
|
|
|
|
glm::mat4 normalMatrix = glm::inverseTranspose(model); |
|
|
|
|
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
|
|
|
|
|
glUseProgram(program); |
|
|
glUseProgram(program); |
|
|
glUniformMatrix4fv(MLocation, 1, GL_FALSE, glm::value_ptr(model)); |
|
|
glUniformMatrix4fv(MLocation, 1, GL_FALSE, glm::value_ptr(model)); |
|
@ -151,6 +167,9 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
glUniformMatrix4fv(PLocation, 1, GL_FALSE, glm::value_ptr(projection)); |
|
|
glUniformMatrix4fv(PLocation, 1, GL_FALSE, glm::value_ptr(projection)); |
|
|
glUniformMatrix4fv(NMLocation, 1, GL_FALSE, glm::value_ptr(normalMatrix)); |
|
|
glUniformMatrix4fv(NMLocation, 1, GL_FALSE, glm::value_ptr(normalMatrix)); |
|
|
|
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, mainTexture); |
|
|
|
|
|
glUniform1i(textureLocation, 0); |
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vbo); |
|
|
glBindBuffer(GL_ARRAY_BUFFER, vbo); |
|
|
glEnableVertexAttribArray(posLocation); |
|
|
glEnableVertexAttribArray(posLocation); |
|
|
glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)0); |
|
|
glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)0); |
|
|