diff --git a/.vs/shader2/v14/.suo b/.vs/shader2/v14/.suo
index a243411..7e7dfc2 100644
Binary files a/.vs/shader2/v14/.suo and b/.vs/shader2/v14/.suo differ
diff --git a/main.cpp b/main.cpp
index 797b63b..d028fd1 100644
--- a/main.cpp
+++ b/main.cpp
@@ -91,18 +91,16 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
glewInit();
/*创建program*/
- GLuint program = CreateGPUProgram("res/shader/MixLightMT.vs", "res/shader/MixLightMT.fs");
+ GLuint program = CreateGPUProgram("res/shader/ViewDepthMap.vs", "res/shader/ViewDepthMap.fs");
- GLuint posLocation, texcoordLocation, normalLocation, MLocation, VLocation, PLocation, NMLocation, textureLocation, offsetLocation;
+ GLuint posLocation, texcoordLocation, normalLocation, MLocation, VLocation, PLocation;
posLocation = glGetAttribLocation(program, "pos");
texcoordLocation = glGetAttribLocation(program, "texcoord");
normalLocation = glGetAttribLocation(program, "normal");
- offsetLocation = glGetAttribLocation(program, "offset");
+
MLocation = glGetUniformLocation(program, "M");
VLocation = glGetUniformLocation(program, "V");
PLocation = glGetUniformLocation(program, "P");
- NMLocation = glGetUniformLocation(program, "NM");
- textureLocation = glGetUniformLocation(program, "U_MainTexture");
/*load model*/
unsigned int *indexes = nullptr;
@@ -121,10 +119,10 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glEnableVertexAttribArray(posLocation);
glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)0);
- glEnableVertexAttribArray(texcoordLocation);
+ /*glEnableVertexAttribArray(texcoordLocation);
glVertexAttribPointer(texcoordLocation, 2, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)(sizeof(float) * 3));
glEnableVertexAttribArray(normalLocation);
- glVertexAttribPointer(normalLocation, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)(sizeof(float) * 5));
+ glVertexAttribPointer(normalLocation, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), (void*)(sizeof(float) * 5));*/
glBindBuffer(GL_ARRAY_BUFFER, 0);
/*创建IBO*/
@@ -133,10 +131,6 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
/*创建纹理*/
GLuint mainTexture = CreateTextureFromFile("res/image/niutou.bmp");
- /*创建FBO*/
- GLuint colorBuffer, depthBuffer, colorBuffer2;
- GLuint fbo = CreateFramebufferObject(colorBuffer, depthBuffer, windowWidth, windowHeight, &colorBuffer2);
-
glViewport(0, 0, windowWidth, windowHeight);
GL_CALL(glClearColor(0.1f, 0.4f, 0.7f, 1.0f));
@@ -150,7 +144,7 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
0,0,0,1
};
- glm::mat4 model = glm::translate(0.0f, -0.5f, -3.0f) * glm::rotate(-90.0f, 0.0f, 1.0f, 0.0f)*glm::scale(0.01f,0.01f,0.01f);
+ glm::mat4 model = glm::translate(0.0f, -0.5f, -2.0f) * glm::rotate(-90.0f, 0.0f, 1.0f, 0.0f)*glm::scale(0.01f,0.01f,0.01f);
glm::mat4 projection = glm::perspective(45.0f, (float)windowWidth / (float)windowHeight, 0.1f, 1000.0f);
glm::mat4 normalMatrix = glm::inverseTranspose(model);
@@ -169,10 +163,6 @@ 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));
-
- glBindTexture(GL_TEXTURE_2D, colorBuffer);
- glUniform1i(textureLocation, 0);
glUniformMatrix4fv(MLocation, 1, GL_FALSE, glm::value_ptr(model));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
@@ -198,37 +188,10 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
}
//绘制内容到fbo
- glBindFramebuffer(GL_FRAMEBUFFER, fbo);
GL_CALL(glClearColor(0.1f, 0.4f, 0.7f, 1.0f));
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
what();
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
- //把fbo绘制到一个四边形上
- GL_CALL(glClearColor(0.5f, 0.4f, 0.7f, 1.0f));
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_SCISSOR_TEST);
-
- glBindTexture(GL_TEXTURE_2D, colorBuffer);
- glScissor(0, 0, windowWidth, windowHeight/2);
- glBegin(GL_QUADS);
- glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, -0.5f, -1.0f);
- glTexCoord2f(1.0f, 0.0f); glVertex3f(0.5f, -0.5f, -1.0f);
- glTexCoord2f(1.0f, 1.0f); glVertex3f(0.5f, 0.5f, -1.0f);
- glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, 0.5f, -1.0f);
- glEnd();
-
- glBindTexture(GL_TEXTURE_2D, colorBuffer2);
- glScissor(0, windowHeight / 2, windowWidth, windowHeight / 2);
- glBegin(GL_QUADS);
- glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, -0.5f, -1.0f);
- glTexCoord2f(1.0f, 0.0f); glVertex3f(0.5f, -0.5f, -1.0f);
- glTexCoord2f(1.0f, 1.0f); glVertex3f(0.5f, 0.5f, -1.0f);
- glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, 0.5f, -1.0f);
- glEnd();
-
- glDisable(GL_SCISSOR_TEST);
SwapBuffers(dc);
}
diff --git a/res/shader/ViewDepthMap.fs b/res/shader/ViewDepthMap.fs
new file mode 100644
index 0000000..d0f8368
--- /dev/null
+++ b/res/shader/ViewDepthMap.fs
@@ -0,0 +1,3 @@
+void main() {
+ gl_FragColor = vec4(vec3(pow(gl_FragCoord.z,32.0)), 1.0);
+}
\ No newline at end of file
diff --git a/res/shader/ViewDepthMap.vs b/res/shader/ViewDepthMap.vs
new file mode 100644
index 0000000..00b37d2
--- /dev/null
+++ b/res/shader/ViewDepthMap.vs
@@ -0,0 +1,10 @@
+attribute vec3 pos;
+attribute vec2 texcoord;
+attribute vec3 normal;
+
+uniform mat4 M;
+uniform mat4 V;
+uniform mat4 P;
+void main() {
+ gl_Position = P*V*M*vec4(pos, 1.0);
+}
\ No newline at end of file
diff --git a/shader2.vcxproj b/shader2.vcxproj
index 14aeab5..bfff430 100644
--- a/shader2.vcxproj
+++ b/shader2.vcxproj
@@ -159,8 +159,8 @@
-
-
+
+
diff --git a/shader2.vcxproj.filters b/shader2.vcxproj.filters
index 9ed379d..2a8311c 100644
--- a/shader2.vcxproj.filters
+++ b/shader2.vcxproj.filters
@@ -46,10 +46,10 @@
-
+
婧愭枃浠
-
+
婧愭枃浠