From f2a9e986afe980c6b32f7f40d1fe2b0294d86d90 Mon Sep 17 00:00:00 2001 From: realtradam Date: Thu, 24 Nov 2022 21:44:59 -0500 Subject: implemented proper batch rendering of quads and textures --- src/texture.cpp | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) (limited to 'src/texture.cpp') 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); -} -- cgit v1.2.3