From 3d666aa3a1b2e71eb315454b59a66cb5968f5aed Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 19 Oct 2019 23:18:09 +0300 Subject: [PATCH] supported .png files flipped quad coordinates --- quad.cpp | 12 ++++++------ tags | 2 +- text.h | 2 +- texture.cpp | 7 ++++++- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/quad.cpp b/quad.cpp index 27e86f6..d5503f7 100755 --- a/quad.cpp +++ b/quad.cpp @@ -36,22 +36,22 @@ namespace vb01{ v6.pos=Vector3(size.x,0,0); } v1.norm=Vector3(0,0,-1); - v1.texCoords=Vector2(1,1); + v1.texCoords=Vector2(1,0); v2.norm=Vector3(0,0,-1); - v2.texCoords=Vector2(0,1); + v2.texCoords=Vector2(0,0); v3.norm=Vector3(0,0,-1); - v3.texCoords=Vector2(0,0); + v3.texCoords=Vector2(0,1); v4.norm=Vector3(0,0,-1); - v4.texCoords=Vector2(0,0); + v4.texCoords=Vector2(0,1); v5.norm=Vector3(0,0,-1); - v5.texCoords=Vector2(1,0); + v5.texCoords=Vector2(1,1); v6.norm=Vector3(0,0,-1); - v6.texCoords=Vector2(1,1); + v6.texCoords=Vector2(1,0); indices[0]=0; indices[1]=1; diff --git a/tags b/tags index 2ab98b3..c57b95e 100755 --- a/tags +++ b/tags @@ -242,7 +242,7 @@ buflen stb_image.h /^ int buflen;$/;" m struct:__anon84e4e8860308 typeref:type camera root.h /^ Camera *camera;$/;" m class:vb01::Root typeref:typename:Camera * castShadow mesh.h /^ bool staticVerts=true,castShadow=false;$/;" m class:vb01::Mesh typeref:typename:bool castShadow model.h /^ bool castShadow=false;$/;" m class:vb01::Model typeref:typename:bool -ch text.h /^ int ch;$/;" m struct:vb01::Text::Glyph typeref:typename:int +ch text.h /^ u32 ch;$/;" m struct:vb01::Text::Glyph typeref:typename:u32 channel stb_image.h /^ stbi_uc size,type,channel;$/;" m struct:__anon84e4e8861108 typeref:typename:stbi_uc channel_order stb_image.h /^ int channel_order;$/;" m struct:__anon84e4e8860508 typeref:typename:int characters text.h /^ std::vector characters;$/;" m class:vb01::Text typeref:typename:std::vector diff --git a/text.h b/text.h index 09af47f..54c6999 100755 --- a/text.h +++ b/text.h @@ -14,7 +14,7 @@ namespace vb01{ class Text{ public: struct Glyph{ - int ch; + u32 ch; Texture *texture=nullptr; unsigned int advance; Vector2 size,bearing; diff --git a/texture.cpp b/texture.cpp index 0cfafba..b2ec074 100755 --- a/texture.cpp +++ b/texture.cpp @@ -59,6 +59,11 @@ namespace vb01{ } Texture::Texture(string path){ + bool png=false; + int length=path.length(); + if(path.substr(length-4,string::npos)==".png") + png=true; + glGenTextures(1,&texture); glBindTexture(GL_TEXTURE_2D,texture); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); @@ -70,7 +75,7 @@ namespace vb01{ data=stbi_load(path.c_str(),&width,&height,&numChannels,0); - glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,width,height,0,GL_RGB,GL_UNSIGNED_BYTE,data); + glTexImage2D(GL_TEXTURE_2D,0,png?GL_RGBA:GL_RGB,width,height,0,png?GL_RGBA:GL_RGB,GL_UNSIGNED_BYTE,data); //glGenerateMipmap(GL_TEXTURE_2D); stbi_image_free(data); }