pull/3/head
E. Almqvist 2 years ago
parent 92b0e38468
commit c5bde46c08
  1. BIN
      assets/textures/meep.jpg
  2. 93
      src/main.cpp
  3. 4
      src/renderer.cpp
  4. 2
      src/textures.cpp

Binary file not shown.

After

Width:  |  Height:  |  Size: 752 KiB

@ -58,17 +58,89 @@ int main() {
return 1; return 1;
} }
// std::vector<float> verts({
// 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
// 0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
// -0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
// -0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
// });
std::vector<float> verts({ std::vector<float> verts({
0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, -0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
-0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
-0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
-0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
-0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
-0.5f, -0.5f, 0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
0.5f, -0.5f, 0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 1.0f, 1.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.0f, 1.0f,
-0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
0.5f, 0.5f, 0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
-0.5f, 0.5f, 0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
-0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f
}); });
// Vert struc: x y z r g b tx ty // Vert struc: x y z r g b tx ty
std::vector<unsigned int> indices({ std::vector<unsigned int> indices({
0, 1, 3, 0, 1, 3,
1, 2, 3 3, 4, 5,
5, 6, 7,
7, 8, 9,
9, 10, 11,
11, 12, 13,
0, 1, 3,
3, 4, 5,
5, 6, 7,
7, 8, 9,
9, 10, 11,
11, 12, 13,
0, 1, 3,
3, 4, 5,
5, 6, 7,
7, 8, 9,
9, 10, 11,
11, 12, 13,
0, 1, 3,
3, 4, 5,
5, 6, 7,
7, 8, 9,
9, 10, 11,
11, 12, 13,
0, 1, 3,
3, 4, 5,
5, 6, 7,
7, 8, 9,
9, 10, 11,
11, 12, 13,
}); });
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
@ -78,10 +150,15 @@ int main() {
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
Renderer::Obj2D ro(verts, indices); Renderer::Obj2D ro(verts, indices);
renderer.spawnObject(ro); Renderer::Obj2D ro2(verts, indices);
renderer.setCamera(glm::vec3(0.0f, 0.0f, -8.0f));
ro2.setTexture("assets/textures/meep.jpg");
ro.setTexture(RUSTY_METAL_TEXTURE); ro.setTexture(RUSTY_METAL_TEXTURE);
renderer.spawnObject(ro);
renderer.spawnObject(ro2);
renderer.setCamera(glm::vec3(0.0f, 0.0f, -4.0f));
// Window width & height // Window width & height
while (!glfwWindowShouldClose(win)) { while (!glfwWindowShouldClose(win)) {
// Handle input // Handle input
@ -93,7 +170,7 @@ int main() {
/* OBJECT RENDERING */ /* OBJECT RENDERING */
float time = glfwGetTime(); float time = glfwGetTime();
float gVal = sin(time) / 10.5f; float gVal = sin(time) / 10.5f;
renderer.setCamera(glm::vec3(0.0f, 0.0f, -gVal)); renderer.setCamera(glm::vec3(0.0f, 0.0f, gVal/10.0f));
// Transformation // Transformation
float rotang = time; float rotang = time;

@ -91,7 +91,8 @@ namespace Renderer {
preRenderHook(); preRenderHook();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glDrawElements(GL_TRIANGLES, indicesVec.size(), GL_UNSIGNED_INT, 0); // glDrawElements(GL_TRIANGLES, indicesVec.size(), GL_UNSIGNED_INT, 0);
glDrawArrays(GL_TRIANGLES, 0, indicesVec.size());
} }
void RenderObject::transform(glm::mat4 T) { void RenderObject::transform(glm::mat4 T) {
@ -106,6 +107,7 @@ namespace Renderer {
void Obj2D::preRenderHook() { void Obj2D::preRenderHook() {
printf("OBJ2D was here!\n"); printf("OBJ2D was here!\n");
printf("Now has texture: %s", texture.texture_src);
if (texture.loaded) if (texture.loaded)
texture.bind(); texture.bind();
} }

@ -19,7 +19,7 @@ namespace Textures {
void Texture2D::load() { void Texture2D::load() {
// Bind this texture // Bind this texture
glGenTextures(1, &id); glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id); bind();
// Repeat/bounded etc // Repeat/bounded etc
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);

Loading…
Cancel
Save