Browse Source

调整到渲染大理石材质球

master
blobt 4 years ago
parent
commit
e1d08a591e
  1. BIN
      .vs/shader2/v14/.suo
  2. 26
      main.cpp
  3. 6
      shader2.vcxproj
  4. 10
      shader2.vcxproj.filters

BIN
.vs/shader2/v14/.suo

26
main.cpp

@ -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);

6
shader2.vcxproj

@ -159,10 +159,8 @@
<ClInclude Include="timer.h" />
</ItemGroup>
<ItemGroup>
<None Include="res\shader\PointSprite.fs" />
<None Include="res\shader\PointSprite.vs" />
<None Include="res\shader\WhiteColor.fs" />
<None Include="res\shader\WhiteColor.vs" />
<None Include="res\shader\test.fs" />
<None Include="res\shader\test.vs" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

10
shader2.vcxproj.filters

@ -46,16 +46,10 @@
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="res\shader\WhiteColor.fs">
<None Include="res\shader\test.fs">
<Filter>源文件</Filter>
</None>
<None Include="res\shader\WhiteColor.vs">
<Filter>源文件</Filter>
</None>
<None Include="res\shader\PointSprite.fs">
<Filter>源文件</Filter>
</None>
<None Include="res\shader\PointSprite.vs">
<None Include="res\shader\test.vs">
<Filter>源文件</Filter>
</None>
</ItemGroup>
Loading…
Cancel
Save