-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Game is done
- Loading branch information
Showing
24 changed files
with
174 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include "House.h" | ||
#include "stb_image/stb_image.h" | ||
|
||
void House::reset(float newPos) | ||
{ | ||
translation.x = newPos; | ||
} | ||
|
||
void House::render(Renderer& renderer) | ||
{ | ||
m_shader.use(); | ||
glBindTexture(GL_TEXTURE_2D, texture); | ||
|
||
glm::mat4 model = glm::mat4(1.0f); | ||
model = glm::translate(model, translation); | ||
m_shader.setMat4("model", model); | ||
|
||
renderer.render(VAO, EBO); | ||
} | ||
|
||
void House::initTextures() | ||
{ | ||
|
||
m_shader.use(); | ||
glGenTextures(1, &texture); | ||
glBindTexture(GL_TEXTURE_2D, texture); | ||
|
||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); | ||
|
||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
|
||
int width, height, nrChannels; | ||
stbi_set_flip_vertically_on_load(true); | ||
|
||
unsigned char* data = stbi_load("res\\textures\\house.png", &width, &height, &nrChannels, 0); | ||
if (data) | ||
{ | ||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); | ||
glGenerateMipmap(GL_TEXTURE_2D); | ||
} | ||
else | ||
{ | ||
ERROR("Failed to load texture."); | ||
} | ||
stbi_image_free(data); | ||
m_shader.setInt("texture", 0); | ||
} | ||
|
||
House::House(Shader& shader) | ||
: m_shader(shader) | ||
{ | ||
glGenVertexArrays(1, &VAO); | ||
glGenBuffers(1, &VBO); | ||
glGenBuffers(1, &EBO); | ||
|
||
glBindVertexArray(VAO); | ||
|
||
glBindBuffer(GL_ARRAY_BUFFER, VBO); | ||
glBufferData(GL_ARRAY_BUFFER, sizeof(_vertices), _vertices, GL_STATIC_DRAW); | ||
|
||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); | ||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(_indices), _indices, GL_STATIC_DRAW); | ||
|
||
// position attribute | ||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0); | ||
glEnableVertexAttribArray(0); | ||
// texture coord attribute | ||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float))); | ||
glEnableVertexAttribArray(1); | ||
|
||
initTextures(); | ||
|
||
glBindBuffer(GL_ARRAY_BUFFER, 0); | ||
glBindVertexArray(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#pragma once | ||
#include "engine/Renderer.h" | ||
|
||
class House | ||
{ | ||
public: | ||
House(Shader& shader); | ||
void render(Renderer& renderer); | ||
void reset(float newPos); | ||
inline float getPos() { return translation.x; } | ||
private: | ||
|
||
float _vertices[20] = { | ||
// positions // texture coords | ||
0.5f, 0.5f, 0.0f, 1.0f, 1.0f, // top right | ||
0.5f, -0.5f, 0.0f, 1.0f, 0.0f, // bottom right | ||
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, // bottom left | ||
-0.5f, 0.5f, 0.0f, 0.0f, 1.0f // top left | ||
}; | ||
unsigned int _indices[6] = { | ||
0, 1, 3, // first Triangle | ||
1, 2, 3 // second Triangle | ||
}; | ||
unsigned int VAO, VBO, EBO; | ||
|
||
unsigned int texture = 0; | ||
void initTextures(); | ||
|
||
glm::vec3 translation = glm::vec3(10.0f, -0.5f, 0.0f); | ||
|
||
Shader m_shader; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.