summaryrefslogtreecommitdiffhomepage
path: root/src/texture.cpp
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2022-11-24 21:44:59 -0500
committerrealtradam <[email protected]>2022-11-24 21:44:59 -0500
commitf2a9e986afe980c6b32f7f40d1fe2b0294d86d90 (patch)
tree252b7e7a2a8fa5ff71b1b7953ec9af2492a2ea2d /src/texture.cpp
parentf0f30c12fe919862ade380513c02c9845598ac46 (diff)
downloadOgle-f2a9e986afe980c6b32f7f40d1fe2b0294d86d90.tar.gz
Ogle-f2a9e986afe980c6b32f7f40d1fe2b0294d86d90.zip
implemented proper batch rendering of quads and textures
Diffstat (limited to 'src/texture.cpp')
-rw-r--r--src/texture.cpp28
1 files changed, 4 insertions, 24 deletions
diff --git a/src/texture.cpp b/src/texture.cpp
index 4432f4c..e9a49ce 100644
--- a/src/texture.cpp
+++ b/src/texture.cpp
@@ -5,11 +5,8 @@
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
-
-Texture::Texture(const char* texturePath, unsigned int VAO, unsigned int VBO)
+Texture::Texture(const char* texture_path)
{
- this->VAO = VAO;
- this->VBO = VBO;
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
// set the texture wrapping/filtering options (on the currently bound texture object)
@@ -17,12 +14,12 @@ Texture::Texture(const char* texturePath, unsigned int VAO, unsigned int VBO)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- // load and generate the texture
int width, height, nrChannels;
- unsigned char *data = stbi_load(texturePath, &width, &height, &nrChannels, 0);
+ stbi_set_flip_vertically_on_load(true);
+ unsigned char *data = stbi_load(texture_path, &width, &height, &nrChannels, 0);
if (data)
{
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
}
else
@@ -31,20 +28,3 @@ Texture::Texture(const char* texturePath, unsigned int VAO, unsigned int VBO)
}
stbi_image_free(data);
}
-
-void Texture::draw(float x, float y, float width, float height)
-{
- float vertices[] = {
- // positions // colors // texture coords
- x-width, y+height, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, // top right
- x-width, y, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // bottom right
- x, y, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom left
- x, y+height, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f // top left
- };
- glBindBuffer(GL_ARRAY_BUFFER, VBO); // bind(activate) the buffer to the ARRAY_BUFFER
- glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_DYNAMIC_DRAW); // upload the data
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, id);
- glBindVertexArray(VAO);
- glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
-}