@@ -71,6 +71,7 @@ Game::Game(int initial_pos_x, int initial_pos_y) :
7171 CreateRocketBuffers ();
7272 CreateAsteroidBuffers ();
7373 CreateBulletBuffers ();
74+ CreateGameOverBuffers ();
7475 GenerateAsteroids (Constants::nrOfAsteroidsPerFrame);
7576}
7677
@@ -90,7 +91,7 @@ void Game::InitializeLibraries() {
9091
9192void Game::CreateShaders () {
9293 ProgramId = LoadShaders (" vertShader.vert" , " fragShader.frag" );
93- TextureProgramId = LoadShaders (" asteroidTextureShader .vert" , " asteroidTextureShader .frag" );
94+ TextureProgramId = LoadShaders (" textureShader .vert" , " textureShader .frag" );
9495 glUseProgram (ProgramId);
9596}
9697
@@ -120,6 +121,7 @@ void Game::DestroyVBO(void) {
120121 glDeleteBuffers (1 , &squareVbo);
121122 glDeleteBuffers (1 , &heartColorBufferId);
122123 glDeleteBuffers (1 , &heartVbo);
124+ glDeleteBuffers (1 , &gameOverVbo);
123125
124126 glBindVertexArray (0 );
125127}
@@ -175,11 +177,21 @@ void Game::RenderFunction(void) {
175177 Rocket* rocket = Rocket::getInstance ();
176178
177179 glClearColor (0 .0f , 0 .0f , 0 .0f , 1 .0f );
178- glClear (GL_COLOR_BUFFER_BIT);
180+ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
179181
180182 if (rocket->getIsDead ()) {
181- // TODO: render a png with the text GAME OVER
182- // glutSwapBuffers();
183+ glUseProgram (TextureProgramId);
184+ myMatrixLocation = glGetUniformLocation (TextureProgramId, " myMatrix" );
185+
186+ glActiveTexture (GL_TEXTURE0);
187+ glBindTexture (GL_TEXTURE_2D, gameOverTexture);
188+
189+ glm::mat4 gameOverMatrix = backgroundMatrix;
190+ glUniformMatrix4fv (myMatrixLocation, 1 , GL_FALSE, &gameOverMatrix[0 ][0 ]);
191+ glBindVertexArray (gameOverVao);
192+ glDrawArrays (GL_POLYGON, 0 , 4 );
193+
194+ glFlush ();
183195 return ;
184196 }
185197
@@ -391,7 +403,7 @@ void Game::CreateRocketBuffers() {
391403 glBindBuffer (GL_ARRAY_BUFFER, squareVbo);
392404 glBufferData (GL_ARRAY_BUFFER, sizeof (Square), Square, GL_STATIC_DRAW);
393405
394- glGenVertexArrays (1 , &squareVbo );
406+ glGenVertexArrays (1 , &squareVao );
395407 glBindVertexArray (squareVao);
396408
397409 glVertexAttribPointer (0 , 4 , GL_FLOAT, GL_FALSE, 0 , 0 );
@@ -516,7 +528,8 @@ void Game::loadTextures() {
516528 GLuint texture;
517529 LoadTexture (texture, imageName);
518530 Game::textures.push_back (texture);
519- }
531+ }
532+ LoadTexture (gameOverTexture, Constants::gameOverTexture);
520533}
521534
522535void Game::CreateBulletBuffers () {
@@ -676,3 +689,29 @@ void Game::CreateHeartBuffers() {
676689 glVertexAttribPointer (1 , 4 , GL_FLOAT, GL_FALSE, 0 , 0 );
677690 glEnableVertexAttribArray (1 );
678691}
692+
693+ void Game::CreateGameOverBuffers () {
694+ GLfloat Vertices[] = {
695+ 0 .0f , 0 .0f , 0 .0f , 1 .0f , 0 .0f , 0 .0f , 0 .0f , 0 .0f , 0 .0f ,
696+ Constants::maxX, 0 .0f , 0 .0f , 1 .0f , 0 .0f , 0 .0f , 0 .0f , 1 .0f , 0 .0f ,
697+ Constants::maxX, Constants::maxY, 0 .0f , 1 .0f , 0 .0f , 0 .0f , 0 .0f , 1 .0f , 1 .0f ,
698+ 0 .0f , Constants::maxY, 0 .0f , 1 .0f , 0 .0f , 0 .0f , 0 .0f , 0 .0f , 1 .0f ,
699+ };
700+
701+ glGenVertexArrays (1 , &gameOverVao);
702+ glGenBuffers (1 , &gameOverVbo);
703+
704+ glBindVertexArray (gameOverVao);
705+
706+ glBindBuffer (GL_ARRAY_BUFFER, gameOverVbo);
707+ glBufferData (GL_ARRAY_BUFFER, sizeof (Vertices), Vertices, GL_STATIC_DRAW);
708+
709+ glEnableVertexAttribArray (0 );
710+ glVertexAttribPointer (0 , 4 , GL_FLOAT, GL_FALSE, 9 * sizeof (GLfloat), (GLvoid*)0 );
711+
712+ glEnableVertexAttribArray (1 );
713+ glVertexAttribPointer (1 , 3 , GL_FLOAT, GL_FALSE, 9 * sizeof (GLfloat), (GLvoid*)(4 * sizeof (GLfloat)));
714+
715+ glEnableVertexAttribArray (2 );
716+ glVertexAttribPointer (2 , 2 , GL_FLOAT, GL_FALSE, 9 * sizeof (GLfloat), (GLvoid*)(7 * sizeof (GLfloat)));
717+ }
0 commit comments