diff --git a/.vs/shader2/v14/.suo b/.vs/shader2/v14/.suo index 032b253..aa9fbd5 100644 Binary files a/.vs/shader2/v14/.suo and b/.vs/shader2/v14/.suo differ diff --git a/frustum.cpp b/frustum.cpp index d2179d8..4168a89 100644 --- a/frustum.cpp +++ b/frustum.cpp @@ -54,6 +54,32 @@ void Frustum::InitPerspective(float fov, float aspect, float zNear, float zFar) } +void Frustum::InitOrtho(float left, float right, float bottom, float top, float zNear, float zFar) +{ + + + float vertexes[24] = { + left,bottom,-zNear, + right,bottom,-zNear, + right,top,-zNear, + left,top,-zNear, + + left,bottom,-zFar, + right,bottom,-zFar, + right,top,-zFar, + left,top,-zFar, + }; + + mVBO = CreateBufferObject(GL_ARRAY_BUFFER, sizeof(float) * 24, GL_STATIC_DRAW, vertexes); + + unsigned int indexes[] = { + 0,1,1,2,2,3,3,0, //近剪裁面 + 4,5,5,6,6,7,7,4, //远剪裁面 + 0,4,3,7,2,6,1,5 + }; + mIBO = CreateBufferObject(GL_ELEMENT_ARRAY_BUFFER, sizeof(int) * 24, GL_STATIC_DRAW, indexes); +} + void Frustum::Draw(float* M, float* V, float* P) { glUseProgram(mProgram); diff --git a/frustum.h b/frustum.h index 27ab866..31ae382 100644 --- a/frustum.h +++ b/frustum.h @@ -10,5 +10,6 @@ public: Frustum(); void Init(); void InitPerspective(float fov, float aspect, float zNear, float zFar); + void InitOrtho(float left, float right, float bottom, float top, float zNear, float zFar); void Draw(float* M, float* V, float* P); }; \ No newline at end of file diff --git a/main.cpp b/main.cpp index b694569..68f1d79 100644 --- a/main.cpp +++ b/main.cpp @@ -133,6 +133,8 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine 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 @@ -143,13 +145,14 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine 0,0,0,1 }; - glm::mat4 model = glm::translate(-1.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::rotate(-20.0f, 0.0f, 1.0f, 0.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.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);