mirror of
https://github.com/devZoGok/vb01.git
synced 2026-08-26 19:43:30 +00:00
animated textures
This commit is contained in:
+3
-3
@@ -50,11 +50,11 @@ namespace vb01{
|
||||
}
|
||||
if(texturingEnabled){
|
||||
for(Texture *t : diffuseMapTextures)
|
||||
t->select();
|
||||
t->update();
|
||||
for(Texture *t : normalMapTextures)
|
||||
t->select();
|
||||
t->update();
|
||||
for(Texture *t : specularMapTextures)
|
||||
t->select();
|
||||
t->update();
|
||||
}
|
||||
else {
|
||||
shader->setVec4(diffuseColor,"diffuseColor");
|
||||
|
||||
+15
-3
@@ -14,13 +14,25 @@ namespace vb01{
|
||||
Material(Type=MATERIAL_2D);
|
||||
~Material();
|
||||
void update();
|
||||
inline void addDiffuseMap(std::string diffuseMap){diffuseMapTextures.push_back(new Texture(diffuseMap));}
|
||||
inline void addDiffuseMap(std::string diffuseMap){
|
||||
std::string p[]{diffuseMap};
|
||||
diffuseMapTextures.push_back(new Texture(p,1));
|
||||
}
|
||||
inline void addDiffuseMap(std::string diffuseMap[],int numFrames){diffuseMapTextures.push_back(new Texture(diffuseMap,numFrames));}
|
||||
inline void addDiffuseMap(std::string diffuseMap[6]){diffuseMapTextures.push_back(new Texture(diffuseMap));}
|
||||
inline void addDiffuseMap(Texture *texture){diffuseMapTextures.push_back(texture);}
|
||||
inline void setDiffuseMap(Texture *texture, int i){diffuseMapTextures[i]=texture;}
|
||||
inline void addNormalMap(std::string normalMap){normalMapTextures.push_back(new Texture(normalMap));}
|
||||
inline void addNormalMap(std::string normalMap){
|
||||
std::string p[]{normalMap};
|
||||
normalMapTextures.push_back(new Texture(p,1));
|
||||
}
|
||||
inline void addNormalMap(std::string normalMap[],int numFrames){normalMapTextures.push_back(new Texture(normalMap,numFrames));}
|
||||
inline void setNormalMap(Texture *texture, int i){normalMapTextures[i]=texture;}
|
||||
inline void addSpecularMap(std::string specularMap){specularMapTextures.push_back(new Texture(specularMap));}
|
||||
inline void addSpecularMap(std::string specularMap){
|
||||
std::string p[]{specularMap};
|
||||
specularMapTextures.push_back(new Texture(p,1));
|
||||
}
|
||||
inline void addSpecularMap(std::string specularMap[],int numFrames){specularMapTextures.push_back(new Texture(specularMap,numFrames));}
|
||||
inline void setSpecularMap(Texture *texture, int i){specularMapTextures[i]=texture;}
|
||||
inline void setDiffuseColor(Vector4 diffuse){this->diffuseColor=diffuse;}
|
||||
inline void setSpecularColor(Vector4 specular){this->specularColor=specular;}
|
||||
|
||||
+61
-28
@@ -11,9 +11,10 @@ namespace vb01{
|
||||
Texture::Texture(int width, int height, bool shadowMap){
|
||||
this->width=width;
|
||||
this->height=height;
|
||||
texture=new u32;
|
||||
|
||||
glGenTextures(1,&texture);
|
||||
glBindTexture(GL_TEXTURE_2D,texture);
|
||||
glGenTextures(1,&texture[0]);
|
||||
glBindTexture(GL_TEXTURE_2D,texture[0]);
|
||||
if(shadowMap){
|
||||
glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT,width,height,0,GL_DEPTH_COMPONENT,GL_FLOAT,NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
@@ -32,35 +33,44 @@ namespace vb01{
|
||||
}
|
||||
}
|
||||
|
||||
Texture::Texture(string path,bool flip){
|
||||
bool png=false;
|
||||
int length=path.length();
|
||||
if(path.substr(length-4,string::npos)==".png")
|
||||
png=true;
|
||||
Texture::Texture(string path[],int numPaths,int updateRate,bool flip){
|
||||
this->numFrames=numPaths;
|
||||
this->updateRate=updateRate;
|
||||
|
||||
glGenTextures(1,&texture);
|
||||
glBindTexture(GL_TEXTURE_2D,texture);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
|
||||
texture=new u32[numPaths];
|
||||
|
||||
stbi_set_flip_vertically_on_load(flip);
|
||||
for(int i=0;i<numPaths;i++){
|
||||
bool png=false;
|
||||
int length=path[i].length();
|
||||
|
||||
data=stbi_load(path.c_str(),&width,&height,&numChannels,0);
|
||||
if(path[i].substr(length-4,string::npos)==".png")
|
||||
png=true;
|
||||
|
||||
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);
|
||||
glGenTextures(1,&texture[i]);
|
||||
glBindTexture(GL_TEXTURE_2D,texture[i]);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
|
||||
|
||||
stbi_set_flip_vertically_on_load(flip);
|
||||
|
||||
data=stbi_load(path[i].c_str(),&width,&height,&numChannels,0);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Texture::Texture(string paths[6],bool flip){
|
||||
this->type=TextureType::TEXTURE_CUBEMAP;
|
||||
texture=new u32;
|
||||
|
||||
glGenTextures(1,&texture);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP,texture);
|
||||
glGenTextures(1,&texture[0]);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP,texture[0]);
|
||||
|
||||
stbi_set_flip_vertically_on_load(flip);
|
||||
|
||||
@@ -86,9 +96,10 @@ namespace vb01{
|
||||
Texture::Texture(int width){
|
||||
this->width=width;
|
||||
this->type=TextureType::TEXTURE_CUBEMAP;
|
||||
texture=new u32;
|
||||
|
||||
glGenTextures(1,&texture);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP,texture);
|
||||
glGenTextures(1,&texture[0]);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP,texture[0]);
|
||||
|
||||
for(int i=0;i<6;i++)
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+i,0,GL_DEPTH_COMPONENT,width,width,0,GL_DEPTH_COMPONENT,GL_FLOAT,NULL);
|
||||
@@ -102,8 +113,10 @@ namespace vb01{
|
||||
}
|
||||
|
||||
Texture::Texture(FT_Face &face, char ch){
|
||||
glGenTextures(1,&texture);
|
||||
glBindTexture(GL_TEXTURE_2D,texture);
|
||||
texture=new u32;
|
||||
|
||||
glGenTextures(1,&texture[0]);
|
||||
glBindTexture(GL_TEXTURE_2D,texture[0]);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0,
|
||||
@@ -124,11 +137,31 @@ namespace vb01{
|
||||
|
||||
Texture::~Texture(){
|
||||
glBindTexture(type==TEXTURE_2D?GL_TEXTURE_2D:GL_TEXTURE_CUBE_MAP,0);
|
||||
glDeleteTextures(1,&texture);
|
||||
if(numFrames>0){
|
||||
for(int i=0;i<numFrames;i++)
|
||||
glDeleteTextures(1,&texture[i]);
|
||||
delete[] texture;
|
||||
}
|
||||
else{
|
||||
glDeleteTextures(1,&texture[0]);
|
||||
delete texture;
|
||||
}
|
||||
}
|
||||
|
||||
void Texture::select(int id){
|
||||
glActiveTexture(GL_TEXTURE0+id);
|
||||
glBindTexture(type==TEXTURE_2D?GL_TEXTURE_2D:GL_TEXTURE_CUBE_MAP,texture);
|
||||
glBindTexture(type==TEXTURE_2D?GL_TEXTURE_2D:GL_TEXTURE_CUBE_MAP,texture[numFrames>0?frame:0]);
|
||||
}
|
||||
|
||||
void Texture::update(){
|
||||
if(numFrames>0){
|
||||
if(getTime()-lastUpdateTime>updateRate){
|
||||
frame++;
|
||||
if(frame==numFrames)
|
||||
frame=0;
|
||||
lastUpdateTime=getTime();
|
||||
}
|
||||
}
|
||||
select();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,16 +13,18 @@ namespace vb01{
|
||||
|
||||
~Texture();
|
||||
Texture(int,int,bool=true);
|
||||
Texture(std::string,bool=false);
|
||||
Texture(std::string[],int,int=0,bool=false);
|
||||
Texture(std::string[6],bool=false);
|
||||
Texture(int);
|
||||
Texture(FT_Face&,char);
|
||||
void select(int=0);
|
||||
inline unsigned int* getTexture(){return &texture;}
|
||||
void update();
|
||||
inline unsigned int* getTexture(int i=0){return &(texture[i]);}
|
||||
inline std::string getPath(){return path;}
|
||||
private:
|
||||
TextureType type=TextureType::TEXTURE_2D;
|
||||
u32 texture;
|
||||
u32 *texture=nullptr;
|
||||
s32 updateRate=0,numFrames=0,frame=0;
|
||||
s64 lastUpdateTime=0;
|
||||
int width,height,numChannels;
|
||||
float weight;
|
||||
|
||||
Reference in New Issue
Block a user