diff --git a/.vscode/settings.json b/.vscode/settings.json index 0ad8168..fb693c0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -96,6 +96,7 @@ }, "C_Cpp.errorSquiggles": "Disabled", "cSpell.words": [ + "awesomeface", "kuchy", "multiplatform", "VERTICE" diff --git a/Engine/engine/assets/awesomeface.png b/Engine/engine/assets/awesomeface.png new file mode 100644 index 0000000..23c778d Binary files /dev/null and b/Engine/engine/assets/awesomeface.png differ diff --git a/Engine/engine/assets/container.png b/Engine/engine/assets/container.png new file mode 100644 index 0000000..bc1452a Binary files /dev/null and b/Engine/engine/assets/container.png differ diff --git a/Engine/engine/draw.cpp b/Engine/engine/draw.cpp index 1164bb1..d82d9fe 100644 --- a/Engine/engine/draw.cpp +++ b/Engine/engine/draw.cpp @@ -179,11 +179,20 @@ drawFigureReturn drawDebilMode(const char* vertexPath, const char* fragmentPath, configureVertexAttribute(true, true); - loadAndCreateTexture(); + unsigned int texture1 = loadAndCreateTexture("assets/Preview.png", GL_RGBA, true); + // unsigned int texture2 = loadAndCreateTexture("assets/awesomeface.png", GL_RGBA, false); + + + activateAndBindTextures(texture1, GL_TEXTURE0); + // activateAndBindTextures(texture2, GL_TEXTURE1); + ourShader.use(); // don't forget to activate/use the shader before setting uniforms! - // set it via the texture class - ourShader.setInt("texture1", 1); + // either set it manually like so: + glUniform1i(glGetUniformLocation(ourShader.ID, "texture1"), 0); + // or set it via the texture class + ourShader.setInt("texture2", 1); + glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); drawFigureReturn newReturn; @@ -227,8 +236,6 @@ void doDrawArrays(const unsigned int shaderProgram, const unsigned int vertexArr // use shader program to render an object glUseProgram(shaderProgram); updateUniformColor(shaderProgram, "ourColor"); - const unsigned int texture = generateTexture("./assets/Preview.png"); - glBindTexture(GL_TEXTURE_2D, texture); glBindVertexArray(vertexArrayObject); // From left: // primitive type we want to draw diff --git a/Engine/engine/match b/Engine/engine/match index 8f59bfa..7374b38 100755 Binary files a/Engine/engine/match and b/Engine/engine/match differ diff --git a/Engine/engine/textures.cpp b/Engine/engine/textures.cpp index 431d588..8f4f014 100644 --- a/Engine/engine/textures.cpp +++ b/Engine/engine/textures.cpp @@ -91,10 +91,12 @@ unsigned int generateAndBindTexture(const GLenum textureTarget, const GLsizei nu return texture; } -unsigned int loadAndBindTextureFile(unsigned int texture, const char* texturePath) { +unsigned int loadAndBindTextureFile(unsigned int texture, const char* texturePath, GLenum rgbFormat, bool flipImage) { int textureWidth, textureHeight, colorChannels; - unsigned char *data = stbi_load("assets/container.jpg", &textureWidth, &textureHeight, &colorChannels, 0); + stbi_set_flip_vertically_on_load(flipImage); + unsigned char *data = stbi_load(texturePath, &textureWidth, &textureHeight, &colorChannels, 0); if(data) { + std::cout << "textureWidth " << textureWidth << " textureHeight " << textureHeight << " colorChannels " << colorChannels << std::endl; // generate texture /* first argument is texture target, setting it to GL_TEXTURE_2D will only affect 2D targets and not 1D or 3D @@ -105,7 +107,7 @@ unsigned int loadAndBindTextureFile(unsigned int texture, const char* texturePat 7th and 8th are the format and datatype of source image, we store the image data as chars (bytes) so we pass that 9th last argument is actual data of the texture */ - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, textureWidth, textureHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, data); + glTexImage2D(GL_TEXTURE_2D, 0, rgbFormat, textureWidth, textureHeight, 0, rgbFormat, GL_UNSIGNED_BYTE, data); glGenerateMipmap(GL_TEXTURE_2D); // after generating texture, lets free the memory from image stbi_image_free(data); @@ -118,13 +120,8 @@ unsigned int loadAndBindTextureFile(unsigned int texture, const char* texturePat } } -unsigned int generateTexture(const char* texturePath) { - unsigned int texture = generateAndBindTexture(GL_TEXTURE_2D, 1); - texture = loadAndBindTextureFile(texture, texturePath); -} - // const char* texturePath, int textureWidth, int textureHeight, int colorChannels, const GLenum textureTarget, const GLint sCoordinateOption, const GLint tCoordinateOption, const GLint rCoordinateOption, const float* borderColor -unsigned int loadAndCreateTexture() { +unsigned int loadAndCreateTexture(const char* texturePath, GLenum RGBFormat, bool flipImage) { // load and create a texture // ------------------------- unsigned int texture = generateAndBindTexture(GL_TEXTURE_2D, 1); @@ -134,9 +131,13 @@ unsigned int loadAndCreateTexture() { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // load image, create texture and generate mipmaps - texture = loadAndBindTextureFile(texture, "assets/Preview.png"); + texture = loadAndBindTextureFile(texture, texturePath, RGBFormat, flipImage); + return texture; +} - glActiveTexture(GL_TEXTURE0); +void activateAndBindTextures(unsigned int texture, GLenum textureNumber) +{ + glActiveTexture(textureNumber); glBindTexture(GL_TEXTURE_2D, texture); } diff --git a/Engine/engine/textures.hpp b/Engine/engine/textures.hpp index 70d449f..0ba723c 100644 --- a/Engine/engine/textures.hpp +++ b/Engine/engine/textures.hpp @@ -10,10 +10,11 @@ void setTextureTCoordinate(const GLenum textureTarget = GL_TEXTURE_2D, const GLi void setTextureRCoordinate(const GLenum textureTarget = GL_TEXTURE_3D, const GLint rCoordinateOption = GL_REPEAT, const float* borderColor = NULL); void setTextureFilteringAndMipMap(const GLenum textureTarget = GL_TEXTURE_2D, const GLenum filterType = GL_TEXTURE_MAG_FILTER, const GLint textureFilteringMethod = GL_NEAREST, const GLint mipMapFilteringMethod = GL_NEAREST_MIPMAP_NEAREST); unsigned int generateAndBindTexture(const GLenum textureTarget); -unsigned int generateTexture(const char* texturePath); unsigned char* loadTexture(const char* texturePath, int textureWidth, int textureHeight, int colorChannels); // const char* texturePath, int textureWidth, int textureHeight, int colorChannels, const GLenum textureTarget, const GLint sCoordinateOption, const GLint tCoordinateOption, const GLint rCoordinateOption, const float* borderColor -unsigned int loadAndCreateTexture(); +unsigned int loadAndCreateTexture(const char* texturePath, GLenum RGBFormat, bool flipImage); +void activateAndBindTextures(unsigned int texture, GLenum textureNumber); +unsigned int loadAndBindTextureFile(unsigned int texture, const char* texturePath, GLenum rgbFormat, bool flipImage); #endif // TEXTURES_HPP \ No newline at end of file