|
|
@ -91,7 +91,7 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
glewInit(); |
|
|
|
|
|
|
|
/*创建program*/ |
|
|
|
GLuint program = CreateGPUProgram("res/shader/PointSprite.vs", "res/shader/PointSprite.fs"); |
|
|
|
GLuint program = CreateGPUProgram("res/shader/test.vs", "res/shader/test.fs"); |
|
|
|
|
|
|
|
GLuint posLocation, texcoordLocation, normalLocation, MLocation, VLocation, PLocation, NMLocation, textureLocation; |
|
|
|
posLocation = glGetAttribLocation(program, "pos"); |
|
|
@ -109,16 +109,13 @@ 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/Sphere.obj", &indexes, vertexCount, indexCount); |
|
|
|
printf("load model cost %fs %d\n", t.GetPassedTime(), t.GetPassedTickers()); |
|
|
|
|
|
|
|
if (vertexes == nullptr) { |
|
|
|
printf("load obj model fail\n"); |
|
|
|
} |
|
|
|
|
|
|
|
vertexes[0].position[0] = 0.0f; |
|
|
|
vertexes[0].position[1] = 0.0f; |
|
|
|
|
|
|
|
/*创建vbo*/ |
|
|
|
GLuint vbo = CreateBufferObject(GL_ARRAY_BUFFER, sizeof(VertexData) * vertexCount, GL_STATIC_DRAW, vertexes); |
|
|
|
|
|
|
@ -127,14 +124,10 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
|
|
|
|
/*创建纹理*/ |
|
|
|
GLuint mainTexture = CreateTextureFromFile("res/image/stone.jpg"); |
|
|
|
GLuint secondTexture = CreateTextureFromDds("res/image/camera.dds"); |
|
|
|
|
|
|
|
glClearColor(0.1f, 0.4f, 0.7f, 1.0f); |
|
|
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f); |
|
|
|
glEnable(GL_DEPTH_TEST); |
|
|
|
glEnable(GL_POINT_SPRITE); |
|
|
|
glEnable(GL_PROGRAM_POINT_SIZE); |
|
|
|
glEnable(GL_BLEND); |
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
|
|
|
|
|
glViewport(0,0, windowWidth, windowHeight); |
|
|
|
|
|
|
|
//创建一个单位矩阵和一个投影矩阵,后面用来传递到shader
|
|
|
@ -145,14 +138,10 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
0,0,0,1 |
|
|
|
}; |
|
|
|
|
|
|
|
glm::mat4 model = glm::translate(0.0f, 0.0f, -3.0f)*glm::rotate(-20.0f, 0.0f, 1.0f, 0.0f); |
|
|
|
glm::mat4 model = glm::translate(0.0f, 0.0f, -3.0f); |
|
|
|
glm::mat4 projection = glm::perspective(45.0f, (float)windowWidth / (float)windowHeight, 0.1f, 1000.0f); |
|
|
|
glm::mat4 normalMatrix = glm::inverseTranspose(model); |
|
|
|
|
|
|
|
Frustum frustum; |
|
|
|
frustum.Init(); |
|
|
|
//frustum.InitPerspective(45.0f, (float)windowWidth / (float)windowHeight, 0.1f, 4.0f);
|
|
|
|
frustum.InitOrtho(-0.5f, 0.5f,-0.5, 0.5,0.1f,4.0f); |
|
|
|
|
|
|
|
/*显示窗口*/ |
|
|
|
ShowWindow(hwnd, SW_SHOW); |
|
|
@ -170,7 +159,7 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
glUniformMatrix4fv(PLocation, 1, GL_FALSE, glm::value_ptr(projection)); |
|
|
|
glUniformMatrix4fv(NMLocation, 1, GL_FALSE, glm::value_ptr(normalMatrix)); |
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, secondTexture); |
|
|
|
glBindTexture(GL_TEXTURE_2D, mainTexture); |
|
|
|
glUniform1i(textureLocation, 0); |
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vbo); |
|
|
@ -183,7 +172,7 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0); |
|
|
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo); |
|
|
|
glDrawElements(GL_POINTS, 1, GL_UNSIGNED_INT, 0); |
|
|
|
glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, 0); |
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
|
|
|
glUseProgram(0); |
|
|
|
}; |
|
|
@ -198,7 +187,6 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine |
|
|
|
} |
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
|
frustum.Draw(glm::value_ptr(model), identify, glm::value_ptr(projection)); |
|
|
|
what(); |
|
|
|
|
|
|
|
SwapBuffers(dc); |
|
|
|