From 79bc1ac86329b21b80b810b37d2426a724e08b30 Mon Sep 17 00:00:00 2001 From: blobt Date: Wed, 23 Sep 2020 10:39:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dframework=20bug=EF=BC=8C?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0RGB=20Cube?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Res/rgbcube.fs | 8 ++++ Res/rgbcube.vs | 12 ++++++ model.cpp | 6 +-- renderFramework.vcxproj | 9 +++++ renderFramework.vcxproj.filters | 65 +++++++++++++++++++-------------- scene.cpp | 13 +++++++ shader.cpp | 2 +- 7 files changed, 83 insertions(+), 32 deletions(-) create mode 100644 Res/rgbcube.fs create mode 100644 Res/rgbcube.vs diff --git a/Res/rgbcube.fs b/Res/rgbcube.fs new file mode 100644 index 0000000..2f90d25 --- /dev/null +++ b/Res/rgbcube.fs @@ -0,0 +1,8 @@ +#ifdef GL_ES +precision mediump float; +#endif +varying vec4 V_Color; +void main() +{ + gl_FragColor=V_Color; +} \ No newline at end of file diff --git a/Res/rgbcube.vs b/Res/rgbcube.vs new file mode 100644 index 0000000..7f32ccb --- /dev/null +++ b/Res/rgbcube.vs @@ -0,0 +1,12 @@ +#ifdef GL_ES +precision mediump float; +#endif; +attribute vec4 position; +uniform mat4 ModelMatrix; +uniform mat4 ViewMatrix; +uniform mat4 ProjectionMatrix; +varying vec4 V_Color; +void main(){ + V_Color = vec4(position.x + 0.5, position.y+0.5, position.z +0.5, 1.0); + gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * position; +} \ No newline at end of file diff --git a/model.cpp b/model.cpp index c8657e8..29eb732 100644 --- a/model.cpp +++ b/model.cpp @@ -141,11 +141,11 @@ void Model::createVertexBuffer() glm::float3 t; mVertexBuffer->SetSize(vertexCount); for (int i = 0; i < vertexCount; ++i) { - t = position[vertices[i].position - 1]; + t = position[vertices[i].position]; mVertexBuffer->SetPosition(i, t[0], t[1], t[2]); - t = texcoord[vertices[i].texcoord - 1]; + t = texcoord[vertices[i].texcoord]; mVertexBuffer->SetTexcoord(i, t[0], t[1]); - t = normal[vertices[i].normal - 1]; + t = normal[vertices[i].normal]; mVertexBuffer->SetNormal(i, t[0], t[1], t[2]); } } diff --git a/renderFramework.vcxproj b/renderFramework.vcxproj index 75fe671..c6f5e70 100644 --- a/renderFramework.vcxproj +++ b/renderFramework.vcxproj @@ -82,6 +82,9 @@ Windows + + editbin /subsystem:console $(OutDir)$(ProjectName).exe + @@ -127,6 +130,7 @@ + @@ -136,6 +140,7 @@ + @@ -143,6 +148,10 @@ + + + + diff --git a/renderFramework.vcxproj.filters b/renderFramework.vcxproj.filters index 4bbf003..946d7f0 100644 --- a/renderFramework.vcxproj.filters +++ b/renderFramework.vcxproj.filters @@ -5,13 +5,8 @@ {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + {a3e69115-b076-4917-a38c-f8c6f3a7021c} @@ -21,43 +16,57 @@ 源文件 - - 源文件 + + framework - - 源文件 + + framework + + + framework - 源文件 + framework - - 源文件 + + framework - - 源文件 + + framework - - 源文件 - 源文件 - - 源文件 + + framework - - 源文件 + + framework - - 源文件 + + framework - 源文件 + framework - - 源文件 + + framework + + + framework + + + framework + + + 源文件 + + + 源文件 + + \ No newline at end of file diff --git a/scene.cpp b/scene.cpp index f3ea46b..0d0a761 100644 --- a/scene.cpp +++ b/scene.cpp @@ -1,13 +1,26 @@ #include "scene.h" +#include "utils.h" +#include "model.h" +glm::mat4 viewMatrix, projectionMatrix; +glm::vec3 cameraPos(4.0f, 3.0f, 4.0f); +Model model; void Init() { + model.Init("Res/Cube.obj"); + model.mShader->Init("Res/rgbcube.vs", "Res/rgbcube.fs"); + model.SetPosition(0.0f, 0.0f, 0.0f); + viewMatrix = glm::lookAt(cameraPos, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f)); } void SetViewPortSize(float width, float height) { + projectionMatrix = glm::perspective(50.0f, width/height, 0.1f, 1000.0f); } void Draw() { + glClearColor(0.0f,0.0f,0.0f,1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + model.Draw(viewMatrix, projectionMatrix, cameraPos.x, cameraPos.y, cameraPos.z); } diff --git a/shader.cpp b/shader.cpp index 31c9acb..4a9eacf 100644 --- a/shader.cpp +++ b/shader.cpp @@ -45,7 +45,7 @@ void Shader::Init(const char * vs, const char * fs) { int nFileSize = 0; const char* vsCode = (char*)LoadFileContent(vs, nFileSize); - const char* fsCode = (char*)LoadFileContent(vs, nFileSize); + const char* fsCode = (char*)LoadFileContent(fs, nFileSize); GLuint vsShader = CompileShader(GL_VERTEX_SHADER, vsCode); if (vsShader == 0) { return;