mostly implemented skybox and fixed box verts

This commit is contained in:
devZoGok
2021-10-18 19:04:20 +03:00
parent fd09cbf762
commit 03f65e62f5
22 changed files with 227 additions and 106 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ link_directories(/usr/lib/)
set(CMAKE_BUILD_TYPE Debug)
set(math quaternion.cpp vector.cpp)
set(render camera.cpp light.cpp material.cpp mesh.cpp model.cpp node.cpp quad.cpp root.cpp shader.cpp texture.cpp)
set(render camera.cpp light.cpp material.cpp mesh.cpp model.cpp node.cpp quad.cpp box.cpp root.cpp shader.cpp texture.cpp)
add_executable(vb01 main.cpp ${render} ${math})
target_link_libraries(vb01 glfw)
+51 -61
View File
@@ -1,73 +1,63 @@
#include"box.h"
namespace vb01{
Box::Box(){
float size=.1;
float vertData[]={
0,1,0,1,1,
0,1,0,0,1,
0,1,0,0,0,
0,1,0,0,0,
0,1,0,1,0,
0,1,0,1,1,
0,-1,0,1,1,
0,-1,0,0,1,
0,-1,0,0,0,
0,-1,0,0,0,
0,-1,0,1,0,
0,-1,0,1,1,
0,0,1,1,1,
0,0,1,0,1,
0,0,1,0,0,
0,0,1,0,0,
0,0,1,1,0,
0,0,1,1,1,
0,0,-1,1,1,
0,0,-1,0,1,
0,0,-1,0,0,
0,0,-1,0,0,
0,0,-1,1,0,
0,0,-1,1,1,
1,0,0,1,1,
1,0,0,0,1,
1,0,0,0,0,
1,0,0,0,0,
1,0,0,1,0,
1,0,0,1,1,
-1,0,0,1,1,
-1,0,0,0,1,
-1,0,0,0,0,
-1,0,0,0,0,
-1,0,0,1,0,
-1,0,0,1,1
};
Vector3 p[]={
Vector3(size.x/2,size.y/2,size.z/2),
Vector3(-size.x/2,size.y/2,size.z/2),
Vector3(-size.x/2,size.y/2,-size.z/2),
Box::Box(Vector3 size){
Vector3 pos[]={
Vector3(size.x/2,size.y/2,size.z/2),
Vector3(-size.x/2,size.y/2,size.z/2),
Vector3(-size.x/2,size.y/2,-size.z/2),
Vector3(size.x/2,size.y/2,-size.z/2),
Vector3(size.x/2,-size.y/2,size.z/2),
Vector3(-size.x/2,-size.y/2,size.z/2),
Vector3(-size.x/2,-size.y/2,-size.z/2),
Vector3(-size.x/2,-size.y/2,-size.z/2)
Vector3(size.x/2,-size.y/2,-size.z/2)
};
int indices[]={
Vector3 norm[]={
Vector3(0,0,1),
Vector3(0,1,0),
Vector3(1,0,0),
Vector3(0,0,-1),
Vector3(0,-1,0),
Vector3(-1,0,0)
};
}
void Box::update(){
Vector2 tex[]={
Vector2(1,1),
Vector2(0,1),
Vector2(0,0),
Vector2(1,0)
};
unsigned int data[]={
0,3,1, 4,3,0, 1,3,2,
5,3,3, 1,3,2, 4,3,0,
2,0,1, 6,0,0, 3,0,2,
6,0,2, 7,0,0, 3,0,3,
3,2,0, 7,2,1, 4,2,2,
4,2,2, 0,2,3, 3,2,0,
1,5,0, 5,5,1, 6,5,2,
6,5,2, 2,5,3, 1,5,0,
0,1,0, 1,1,1, 2,1,2,
2,1,2, 3,1,3, 0,1,0,
4,4,3, 6,4,1, 5,4,2,
6,4,1, 4,4,3, 7,4,0
};
numTris=12;
indices=new unsigned int[3*numTris];
vertices=new Vertex[3*numTris];
for(int i=0;i<3*numTris;i++){
Vertex v;
v.pos=pos[data[3*i]];
v.norm=norm[data[3*i+1]];
v.texCoords=tex[data[3*i+2]];
vertices[i]=v;
indices[i]=i;
}
construct();
}
}
+1 -3
View File
@@ -6,9 +6,7 @@
namespace vb01{
class Box : public Mesh{
public:
Box();
void update();
private:
Box(Vector3);
};
}
+22 -7
View File
@@ -1,7 +1,10 @@
#include<cmath>
#include<iostream>
#include<string>
#include"root.h"
#include"node.h"
#include"quad.h"
#include"box.h"
#include"material.h"
#include"model.h"
#include"light.h"
@@ -14,20 +17,31 @@ int main(){
Root *root=Root::getSingleton();
root->start(800,600);
Vector3 v1[]={Vector3(.2,.2,.2),Vector3(.5,.5,.5)};
Vector3 v2[]={Vector3(-.5,0,-2),Vector3(.0,0,0)};
Vector3 v1[]={Vector3(.2,.2,.2),Vector3(1,1,1)};
Vector3 v2[]={Vector3(0,0,0),Vector3(.0,0,0)};
//Quad *q=new Quad(v1[1]);
Model *n=new Model("/home/dominykas/c++/FSim/jet00.obj");
string t[]={
"/home/dominykas/c++/FSim/left.jpg",
"/home/dominykas/c++/FSim/right.jpg",
"/home/dominykas/c++/FSim/top.jpg",
"/home/dominykas/c++/FSim/bottom.jpg",
"/home/dominykas/c++/FSim/front.jpg",
"/home/dominykas/c++/FSim/back.jpg"
};
root->createSkybox(t);
Box *b=new Box(Vector3(1,1,1));
Node *n=new Node(v2[0]);
Material *mat=new Material();
mat->addDiffuseMap("/home/dominykas/c++/FSim/defaultTexture.jpg");
mat->setLightingEnabled(false);
n->setMaterial(mat);
//n->attachMesh(q);
b->setMaterial(mat);
n->attachMesh(b);
root->getRootNode()->attachChild(n);
Camera *cam=Root::getSingleton()->getCamera();
cam->setPosition(Vector3(0,0,-5));
cam->lookAt(Vector3(1,0,1).norm(),Vector3(0,1,0));
Light *l1=new Light();
l1->setPosition(Vector3(-.5,.1,0));
l1->setColor(Vector3(0,1,0));
@@ -37,7 +51,8 @@ int main(){
l1->setOuterAngle(glm::radians(60.));
l1->setType(Light::POINT);
//root->getRootNode()->addLight(l1);
while(true)
while(true){
root->update();
}
return 0;
}
+13 -3
View File
@@ -4,9 +4,19 @@
using namespace std;
namespace vb01{
Material::Material(){
string basePath="/home/dominykas/c++/FSim/";
shader=new Shader(basePath+"texture.vert",basePath+"texture.frag");
Material::Material(Type type){
this->type=type;
string basePath="/home/dominykas/c++/FSim/",shaderName;
switch(type){
case MATERIAL_2D:
shaderName="texture.";
break;
case MATERIAL_SKYBOX:
shaderName="skybox.";
break;
}
shader=new Shader(basePath+shaderName+"vert",basePath+shaderName+"frag");
}
Material::~Material(){}
+5 -3
View File
@@ -6,20 +6,22 @@
#include<vector>
namespace vb01{
class Texture;
class Material{
public:
Material();
enum Type{MATERIAL_2D,MATERIAL_SKYBOX};
Material(Type=MATERIAL_2D);
~Material();
void update();
void addDiffuseMap(std::string diffuseMap){diffuseMapTextures.push_back(new Texture(diffuseMap));}
void addDiffuseMap(std::string diffuseMap[6]){diffuseMapTextures.push_back(new Texture(diffuseMap));}
void addNormalMap(std::string normalMap){normalMapTextures.push_back(new Texture(normalMap));}
void addSpecularMap(std::string specularMap){specularMapTextures.push_back(new Texture(specularMap));}
inline void setLightingEnabled(bool lighting){this->lightingEnabled=lighting;}
inline Shader* getShader(){return shader;}
inline bool isLightingEnabled(){return lightingEnabled;}
private:
Type type;
bool lightingEnabled=false;
std::vector<Texture*> diffuseMapTextures,normalMapTextures,specularMapTextures;
Shader *shader=nullptr;
+2 -2
View File
@@ -49,11 +49,11 @@ namespace vb01{
Camera *cam=root->getCamera();
float fov=cam->getFov(),width=root->getWidth(),height=root->getHeight();
float nearPlane=cam->getNearPlane(),farPlane=cam->getFarPlane();
Vector3 pos=node->getPosition();
Vector3 pos=(node?node->getPosition():Vector3::VEC_ZERO);
Vector3 dir=cam->getDirection(),up=cam->getUp(),camPos=cam->getPosition();
mat4 model=translate(mat4(1.),vec3(pos.x,pos.y,pos.z));
model=rotate(model,13.f,vec3(0,1,0));
model=rotate(model,radians(0.f),vec3(0,1,0));
mat4 view=lookAt(vec3(camPos.x,camPos.y,camPos.z),vec3(camPos.x+dir.x,camPos.y+dir.y,camPos.z+dir.z),vec3(up.x,up.y,up.z));
mat4 proj=perspective(radians(fov),width/height,nearPlane,farPlane);
//proj=ortho(0.f,800.f,0.f,-600.f,nearPlane,farPlane);
+1 -1
View File
@@ -16,7 +16,6 @@ namespace vb01{
Vector3 pos,norm;
Vector2 texCoords;
};
Mesh();
Mesh(Vertex*,unsigned int*,int);
~Mesh();
virtual void update();
@@ -31,6 +30,7 @@ namespace vb01{
std::vector<Mesh*> meshes;
std::string name="";
protected:
Mesh();
void construct();
Vertex *vertices;
unsigned int *indices,VAO,VBO,EBO;
+2 -1
View File
@@ -51,7 +51,8 @@ namespace vb01{
vector<Mesh*> meshes=n->getMeshes();
for(Mesh *m : meshes){
Material *mat=m->getMaterial();
if(mat) mat->getShader()->setNumLights(numLights>0?numLights:1);
string str=to_string(numLights>0?numLights:1);
if(mat) mat->getShader()->editShader(false,'=',';',str);
}
}
}
+3 -2
View File
@@ -27,8 +27,9 @@ namespace vb01{
v6.norm=Vector3(0,0,-1);
v6.texCoords=Vector2(1,1);
int numPolyVerts=3;
numTris=2;
indices=new unsigned int[numTris*3];
indices=new unsigned int[numTris*numPolyVerts];
indices[0]=0;
indices[1]=1;
indices[2]=2;
@@ -36,7 +37,7 @@ namespace vb01{
indices[4]=4;
indices[5]=5;
vertices=new Vertex[numTris*3];
vertices=new Vertex[numTris*numPolyVerts];
vertices[0]=v1;
vertices[1]=v2;
vertices[2]=v3;
+17 -1
View File
@@ -1,8 +1,13 @@
#include"stb_image.h"
#include"root.h"
#include<glad.h>
#include<glfw3.h>
#include<cstdlib>
#include<iostream>
#include"shader.h"
#include"box.h"
using namespace std;
namespace vb01{
static Root *root=new Root();
@@ -41,7 +46,6 @@ namespace vb01{
glEnable(GL_DEPTH_TEST);
glEnable(GL_STENCIL_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
}
void Root::update(){
@@ -49,9 +53,21 @@ namespace vb01{
glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glDepthMask(GL_FALSE);
glCullFace(GL_BACK);
skybox->update();
glDepthMask(GL_TRUE);
glCullFace(GL_FRONT);
rootNode->update();
glfwSwapBuffers(window);
}
}
void Root::createSkybox(string textures[6]){
skybox = new Box(Vector3(10,10,10));
Material *skyboxMat=new Material(Material::Type::MATERIAL_SKYBOX);
skyboxMat->addDiffuseMap(textures);
skybox->setMaterial(skyboxMat);
}
}
+5
View File
@@ -3,6 +3,7 @@
#include"node.h"
#include"camera.h"
#include<string>
class GLFWwindow;
@@ -10,6 +11,8 @@ namespace vb01{
void foo();
class Mesh;
class Box;
class Shader;
class Root{
public:
@@ -20,8 +23,10 @@ namespace vb01{
inline Node* getRootNode(){return rootNode;}
inline int getWidth(){return width;}
inline int getHeight(){return height;}
void createSkybox(std::string[6]);
static Root* getSingleton();
private:
Box *skybox=nullptr;
bool running=false;
int width,height;
GLFWwindow *window;
+12 -5
View File
@@ -25,19 +25,26 @@ namespace vb01{
vString=vertShaderStream.str();
fString=fragShaderStream.str();
setNumLights(1);
loadShaders();
}
void Shader::setNumLights(int numLights){
void Shader::editShader(bool vertexShader, char firstChar, char secondChar, string insertion){
int firstCharId=-1,secondCharId=-1;
for(int i=0;i<fString.length()&&(firstCharId==-1||secondCharId==-1);i++){
if(fString.c_str()[i]=='=')
if(fString.c_str()[i]==firstChar)
firstCharId=i;
if(fString.c_str()[i]==';')
if(fString.c_str()[i]==secondChar)
secondCharId=i;
}
fString=fString.substr(0,firstCharId+1)+to_string(numLights)+fString.substr(secondCharId,string::npos);
string *shaderString=(vertexShader?&vString:&fString);
(*shaderString)=(*shaderString).substr(0,firstCharId+1)+insertion+(*shaderString).substr(secondCharId,string::npos);
loadShaders();
}
void Shader::loadShaders(){
const char *vertShaderSource=vString.c_str();
const char *fragShaderSource=fString.c_str();
+4 -1
View File
@@ -7,6 +7,8 @@
namespace vb01{
class Shader{
public:
enum ErrorType{VERTEX,FRAGMENT,PROGRAM};
Shader(std::string,std::string);
void setNumLights(int);
void use();
@@ -15,8 +17,9 @@ namespace vb01{
void setFloat(float,std::string);
void setBool(bool,std::string);
void setInt(int,std::string);
void editShader(bool,char,char,std::string);
private:
enum ErrorType{VERTEX,FRAGMENT,PROGRAM};
void loadShaders();
void checkCompileErrors(unsigned int,ErrorType);
unsigned int id;
std::string vString,fString;
+11
View File
@@ -0,0 +1,11 @@
#version 330 core
in vec3 texCoords;
out vec4 FragColor;
uniform samplerCube skybox;
void main(){
FragColor=texture(skybox,texCoords);
}
+13
View File
@@ -0,0 +1,13 @@
#version 330 core
layout (location=0) in vec3 aPos;
out vec3 texCoords;
uniform mat4 proj;
uniform mat4 view;
void main(){
texCoords=aPos;
gl_Position=proj*view*vec4(aPos,1);
}
+27 -11
View File
@@ -7,7 +7,7 @@
!_TAG_PROGRAM_VERSION 0.0.0 /3fdf28bc/
AMBIENT light.h /^ enum Type{POINT,DIRECTIONAL,SPOT,AMBIENT};$/;" e enum:vb01::Light::Type
BOX_H box.h /^#define BOX_H$/;" d
Box box.cpp /^ Box::Box(){$/;" f class:vb01::Box
Box box.cpp /^ Box::Box(Vector3 size){$/;" f class:vb01::Box
Box box.h /^ class Box : public Mesh{$/;" c namespace:vb01
CAMERA_H camera.h /^#define CAMERA_H$/;" d
Camera camera.cpp /^ Camera::Camera(){$/;" f class:vb01::Camera
@@ -20,10 +20,12 @@ FRAGMENT shader.h /^ enum ErrorType{VERTEX,FRAGMENT,PROGRAM};$/;" e enum:vb01:
LIGHT_H light.h /^#define LIGHT_H$/;" d
Light light.cpp /^ Light::Light(){$/;" f class:vb01::Light
Light light.h /^ class Light{$/;" c namespace:vb01
MATERIAL_2D material.h /^ enum Type{MATERIAL_2D,MATERIAL_SKYBOX};$/;" e enum:vb01::Material::Type
MATERIAL_H material.h /^#define MATERIAL_H$/;" d
MATERIAL_SKYBOX material.h /^ enum Type{MATERIAL_2D,MATERIAL_SKYBOX};$/;" e enum:vb01::Material::Type
MESH_H mesh.h /^#define MESH_H$/;" d
MODEL_H model.h /^#define MODEL_H$/;" d
Material material.cpp /^ Material::Material(){$/;" f class:vb01::Material
Material material.cpp /^ Material::Material(Type type){$/;" f class:vb01::Material
Material material.h /^ class Material{$/;" c namespace:vb01
Mesh mesh.cpp /^ Mesh::Mesh(){$/;" f class:vb01::Mesh
Mesh mesh.cpp /^ Mesh::Mesh(Vertex *vertices, unsigned int *indices,int numTris){$/;" f class:vb01::Mesh
@@ -107,27 +109,36 @@ STBI_rgb_alpha stb_image.h /^ STBI_rgb_alpha = 4$/;" e enum:__anon84e4e886010
STB_IMAGE_IMPLEMENTATION texture.cpp /^#define STB_IMAGE_IMPLEMENTATION$/;" d file:
Shader shader.cpp /^ Shader::Shader(string vertShaderPath, string fragShaderPath){$/;" f class:vb01::Shader
Shader shader.h /^ class Shader{$/;" c namespace:vb01
TEXTURE_2D texture.h /^ enum TextureType{TEXTURE_2D,TEXTURE_CUBEMAP};$/;" e enum:vb01::Texture::TextureType
TEXTURE_CUBEMAP texture.h /^ enum TextureType{TEXTURE_2D,TEXTURE_CUBEMAP};$/;" e enum:vb01::Texture::TextureType
TEXTURE_H texture.h /^#define TEXTURE_H$/;" d
Texture texture.cpp /^ Texture::Texture(string path){$/;" f class:vb01::Texture
Texture texture.cpp /^ Texture::Texture(string paths[6]){$/;" f class:vb01::Texture
Texture texture.h /^ class Texture{$/;" c namespace:vb01
TextureType texture.h /^ enum TextureType{TEXTURE_2D,TEXTURE_CUBEMAP};$/;" g class:vb01::Texture
Type light.h /^ enum Type{POINT,DIRECTIONAL,SPOT,AMBIENT};$/;" g class:vb01::Light
Type material.h /^ enum Type{MATERIAL_2D,MATERIAL_SKYBOX};$/;" g class:vb01::Material
VAO mesh.h /^ unsigned int *indices,VAO,VBO,EBO;$/;" m class:vb01::Mesh typeref:typename:unsigned int *
VBO mesh.h /^ unsigned int *indices,VAO,VBO,EBO;$/;" m class:vb01::Mesh typeref:typename:unsigned int *
VECTOR_H vector.h /^#define VECTOR_H$/;" d
VEC_I vector.cpp /^ const Vector2 Vector2::VEC_I(1,0); $/;" m class:vb01::Vector2 typeref:typename:const Vector2
VEC_I vector.cpp /^ const Vector3 Vector3::VEC_I(1,0,0); $/;" m class:vb01::Vector3 typeref:typename:const Vector3
VEC_I vector.h /^ static const Vector2 VEC_I,VEC_J,VEC_ZERO;$/;" m struct:vb01::Vector2 typeref:typename:const Vector2
VEC_I vector.h /^ static const Vector3 VEC_I,VEC_J,VEC_K,VEC_ZERO;$/;" m struct:vb01::Vector3 typeref:typename:const Vector3
VEC_I vector.h /^ static const Vector2 VEC_IJ, VEC_I,VEC_J,VEC_ZERO;$/;" m struct:vb01::Vector2 typeref:typename:const Vector2
VEC_I vector.h /^ static const Vector3 VEC_IJK, VEC_I,VEC_J,VEC_K,VEC_ZERO;$/;" m struct:vb01::Vector3 typeref:typename:const Vector3
VEC_IJ vector.cpp /^ const Vector2 Vector2::VEC_IJ(1,1); $/;" m class:vb01::Vector2 typeref:typename:const Vector2
VEC_IJ vector.h /^ static const Vector2 VEC_IJ, VEC_I,VEC_J,VEC_ZERO;$/;" m struct:vb01::Vector2 typeref:typename:const Vector2
VEC_IJK vector.cpp /^ const Vector3 Vector3::VEC_IJK(1,1,1); $/;" m class:vb01::Vector3 typeref:typename:const Vector3
VEC_IJK vector.h /^ static const Vector3 VEC_IJK, VEC_I,VEC_J,VEC_K,VEC_ZERO;$/;" m struct:vb01::Vector3 typeref:typename:const Vector3
VEC_J vector.cpp /^ const Vector2 Vector2::VEC_J(0,1); $/;" m class:vb01::Vector2 typeref:typename:const Vector2
VEC_J vector.cpp /^ const Vector3 Vector3::VEC_J(0,1,0); $/;" m class:vb01::Vector3 typeref:typename:const Vector3
VEC_J vector.h /^ static const Vector2 VEC_I,VEC_J,VEC_ZERO;$/;" m struct:vb01::Vector2 typeref:typename:const Vector2
VEC_J vector.h /^ static const Vector3 VEC_I,VEC_J,VEC_K,VEC_ZERO;$/;" m struct:vb01::Vector3 typeref:typename:const Vector3
VEC_J vector.h /^ static const Vector2 VEC_IJ, VEC_I,VEC_J,VEC_ZERO;$/;" m struct:vb01::Vector2 typeref:typename:const Vector2
VEC_J vector.h /^ static const Vector3 VEC_IJK, VEC_I,VEC_J,VEC_K,VEC_ZERO;$/;" m struct:vb01::Vector3 typeref:typename:const Vector3
VEC_K vector.cpp /^ const Vector3 Vector3::VEC_K(0,0,1); $/;" m class:vb01::Vector3 typeref:typename:const Vector3
VEC_K vector.h /^ static const Vector3 VEC_I,VEC_J,VEC_K,VEC_ZERO;$/;" m struct:vb01::Vector3 typeref:typename:const Vector3
VEC_K vector.h /^ static const Vector3 VEC_IJK, VEC_I,VEC_J,VEC_K,VEC_ZERO;$/;" m struct:vb01::Vector3 typeref:typename:const Vector3
VEC_ZERO vector.cpp /^ const Vector2 Vector2::VEC_ZERO(0,0); $/;" m class:vb01::Vector2 typeref:typename:const Vector2
VEC_ZERO vector.cpp /^ const Vector3 Vector3::VEC_ZERO(0,0,0); $/;" m class:vb01::Vector3 typeref:typename:const Vector3
VEC_ZERO vector.h /^ static const Vector2 VEC_I,VEC_J,VEC_ZERO;$/;" m struct:vb01::Vector2 typeref:typename:const Vector2
VEC_ZERO vector.h /^ static const Vector3 VEC_I,VEC_J,VEC_K,VEC_ZERO;$/;" m struct:vb01::Vector3 typeref:typename:const Vector3
VEC_ZERO vector.h /^ static const Vector2 VEC_IJ, VEC_I,VEC_J,VEC_ZERO;$/;" m struct:vb01::Vector2 typeref:typename:const Vector2
VEC_ZERO vector.h /^ static const Vector3 VEC_IJK, VEC_I,VEC_J,VEC_K,VEC_ZERO;$/;" m struct:vb01::Vector3 typeref:typename:const Vector3
VERTEX shader.h /^ enum ErrorType{VERTEX,FRAGMENT,PROGRAM};$/;" e enum:vb01::Shader::ErrorType
Vector2 vector.h /^ Vector2(){};$/;" f struct:vb01::Vector2
Vector2 vector.h /^ Vector2(float x,float y){$/;" f struct:vb01::Vector2
@@ -157,6 +168,7 @@ __anon84e4e8861108 stb_image.h /^{$/;" s
__anon84e4e8861208 stb_image.h /^{$/;" s
__anon84e4e8861308 stb_image.h /^{$/;" s
addDiffuseMap material.h /^ void addDiffuseMap(std::string diffuseMap){diffuseMapTextures.push_back(new Texture(diffuseMa/;" f class:vb01::Material typeref:typename:void
addDiffuseMap material.h /^ void addDiffuseMap(std::string diffuseMap[6]){diffuseMapTextures.push_back(new Texture(diffus/;" f class:vb01::Material typeref:typename:void
addLight node.cpp /^ void Node::addLight(Light *light){$/;" f class:vb01::Node typeref:typename:void
addNormalMap material.h /^ void addNormalMap(std::string normalMap){normalMapTextures.push_back(new Texture(normalMap));/;" f class:vb01::Material typeref:typename:void
addSpecularMap material.h /^ void addSpecularMap(std::string specularMap){specularMapTextures.push_back(new Texture(specul/;" f class:vb01::Material typeref:typename:void
@@ -188,6 +200,7 @@ color light.h /^ Vector3 pos,color,attenuationValues=Vector3(1.8,.7,1),directi
color_table stb_image.h /^ stbi_uc *color_table;$/;" m struct:__anon84e4e8861308 typeref:typename:stbi_uc *
conj quaternion.h /^ inline vb01::quaternion conj(){return (*this+vb01::quaternion(0,1,0,0)*(*this)*vb01::quaterni/;" f class:vb01::quaternion typeref:typename:vb01::quaternion
construct mesh.cpp /^ void Mesh::construct(){$/;" f class:vb01::Mesh typeref:typename:void
createSkybox root.cpp /^ void Root::createSkybox(string textures[6]){$/;" f class:vb01::Root typeref:typename:void
cross vector.h /^ Vector3 cross(Vector3 v){return Vector3(y*v.z-v.y*z,x*v.z-v.x*z,x*v.y-v.x*y);}$/;" f struct:vb01::Vector3 typeref:typename:Vector3
cur_x stb_image.h /^ int cur_x, cur_y;$/;" m struct:__anon84e4e8861308 typeref:typename:int
cur_y stb_image.h /^ int cur_x, cur_y;$/;" m struct:__anon84e4e8861308 typeref:typename:int
@@ -226,6 +239,7 @@ direction camera.h /^ Vector3 position=Vector3(0,0,0),direction=Vector3(0,0,1)
direction light.h /^ Vector3 pos,color,attenuationValues=Vector3(1.8,.7,1),direction;$/;" m class:vb01::Light typeref:typename:Vector3
dot vector.h /^ float dot(Vector2 v){return x*v.x+y*v.y;}$/;" f struct:vb01::Vector2 typeref:typename:float
dot vector.h /^ float dot(Vector3 v){return x*v.x+y*v.y+z*v.z;}$/;" f struct:vb01::Vector3 typeref:typename:float
editShader shader.cpp /^ void Shader::editShader(bool vertexShader, char firstChar, char secondChar, string insertion){$/;" f class:vb01::Shader typeref:typename:void
eflags stb_image.h /^ int flags, bgindex, ratio, transparent, eflags;$/;" m struct:__anon84e4e8861308 typeref:typename:int
eob_run stb_image.h /^ int eob_run;$/;" m struct:__anon84e4e8860808 typeref:typename:int
eof stb_image.h /^ int (*eof) (void *user); \/\/ returns nonzero if we are at end o/;" m struct:__anon84e4e8860208 typeref:typename:int (*)(void * user)
@@ -324,6 +338,7 @@ line0 stb_image.h /^ stbi_uc *line0,*line1;$/;" m struct:__anon84e4e8860a08 ty
line1 stb_image.h /^ stbi_uc *line0,*line1;$/;" m struct:__anon84e4e8860a08 typeref:typename:stbi_uc **
line_size stb_image.h /^ int line_size;$/;" m struct:__anon84e4e8861308 typeref:typename:int
linebuf stb_image.h /^ stbi_uc *linebuf;$/;" m struct:__anon84e4e8860808::__anon84e4e8860908 typeref:typename:stbi_uc *
loadShaders shader.cpp /^ void Shader::loadShaders(){$/;" f class:vb01::Shader typeref:typename:void
load_jpeg_image stb_image.h /^static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp, int req_comp)$/;" f typeref:typename:stbi_uc *
lookAt camera.cpp /^ void Camera::lookAt(Vector3 direction, Vector3 up){$/;" f class:vb01::Camera typeref:typename:void
lpal stb_image.h /^ stbi_uc lpal[256][4];$/;" m struct:__anon84e4e8861308 typeref:typename:stbi_uc[256][4]
@@ -420,7 +435,6 @@ setMaterial mesh.h /^ void setMaterial(Material *mat){this->material=mat;}$/;"
setMaterial model.cpp /^ void Model::setMaterial(Material *mat){$/;" f class:vb01::Model typeref:typename:void
setNode light.h /^ inline void setNode(Node *node){this->node=node;}$/;" f class:vb01::Light typeref:typename:void
setNode mesh.h /^ inline void setNode(Node *node){this->node=node;}$/;" f class:vb01::Mesh typeref:typename:void
setNumLights shader.cpp /^ void Shader::setNumLights(int numLights){$/;" f class:vb01::Shader typeref:typename:void
setOuterAngle light.h /^ inline void setOuterAngle(float outerAngle){this->outerAngle=outerAngle;}$/;" f class:vb01::Light typeref:typename:void
setPosition camera.h /^ void setPosition(Vector3 position){this->position=position;}$/;" f class:vb01::Camera typeref:typename:void
setPosition light.h /^ inline void setPosition(Vector3 pos){this->pos=pos;}$/;" f class:vb01::Light typeref:typename:void
@@ -431,6 +445,7 @@ size stb_image.h /^ stbi_uc size[257];$/;" m struct:__anon84e4e8860708 typere
size stb_image.h /^ stbi_uc size[288];$/;" m struct:__anon84e4e8860b08 typeref:typename:stbi_uc[288]
size stb_image.h /^ stbi_uc size,type,channel;$/;" m struct:__anon84e4e8861108 typeref:typename:stbi_uc
skip stb_image.h /^ void (*skip) (void *user,int n); \/\/ skip the next 'n' bytes, or 'unget/;" m struct:__anon84e4e8860208 typeref:typename:void (*)(void * user,int n)
skybox root.h /^ Box *skybox=nullptr;$/;" m class:vb01::Root typeref:typename:Box *
spec_end stb_image.h /^ int spec_end;$/;" m struct:__anon84e4e8860808 typeref:typename:int
spec_start stb_image.h /^ int spec_start;$/;" m struct:__anon84e4e8860808 typeref:typename:int
specularMapTextures material.h /^ std::vector<Texture*> diffuseMapTextures,normalMapTextures,specularMapTextures;$/;" m class:vb01::Material typeref:typename:std::vector<Texture * >
@@ -714,10 +729,11 @@ todo stb_image.h /^ int restart_interval, todo;$/;" m struct:__anon84e4e886080
tq stb_image.h /^ int tq;$/;" m struct:__anon84e4e8860808::__anon84e4e8860908 typeref:typename:int
transparent stb_image.h /^ int flags, bgindex, ratio, transparent, eflags;$/;" m struct:__anon84e4e8861308 typeref:typename:int
type light.h /^ Type type;$/;" m class:vb01::Light typeref:typename:Type
type material.h /^ Type type;$/;" m class:vb01::Material typeref:typename:Type
type stb_image.h /^ stbi__uint32 type;$/;" m struct:__anon84e4e8860d08 typeref:typename:stbi__uint32
type stb_image.h /^ stbi_uc size,type,channel;$/;" m struct:__anon84e4e8861108 typeref:typename:stbi_uc
type texture.h /^ TextureType type;$/;" m class:vb01::Texture typeref:typename:TextureType
up camera.h /^ Vector3 position=Vector3(0,0,0),direction=Vector3(0,0,1),left=Vector3(1,0,0),up=Vector3(0,1,0/;" m class:vb01::Camera typeref:typename:Vector3
update box.cpp /^ void Box::update(){$/;" f class:vb01::Box typeref:typename:void
update camera.cpp /^ void Camera::update(){$/;" f class:vb01::Camera typeref:typename:void
update light.cpp /^ void Light::update(){$/;" f class:vb01::Light typeref:typename:void
update material.cpp /^ void Material::update(){$/;" f class:vb01::Material typeref:typename:void
+28 -1
View File
@@ -3,11 +3,14 @@
#include<glad.h>
#include<glfw3.h>
#include"texture.h"
#include<iostream>
using namespace std;
namespace vb01{
Texture::Texture(string path){
this->type=TextureType::TEXTURE_2D;
glGenTextures(1,&texture);
glBindTexture(GL_TEXTURE_2D,texture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
@@ -22,7 +25,31 @@ namespace vb01{
stbi_image_free(data);
}
Texture::Texture(string paths[6]){
this->type=TextureType::TEXTURE_CUBEMAP;
glGenTextures(1,&texture);
glBindTexture(GL_TEXTURE_CUBE_MAP,texture);
for(int i=0;i<6;i++){
data=stbi_load(paths[i].c_str(),&width,&height,&numChannels,0);
if(data){
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+i,0,GL_RGB,width,height,0,GL_RGB,GL_UNSIGNED_BYTE,data);
stbi_image_free(data);
}
else{
cout<<"Failed to read cubemap texture "<<i<<endl;
exit(-1);
}
}
glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_R,GL_CLAMP_TO_EDGE);
}
void Texture::select(){
glBindTexture(GL_TEXTURE_2D,texture);
glBindTexture(type==TEXTURE_2D?GL_TEXTURE_2D:GL_TEXTURE_CUBE_MAP,texture);
}
}
+4
View File
@@ -6,9 +6,13 @@
namespace vb01{
class Texture{
public:
enum TextureType{TEXTURE_2D,TEXTURE_CUBEMAP};
Texture(std::string);
Texture(std::string[6]);
void select();
private:
TextureType type;
unsigned int texture;
int width,height,numChannels;
float weight;
+1 -1
View File
@@ -15,6 +15,6 @@ uniform mat4 proj;
void main(){
gl_Position=proj*view*model*vec4(aPos,1);
fragPos=vec3(model*vec4(aPos,1));
texCoords=aTexCoords;
norm=mat3(transpose(inverse(model)))*aNorm;
texCoords=aTexCoords;
}
+2
View File
@@ -1,10 +1,12 @@
#include"vector.h"
namespace vb01{
const Vector2 Vector2::VEC_IJ(1,1);
const Vector2 Vector2::VEC_I(1,0);
const Vector2 Vector2::VEC_J(0,1);
const Vector2 Vector2::VEC_ZERO(0,0);
const Vector3 Vector3::VEC_IJK(1,1,1);
const Vector3 Vector3::VEC_I(1,0,0);
const Vector3 Vector3::VEC_J(0,1,0);
const Vector3 Vector3::VEC_K(0,0,1);
+2 -2
View File
@@ -24,7 +24,7 @@ namespace vb01{
Vector3 cross(Vector3 v){return Vector3(y*v.z-v.y*z,x*v.z-v.x*z,x*v.y-v.x*y);}
float x,y,z;
static const Vector3 VEC_I,VEC_J,VEC_K,VEC_ZERO;
static const Vector3 VEC_IJK, VEC_I,VEC_J,VEC_K,VEC_ZERO;
};
struct Vector2{
@@ -44,7 +44,7 @@ namespace vb01{
Vector2 norm(){return *this/getLength();}
float x,y;
static const Vector2 VEC_I,VEC_J,VEC_ZERO;
static const Vector2 VEC_IJ, VEC_I,VEC_J,VEC_ZERO;
};
}