ソースを参照

Chapter 5 revisions complete?

Sanjay Madhav 8 年 前
コミット
ecafeb593b

+ 2 - 3
Chapter05/Game.cpp

@@ -178,7 +178,7 @@ void Game::UpdateGame()
 
 
 void Game::GenerateOutput()
 void Game::GenerateOutput()
 {
 {
-	// Set the clear color to dark green
+	// Set the clear color to grey
 	glClearColor(0.86f, 0.86f, 0.86f, 1.0f);
 	glClearColor(0.86f, 0.86f, 0.86f, 1.0f);
 	// Clear the color buffer
 	// Clear the color buffer
 	glClear(GL_COLOR_BUFFER_BIT);
 	glClear(GL_COLOR_BUFFER_BIT);
@@ -186,8 +186,7 @@ void Game::GenerateOutput()
 	// Draw all sprite components
 	// Draw all sprite components
 	// Enable alpha blending on the color buffer
 	// Enable alpha blending on the color buffer
 	glEnable(GL_BLEND);
 	glEnable(GL_BLEND);
-	glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
-	glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
+	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 	
 	
 	// Set shader/vao as active
 	// Set shader/vao as active
 	mSpriteShader->SetActive();
 	mSpriteShader->SetActive();

+ 1 - 0
Chapter05/Game.vcxproj

@@ -50,6 +50,7 @@
     <None Include="Shaders\Basic.vert" />
     <None Include="Shaders\Basic.vert" />
     <None Include="Shaders\Sprite.frag" />
     <None Include="Shaders\Sprite.frag" />
     <None Include="Shaders\Sprite.vert" />
     <None Include="Shaders\Sprite.vert" />
+    <None Include="Shaders\Transform.vert" />
   </ItemGroup>
   </ItemGroup>
   <PropertyGroup Label="Globals">
   <PropertyGroup Label="Globals">
     <ProjectGuid>{BC508D87-495F-4554-932D-DD68388B63CC}</ProjectGuid>
     <ProjectGuid>{BC508D87-495F-4554-932D-DD68388B63CC}</ProjectGuid>

+ 3 - 0
Chapter05/Game.vcxproj.filters

@@ -119,5 +119,8 @@
     <None Include="Shaders\Basic.vert">
     <None Include="Shaders\Basic.vert">
       <Filter>Shaders</Filter>
       <Filter>Shaders</Filter>
     </None>
     </None>
+    <None Include="Shaders\Transform.vert">
+      <Filter>Shaders</Filter>
+    </None>
   </ItemGroup>
   </ItemGroup>
 </Project>
 </Project>

+ 1 - 1
Chapter05/Shaders/Sprite.frag

@@ -21,5 +21,5 @@ uniform sampler2D uTexture;
 void main()
 void main()
 {
 {
 	// Sample color from texture
 	// Sample color from texture
-    outColor = texture(uTexture, fragTexCoord);
+	outColor = texture(uTexture, fragTexCoord);
 }
 }

+ 2 - 2
Chapter05/Shaders/Sprite.vert

@@ -17,14 +17,14 @@ uniform mat4 uViewProj;
 layout(location = 0) in vec3 inPosition;
 layout(location = 0) in vec3 inPosition;
 layout(location = 1) in vec2 inTexCoord;
 layout(location = 1) in vec2 inTexCoord;
 
 
-// Any vertex outputs (other than position)
+// Add texture coordinate as output
 out vec2 fragTexCoord;
 out vec2 fragTexCoord;
 
 
 void main()
 void main()
 {
 {
 	// Convert position to homogeneous coordinates
 	// Convert position to homogeneous coordinates
 	vec4 pos = vec4(inPosition, 1.0);
 	vec4 pos = vec4(inPosition, 1.0);
-	// Transform to position world space, then clip space
+	// Transform position to world space, then clip space
 	gl_Position = pos * uWorldTransform * uViewProj;
 	gl_Position = pos * uWorldTransform * uViewProj;
 
 
 	// Transform
 	// Transform

+ 23 - 0
Chapter05/Shaders/Transform.vert

@@ -0,0 +1,23 @@
+// ----------------------------------------------------------------
+// From Game Programming in C++ by Sanjay Madhav
+// Copyright (C) 2017 Sanjay Madhav. All rights reserved.
+// 
+// Released under the BSD License
+// See LICENSE in root directory for full details.
+// ----------------------------------------------------------------
+
+// Request GLSL 3.3
+#version 330
+
+// Uniforms for world transform and view-proj
+uniform mat4 uWorldTransform;
+uniform mat4 uViewProj;
+
+// Vertex attributes
+in vec3 inPosition;
+
+void main()
+{
+	vec4 pos = vec4(inPosition, 1.0);
+	gl_Position = pos * uWorldTransform * uViewProj;
+}

+ 1 - 1
Chapter05/Texture.cpp

@@ -51,7 +51,7 @@ bool Texture::Load(const std::string& fileName)
 	
 	
 	SOIL_free_image_data(image);
 	SOIL_free_image_data(image);
 	
 	
-	// Enable linear filtering
+	// Enable bilinear filtering
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 	
 	

+ 2 - 0
Chapter05/Texture.h

@@ -22,7 +22,9 @@ public:
 	int GetWidth() const { return mWidth; }
 	int GetWidth() const { return mWidth; }
 	int GetHeight() const { return mHeight; }
 	int GetHeight() const { return mHeight; }
 private:
 private:
+	// OpenGL ID of this texture
 	unsigned int mTextureID;
 	unsigned int mTextureID;
+	// Width/height of the texture
 	int mWidth;
 	int mWidth;
 	int mHeight;
 	int mHeight;
 };
 };