Browse Source

绘制点精灵

master
blobt 4 years ago
parent
commit
5594b8886d
  1. BIN
      .vs/shader2/v14/.suo
  2. 14
      main.cpp
  3. 5
      res/shader/PointSprite.fs
  4. 13
      res/shader/PointSprite.vs
  5. 7
      shader2.vcxproj
  6. 13
      shader2.vcxproj.filters

BIN
.vs/shader2/v14/.suo

14
main.cpp

@ -90,7 +90,7 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
glewInit();
/*创建program*/
GLuint program = CreateGPUProgram("res/shader/UI FullScreemQuad.vs", "res/shader/UI.fs");
GLuint program = CreateGPUProgram("res/shader/PointSprite.vs", "res/shader/PointSprite.fs");
GLuint posLocation, texcoordLocation, normalLocation, MLocation, VLocation, PLocation, NMLocation, textureLocation;
posLocation = glGetAttribLocation(program, "pos");
@ -115,6 +115,9 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
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);
@ -125,8 +128,10 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
GLuint mainTexture = CreateTextureFromFile("res/image/stone.jpg");
GLuint secondTexture = CreateTextureFromDds("res/image/150001.dds");
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClearColor(0.1f, 0.4f, 0.7f, 1.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_POINT_SPRITE);
glEnable(GL_PROGRAM_POINT_SIZE);
glViewport(0,0, windowWidth, windowHeight);
//创建一个单位矩阵和一个投影矩阵,后面用来传递到shader
@ -170,7 +175,7 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, 0);
glDrawElements(GL_POINTS, 1, GL_UNSIGNED_INT, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glUseProgram(0);
};
@ -185,9 +190,6 @@ INT WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_SCISSOR_TEST);
glScissor(400,300, 100, 100);
what();
SwapBuffers(dc);

5
res/shader/PointSprite.fs

@ -0,0 +1,5 @@
uniform sampler2D U_MainTexture;
void main()
{
gl_FragColor=texture2D(U_MainTexture,gl_PointCoord.xy);
}

13
res/shader/PointSprite.vs

@ -0,0 +1,13 @@
attribute vec3 pos;
attribute vec2 texcoord;
attribute vec3 normal;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
void main()
{
gl_PointSize = 30.0;
gl_Position=P*V*M*vec4(pos,1.0);
}

7
shader2.vcxproj

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

13
shader2.vcxproj.filters

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