Sanjay Madhav 8 лет назад
Родитель
Сommit
29fac34f2a
6 измененных файлов с 19 добавлено и 13 удалено
  1. 1 1
      Chapter05/Actor.cpp
  2. 3 2
      Chapter05/Game.cpp
  3. 7 7
      Chapter05/Shader.cpp
  4. 1 1
      Chapter05/Shader.h
  5. 1 2
      Chapter05/VertexArray.cpp
  6. 6 0
      Chapter05/VertexArray.h

+ 1 - 1
Chapter05/Actor.cpp

@@ -17,7 +17,7 @@ Actor::Actor(Game* game)
 	,mScale(1.0f)
 	,mRotation(0.0f)
 	,mGame(game)
-	,mRecomputeWorldTransform(false)
+	,mRecomputeWorldTransform(true)
 {
 	mGame->AddActor(this);
 }

+ 3 - 2
Chapter05/Game.cpp

@@ -51,7 +51,7 @@ bool Game::Initialize()
 	// Force OpenGL to use hardware acceleration
 	SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
 	
-	mWindow = SDL_CreateWindow("Game Programming in C++ (Chapter 6)", 100, 100,
+	mWindow = SDL_CreateWindow("Game Programming in C++ (Chapter 5)", 100, 100,
 							   1024, 768, SDL_WINDOW_OPENGL);
 	if (!mWindow)
 	{
@@ -165,6 +165,7 @@ void Game::UpdateGame()
 	// Move any pending actors to mActors
 	for (auto pending : mPendingActors)
 	{
+		pending->ComputeWorldTransform();
 		mActors.emplace_back(pending);
 	}
 	mPendingActors.clear();
@@ -214,7 +215,7 @@ void Game::GenerateOutput()
 bool Game::LoadShaders()
 {
 	mSpriteShader = new Shader();
-	if (!mSpriteShader->Load("Shaders/Sprite"))
+	if (!mSpriteShader->Load("Shaders/Sprite.vert", "Shaders/Sprite.frag"))
 	{
 		return false;
 	}

+ 7 - 7
Chapter05/Shader.cpp

@@ -25,15 +25,15 @@ Shader::~Shader()
 
 }
 
-bool Shader::Load(const std::string& name)
+bool Shader::Load(const std::string& vertName, const std::string& fragName)
 {
 	// Compile vertex and pixel shaders
-	if (!CompileShader(name + ".vert",
-					   GL_VERTEX_SHADER,
-					   mVertexShader) ||
-		!CompileShader(name + ".frag",
-					   GL_FRAGMENT_SHADER,
-					   mFragShader))
+	if (!CompileShader(vertName,
+		GL_VERTEX_SHADER,
+		mVertexShader) ||
+		!CompileShader(fragName,
+			GL_FRAGMENT_SHADER,
+			mFragShader))
 	{
 		return false;
 	}

+ 1 - 1
Chapter05/Shader.h

@@ -18,7 +18,7 @@ public:
 	~Shader();
 	// Load shader of the specified name, excluding
 	// the .frag/.vert extension
-	bool Load(const std::string& name);
+	bool Load(const std::string& vertName, const std::string& fragName);
 	void Unload();
 	// Set this as the active shader program
 	void SetActive();

+ 1 - 2
Chapter05/VertexArray.cpp

@@ -26,7 +26,7 @@ VertexArray::VertexArray(const float* verts, unsigned int numVerts,
 	// Create index buffer
 	glGenBuffers(1, &mIndexBuffer);
 	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
-	glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices * sizeof(GLuint), indices, GL_STATIC_DRAW);
+	glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices * sizeof(unsigned int), indices, GL_STATIC_DRAW);
 
 	// Specify the vertex attributes
 	// (For now, assume one vertex format)
@@ -48,5 +48,4 @@ VertexArray::~VertexArray()
 void VertexArray::SetActive()
 {
 	glBindVertexArray(mVertexArray);
-	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
 }

+ 6 - 0
Chapter05/VertexArray.h

@@ -14,11 +14,17 @@ public:
 		const unsigned int* indices, unsigned int numIndices);
 	~VertexArray();
 
+	// Activate this vertex array (so we can draw it)
 	void SetActive();
 private:
+	// How many vertices in the vertex buffer?
 	unsigned int mNumVerts;
+	// How many indices in the index buffer
 	unsigned int mNumIndices;
+	// OpenGL ID of the vertex buffer
 	unsigned int mVertexBuffer;
+	// OpenGL ID of the index buffer
 	unsigned int mIndexBuffer;
+	// OpenGL ID of the vertex array object
 	unsigned int mVertexArray;
 };