├── .gitignore ├── examples ├── medium │ ├── textures │ │ └── container.jpg │ ├── Makefile │ ├── shaders │ │ ├── fragmentLight.glsl │ │ ├── vertexLight.glsl │ │ ├── vertexCube.glsl │ │ └── fragmentCube.glsl │ ├── Recipe │ ├── README.md │ ├── draw │ │ ├── shader.h │ │ ├── mesh.h │ │ ├── shader.cpp │ │ └── mesh.cpp │ ├── ui │ │ ├── display.h │ │ ├── camera.h │ │ ├── display.cpp │ │ └── camera.cpp │ ├── main.cpp │ └── mesh │ │ └── cube.h └── small │ ├── main.cpp │ ├── test.h │ ├── Recipe │ └── test.cpp ├── Makefile ├── main.go ├── logger └── logger.go ├── README.md ├── CODE_OF_CONDUCT.md ├── worker └── worker.go ├── manager └── manager.go ├── parser ├── parser.go └── lexer.go └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | Test/ -------------------------------------------------------------------------------- /examples/medium/textures/container.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellozee/cook/HEAD/examples/medium/textures/container.jpg -------------------------------------------------------------------------------- /examples/medium/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | g++ -o GLWindow main.cpp ui/display.cpp draw/mesh.cpp draw/shader.cpp ui/camera.cpp -lSDL2 -lGLEW -lGL -lSOIL 3 | -------------------------------------------------------------------------------- /examples/medium/shaders/fragmentLight.glsl: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | out vec4 color; 4 | 5 | void main(){ 6 | color = vec4(1.0f,1.0f,1.0f,1.0f); 7 | } -------------------------------------------------------------------------------- /examples/small/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "test.h" 3 | 4 | int main(){ 5 | testClass a("yay"); 6 | std::cout << a.print() << std::endl; 7 | } 8 | -------------------------------------------------------------------------------- /examples/small/test.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class testClass{ 6 | private: 7 | std::string _a; 8 | public: 9 | testClass(std::string a); 10 | std::string print(); 11 | }; 12 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | go build -o cook main.go 3 | 4 | .PHONY: clean 5 | clean: 6 | rm cook 7 | 8 | .PHONY: install 9 | install: 10 | sudo cp cook /usr/bin/ 11 | 12 | .PHONY: uninstall 13 | uninstall: 14 | sudo rm /usr/bin/cook 15 | -------------------------------------------------------------------------------- /examples/small/Recipe: -------------------------------------------------------------------------------- 1 | entity #{ 2 | binary = g++ 3 | name = demo 4 | start = main 5 | includes = 6 | others = -Wall -Wextra -std=c++17 7 | } 8 | 9 | entity main{ 10 | file = main.cpp 11 | deps = test 12 | } 13 | entity test{ 14 | file = test.cpp 15 | } 16 | -------------------------------------------------------------------------------- /examples/medium/shaders/vertexLight.glsl: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout (location = 0) in vec3 position; 4 | layout (location = 1) in vec3 normals; 5 | 6 | uniform mat4 model; 7 | uniform mat4 view; 8 | uniform mat4 projection; 9 | 10 | void main(){ 11 | gl_Position = projection * view * model * vec4(position,1.0f); 12 | } -------------------------------------------------------------------------------- /examples/medium/shaders/vertexCube.glsl: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout (location = 0) in vec3 position; 4 | layout (location = 1) in vec3 normals; 5 | 6 | out vec3 Normals; 7 | out vec3 fragPos; 8 | 9 | uniform mat4 model; 10 | uniform mat4 view; 11 | uniform mat4 projection; 12 | 13 | void main(){ 14 | gl_Position = projection * view * model * vec4(position,1.0f); 15 | fragPos = vec3(model * vec4(position,1.0f)); 16 | Normals = normals; 17 | } -------------------------------------------------------------------------------- /examples/medium/Recipe: -------------------------------------------------------------------------------- 1 | entity #{ 2 | binary = g++; 3 | name = GLWindow; 4 | start = main; 5 | ldflags = -lSDL2 -lGLEW -lGL -lSOIL; 6 | includes = ; 7 | others = -Wall -Wextra; 8 | } 9 | 10 | entity main{ 11 | file = main.cpp; 12 | deps = camera display mesh shader; 13 | } 14 | 15 | entity camera{ 16 | file = ui/camera.cpp; 17 | deps = ; 18 | } 19 | 20 | entity display{ 21 | file = ui/display.cpp; 22 | deps = ; 23 | } 24 | 25 | entity mesh{ 26 | file = draw/mesh.cpp; 27 | deps = ; 28 | } 29 | 30 | entity shader{ 31 | file = draw/shader.cpp; 32 | deps = ; 33 | } 34 | -------------------------------------------------------------------------------- /examples/medium/README.md: -------------------------------------------------------------------------------- 1 | # OpenGL Practice Repository 2 | 3 | ### What is done upto now 4 | 5 | - **Display Class** : Done, `ui/display.h` 6 | - **Mesh Class** : Done, `draw/mesh.h` 7 | - **Shader Class** : Done, `draw/shader.h` 8 | - **Camera Class** : Done, `ui/camera.h` 9 | 10 | ### To Do 11 | 12 | - **Lighting** `[Ongoing]` 13 | - **Model Loading** 14 | 15 | 16 | 17 | ### Resources 18 | 19 | - **Vertex Shader** : `shaders/shader.vs` 20 | - **Fragment Shader** : `shaders/shader.fs` 21 | - **Texture** : `textures/container.jpg` -------------------------------------------------------------------------------- /examples/small/test.cpp: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | 3 | testClass::testClass(std::string a): 4 | _a(a) 5 | { 6 | } 7 | 8 | std::string testClass::print() 9 | { 10 | return _a; 11 | } 12 | -------------------------------------------------------------------------------- /examples/medium/draw/shader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | class Shader{ 9 | 10 | public: 11 | 12 | Shader(const std::string &vertexShaderSource,const std::string &fragmentShaderSource); 13 | ~Shader(); 14 | 15 | void Bind(); 16 | 17 | GLuint program; 18 | 19 | private: 20 | GLuint _shaders[2]; 21 | 22 | static void CheckShaderError(GLuint shader, GLuint flag, bool isProgram, const std::string& errorMessage); 23 | static std::string LoadShader(const std::string& fileName); 24 | static GLuint CreateShader(const std::string &text, GLenum shaderType); 25 | }; -------------------------------------------------------------------------------- /examples/medium/draw/mesh.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | class Mesh{ 13 | 14 | public: 15 | Mesh(std::vector meshData); 16 | ~Mesh(); 17 | 18 | void Draw(GLuint program); 19 | void addTexture(const char * path); 20 | void Translate(glm::vec3 transVec); 21 | void Rotate(float angle, glm::vec3 axis); 22 | void Scale(glm::vec3 scaleVec); 23 | 24 | private: 25 | 26 | GLuint _vbo,_vao,_texture; 27 | 28 | glm::mat4 _model; 29 | 30 | unsigned int _drawCount; 31 | }; -------------------------------------------------------------------------------- /examples/medium/ui/display.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //Drawing the window using SDL 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class Display{ 11 | 12 | public: 13 | //Takes in the width , height and title of the window 14 | Display(int width, int height, const std::string &title); 15 | ~Display(); 16 | 17 | //Checking whether the window is closed or not 18 | inline bool isClosed(){return _isClosed;} 19 | //Display what is drawn 20 | void swapBuffers(); 21 | //Clearing the screen for further drawing 22 | void clear(float r,float g,float b,float a); 23 | 24 | void manageEvents(SDL_Event event); 25 | 26 | private: 27 | SDL_Window *_window; 28 | SDL_GLContext _glContext; 29 | 30 | bool _isClosed = false; 31 | 32 | }; -------------------------------------------------------------------------------- /examples/medium/shaders/fragmentCube.glsl: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | in vec3 fragPos; 4 | in vec3 Normals; 5 | 6 | out vec4 color; 7 | 8 | uniform vec3 lightColor; 9 | uniform vec3 cubeColor; 10 | uniform vec3 lightPos; 11 | uniform vec3 viewPos; 12 | 13 | void main(){ 14 | 15 | float ambientStrength = 0.1f; 16 | float specularStrength = 1.0f; 17 | 18 | vec3 ambient = ambientStrength * lightColor; 19 | 20 | vec3 norm = normalize(Normals); 21 | vec3 lightDir = normalize(lightPos - fragPos); 22 | vec3 viewDir = normalize(viewPos - fragPos); 23 | vec3 reflectDir = reflect(-lightDir,norm); 24 | 25 | float diff = max(dot(norm, lightDir), 0.0); 26 | float spec = pow(max(dot(viewDir,reflectDir),0.0),256); 27 | 28 | vec3 specular = specularStrength * spec * lightColor; 29 | vec3 diffuse = diff * lightColor; 30 | vec3 result = (ambient + diffuse + specular) * cubeColor; 31 | 32 | color = vec4(result,1.0f); 33 | } -------------------------------------------------------------------------------- /examples/medium/ui/camera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | class Camera{ 13 | 14 | public: 15 | Camera(glm::vec3 cameraPos, glm::vec3 cameraFront, glm::vec3 cameraUp, GLfloat fov, GLfloat ratio, GLfloat nearPlane, GLfloat farPlane); 16 | ~Camera(); 17 | 18 | void Use(GLuint program); 19 | void manageEvents(SDL_Event event); 20 | void doMovement(unsigned int currentFrame); 21 | 22 | glm::vec3 cameraPos; 23 | 24 | private: 25 | glm::mat4 _projection, _view; 26 | glm::vec3 _cameraFront, _cameraUp; 27 | 28 | unsigned int _deltaTime, _lastFrame; 29 | 30 | GLfloat _pitch, _yaw, _sensitivity; 31 | GLfloat _xoffset,_yoffset; 32 | 33 | bool _firstMouse,_out; 34 | std::vector_keys; 35 | 36 | GLfloat _cameraSpeed; 37 | 38 | void changeView(SDL_Event event); 39 | 40 | }; -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "os" 7 | 8 | lg "./logger" 9 | mg "./manager" 10 | ps "./parser" 11 | wk "./worker" 12 | ) 13 | 14 | var cleanFlag = flag.Bool("clean", false, "To clean the cached data") 15 | var helpFlag = flag.Bool("help", false, "To show this help message") 16 | 17 | func main() { 18 | 19 | flag.Parse() 20 | 21 | help := `Usage: cook [OPTIONS] 22 | 23 | --help: 24 | To show this help message 25 | 26 | --clean: 27 | To clean the cached data 28 | 29 | ` 30 | if *helpFlag == true { 31 | fmt.Println(help) 32 | return 33 | } 34 | 35 | if *cleanFlag == true { 36 | os.RemoveAll("Cooking/") 37 | return 38 | } 39 | 40 | logger := lg.NewLogger() 41 | 42 | //Reading the Recipe File 43 | manager, err := mg.NewManager(&logger) 44 | must(err, &logger) 45 | 46 | Recipe := string(manager.FileData) 47 | 48 | //Parsing the Recipe File 49 | parser := ps.NewParser(Recipe, &logger) 50 | err = parser.Parse() 51 | must(err, &logger) 52 | 53 | worker := wk.NewWorker(&logger) 54 | err = manager.GenerateFileList(parser, parser.CompilerDetails.Start) 55 | must(err, &logger) 56 | 57 | if _, err := os.Stat("Cooking/details.json"); err == nil { 58 | 59 | err = manager.ReadDetails() 60 | must(err, &logger) 61 | 62 | worker.CompareAndCompile(parser, &manager) 63 | 64 | } else { 65 | _ = os.Mkdir("Cooking", 0755) 66 | err = manager.GenerateList() 67 | must(err, &logger) 68 | worker.CompileFirst(parser, manager) 69 | } 70 | 71 | err = manager.WriteDetails() 72 | must(err, &logger) 73 | 74 | err = worker.Link(parser) 75 | must(err, &logger) 76 | 77 | logger.WriteLog() 78 | 79 | fmt.Println("Build finished, logs reported to Cooking/log") 80 | 81 | } 82 | 83 | func must(err error, log *lg.Logger) { 84 | if err != nil { 85 | fmt.Println("Something went wrong, please check Cooking/log/build.errors") 86 | log.WriteLog() 87 | os.Exit(-1) 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /examples/medium/ui/display.cpp: -------------------------------------------------------------------------------- 1 | #include "display.h" 2 | 3 | Display::Display(int width, int height, const std::string &title) 4 | { 5 | //Initializing SDL 6 | SDL_Init(SDL_INIT_EVERYTHING); 7 | 8 | //Setting up OpenGL Attributes 9 | SDL_GL_SetAttribute(SDL_GL_RED_SIZE,8); 10 | SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,8); 11 | SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,8); 12 | SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE,8); 13 | SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE,32); 14 | SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); 15 | 16 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); 17 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); 18 | 19 | _window = SDL_CreateWindow(title.c_str(),SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,width,height,SDL_WINDOW_OPENGL); 20 | _glContext = SDL_GL_CreateContext(_window); 21 | 22 | SDL_SetRelativeMouseMode(SDL_TRUE); 23 | SDL_WarpMouseInWindow(_window, width/2, height/2); 24 | 25 | glewExperimental = GL_TRUE; //oh boy you gave me a lot of headache 26 | GLenum status = glewInit(); 27 | 28 | if(status != GLEW_OK){ 29 | std::cerr << "GLEW failed to initialize." << std::endl; 30 | } 31 | 32 | glEnable(GL_DEPTH_TEST); 33 | } 34 | 35 | Display::~Display() 36 | { 37 | SDL_GL_DeleteContext(_glContext); 38 | SDL_DestroyWindow(_window); 39 | SDL_Quit(); 40 | } 41 | 42 | void Display::clear(float r,float g,float b,float a) 43 | { 44 | glClearColor(r,g,b,a); 45 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 46 | } 47 | 48 | void Display::swapBuffers() 49 | { 50 | SDL_GL_SwapWindow(_window); 51 | } 52 | 53 | void Display::manageEvents(SDL_Event event) 54 | { 55 | if(event.type == SDL_QUIT){ 56 | _isClosed = true; 57 | } 58 | 59 | if(event.type == SDL_KEYDOWN){ 60 | switch (event.key.keysym.sym){ 61 | case SDLK_ESCAPE: 62 | _isClosed = true; 63 | break; 64 | default: 65 | break; 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /logger/logger.go: -------------------------------------------------------------------------------- 1 | package logger 2 | 3 | import ( 4 | "os" 5 | "time" 6 | ) 7 | 8 | //Logger Data Structure for holding data which is going to be written 9 | type Logger struct { 10 | SuccessLog string 11 | ErrorsLog string 12 | WarningsLog string 13 | } 14 | 15 | //ReportSuccess Function to write to the success log 16 | func (log *Logger) ReportSuccess(line string) { 17 | if line == "" { 18 | return 19 | } 20 | tm := time.Now() 21 | toLog := log.SuccessLog + tm.Format("Mon Jan 2 15:04:05 -0700 MST 2006") + " > " + line + "\n" 22 | log.SuccessLog = toLog 23 | } 24 | 25 | //ReportError Function to write to the errors log 26 | func (log *Logger) ReportError(line string) { 27 | if line == "" { 28 | return 29 | } 30 | tm := time.Now() 31 | toLog := log.ErrorsLog + tm.Format("Mon Jan 2 15:04:05 -0700 MST 2006") + " > " + line + "\n" 32 | log.ErrorsLog = toLog 33 | } 34 | 35 | //ReportWarning Function to write to the warnings log 36 | func (log *Logger) ReportWarning(line string) { 37 | if line == "" { 38 | return 39 | } 40 | tm := time.Now() 41 | toLog := log.WarningsLog + tm.Format("Mon Jan 2 15:04:05 -0700 MST 2006") + " > " + line + "\n" 42 | log.WarningsLog = toLog 43 | } 44 | 45 | //WriteLog Function to write the files in the log directory 46 | func (log *Logger) WriteLog() { 47 | 48 | if _, err := os.Stat("Cooking/log"); err != nil { 49 | os.Mkdir("Cooking", 0755) 50 | os.Mkdir("Cooking/log", 0755) 51 | } 52 | 53 | suffix := "=======================================================" 54 | suffix += suffix + "\n" 55 | log.SuccessLog += suffix 56 | log.ErrorsLog += suffix 57 | log.WarningsLog += suffix 58 | 59 | file, _ := os.OpenFile("Cooking/log/build.success", 60 | os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644) 61 | file.Write([]byte(log.SuccessLog)) 62 | 63 | file, _ = os.OpenFile("Cooking/log/build.errors", 64 | os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644) 65 | file.Write([]byte(log.ErrorsLog)) 66 | 67 | file, _ = os.OpenFile("Cooking/log/build.warnings", 68 | os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644) 69 | file.Write([]byte(log.WarningsLog)) 70 | 71 | file.Close() 72 | 73 | } 74 | 75 | //NewLogger Function for creating a new logger object 76 | func NewLogger() Logger { 77 | tm := time.Now() 78 | suffix := " BUILD =================================================\n\n" 79 | log := Logger{ 80 | SuccessLog: tm.String() + suffix, 81 | ErrorsLog: tm.String() + suffix, 82 | WarningsLog: tm.String() + suffix, 83 | } 84 | 85 | return log 86 | } 87 | -------------------------------------------------------------------------------- /examples/medium/main.cpp: -------------------------------------------------------------------------------- 1 | //Includes 2 | #include "ui/display.h" //For drawing the window, uses SDL 3 | #include "draw/mesh.h" //For generating the meshes 4 | #include "draw/shader.h" //Compiling Shaders 5 | #include "ui/camera.h" //Camera Controls 6 | #include "mesh/cube.h" //The default cube 7 | 8 | int main(){ 9 | 10 | const int WIDTH = 800, HEIGHT = 600; 11 | 12 | GLfloat ratio = (GLfloat) WIDTH/ (GLfloat) HEIGHT; 13 | 14 | Display disp(WIDTH,HEIGHT,"Testing"); // SDL Window for drawing things 15 | 16 | //Intializing mesh 17 | Mesh cube(defaultCube); 18 | //cube.addTexture("textures/container.jpg"); // Not required for now 19 | 20 | cube.Rotate(45.0f,glm::vec3(0.0f,1.0f,0.0f)); 21 | cube.Translate(glm::vec3(-1.0f,0.0f,-1.0f)); 22 | 23 | Mesh light(defaultCube); 24 | 25 | glm::vec3 lightPos(1.2f, 1.0f, 2.0f); 26 | 27 | light.Scale(glm::vec3(0.2f)); 28 | light.Translate(lightPos); 29 | 30 | //Fetching Shaders 31 | Shader shader("shaders/vertexCube.glsl","shaders/fragmentCube.glsl"); 32 | Shader lightShader("shaders/vertexLight.glsl","shaders/fragmentLight.glsl"); 33 | 34 | //Creating the camera 35 | Camera cam(glm::vec3(0.0f, 0.0f, 6.0f), glm::vec3(0.0f, 0.0f, -1.0f), glm::vec3(0.0f, 1.0f, 0.0f), 45.0f, ratio, 0.1f, 100.0f); 36 | 37 | while(!disp.isClosed()){ 38 | //Clearing the screen to draw 39 | disp.clear(0.2f,0.2f,0.2f,1.0f); 40 | 41 | SDL_Event event; 42 | 43 | if(SDL_PollEvent(&event)){ 44 | disp.manageEvents(event); 45 | cam.manageEvents(event); 46 | } 47 | 48 | //Attaching the shader to the program 49 | shader.Bind(); 50 | cam.Use(shader.program); 51 | //Drawing the mesh 52 | 53 | glUniform3f(glGetUniformLocation(shader.program,"cubeColor"),1.0f, 0.5f, 0.31f); 54 | glUniform3f(glGetUniformLocation(shader.program,"lightColor"),1.0f,1.0f,1.0f); 55 | glUniform3f(glGetUniformLocation(shader.program,"lightPos"),lightPos.x,lightPos.y,lightPos.z); 56 | glUniform3f(glGetUniformLocation(shader.program,"viewPos"), cam.cameraPos.x, cam.cameraPos.y, cam.cameraPos.z); 57 | 58 | cube.Draw(shader.program); 59 | 60 | lightShader.Bind(); 61 | cam.Use(lightShader.program); 62 | light.Draw(lightShader.program); 63 | 64 | cam.doMovement(SDL_GetTicks()); 65 | 66 | //Now Displying what is drawn 67 | disp.swapBuffers(); 68 | } 69 | 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /examples/medium/ui/camera.cpp: -------------------------------------------------------------------------------- 1 | #include "camera.h" 2 | 3 | Camera::Camera(glm::vec3 cameraPos, glm::vec3 cameraFront, glm::vec3 cameraUp, GLfloat fov, GLfloat ratio, GLfloat nearPlane, GLfloat farPlane): 4 | cameraPos(cameraPos),_cameraFront(cameraFront),_cameraUp(cameraUp),_keys(322,false) 5 | { 6 | _projection = glm::perspective(glm::radians(fov), ratio, nearPlane, farPlane); 7 | _cameraSpeed = 0.05f; 8 | _deltaTime = 0; 9 | _lastFrame = 0; 10 | _pitch = 0.0f ; 11 | _yaw = -90.0f; 12 | _sensitivity = 0.01f; 13 | _xoffset = 0.0f; 14 | _yoffset = 0.0f; 15 | } 16 | 17 | Camera::~Camera() 18 | { 19 | 20 | } 21 | 22 | void Camera::Use(GLuint program) 23 | { 24 | 25 | _view = glm::lookAt(cameraPos, cameraPos + _cameraFront, _cameraUp); 26 | 27 | GLint modelLoc = glGetUniformLocation(program, "view"); 28 | glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(_view)); 29 | 30 | modelLoc = glGetUniformLocation(program, "projection"); 31 | glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(_projection)); 32 | 33 | } 34 | 35 | void Camera::manageEvents(SDL_Event event) 36 | { 37 | if(event.type == SDL_KEYDOWN){ 38 | _keys[event.key.keysym.sym] = true; 39 | }else if(event.type == SDL_KEYUP){ 40 | _keys[event.key.keysym.sym] = false; 41 | } 42 | 43 | if(event.type == SDL_MOUSEMOTION){ 44 | changeView(event); 45 | } 46 | } 47 | 48 | void Camera::doMovement(unsigned int currentFrame) 49 | { 50 | _deltaTime = currentFrame - _lastFrame; 51 | _lastFrame = currentFrame; 52 | 53 | _cameraSpeed = (float) _deltaTime * 0.002; 54 | 55 | if(_keys[SDLK_w]){ 56 | cameraPos += _cameraFront * _cameraSpeed; 57 | } 58 | 59 | if(_keys[SDLK_a]){ 60 | cameraPos -= glm::normalize(glm::cross(_cameraFront, _cameraUp)) * _cameraSpeed; 61 | } 62 | 63 | if(_keys[SDLK_s]){ 64 | cameraPos -= _cameraFront * _cameraSpeed; 65 | } 66 | 67 | if(_keys[SDLK_d]){ 68 | cameraPos += glm::normalize(glm::cross(_cameraFront, _cameraUp)) * _cameraSpeed; 69 | } 70 | } 71 | 72 | void Camera::changeView(SDL_Event event) 73 | { 74 | _xoffset = event.motion.xrel; 75 | _yoffset = -1 * event.motion.yrel; 76 | 77 | _xoffset *= _sensitivity; 78 | _yoffset *= _sensitivity; 79 | 80 | _yaw += _xoffset; 81 | _pitch += _yoffset; 82 | 83 | if (_pitch > 89.0f){ 84 | _pitch = 89.0f; 85 | } 86 | 87 | if (_pitch < -89.0f){ 88 | _pitch = -89.0f; 89 | } 90 | 91 | glm::vec3 front; 92 | front.x = cos(glm::radians(_yaw)) * cos(glm::radians(_pitch)); 93 | front.y = sin(glm::radians(_pitch)); 94 | front.z = sin(glm::radians(_yaw)) * cos(glm::radians(_pitch)); 95 | 96 | _cameraFront = glm::normalize(front); 97 | } -------------------------------------------------------------------------------- /examples/medium/draw/shader.cpp: -------------------------------------------------------------------------------- 1 | #include "shader.h" 2 | 3 | Shader::Shader(const std::string &vertexShaderSource,const std::string &fragmentShaderSource) 4 | { 5 | program = glCreateProgram(); 6 | _shaders[0] = CreateShader(LoadShader(vertexShaderSource),GL_VERTEX_SHADER); 7 | _shaders[1] = CreateShader(LoadShader(fragmentShaderSource),GL_FRAGMENT_SHADER); 8 | 9 | for(unsigned int i=0;i<2;i++){ 10 | glAttachShader(program,_shaders[i]); 11 | } 12 | 13 | glLinkProgram(program); 14 | 15 | CheckShaderError(program,GL_LINK_STATUS,true,"Error Shader program failed to link"); 16 | 17 | glValidateProgram(program); 18 | 19 | CheckShaderError(program,GL_VALIDATE_STATUS,true,"Error Shader program is invalid"); 20 | } 21 | 22 | Shader::~Shader() 23 | { 24 | for(int i=0;i<2;i++){ 25 | glDetachShader(program,_shaders[i]); 26 | glDeleteShader(_shaders[i]); 27 | } 28 | glDeleteProgram(program); 29 | } 30 | 31 | void Shader::Bind() 32 | { 33 | glUseProgram(program); 34 | } 35 | 36 | GLuint Shader::CreateShader(const std::string &text, GLenum shaderType) 37 | { 38 | GLuint shader = glCreateShader(shaderType); 39 | 40 | if(shader == 0){ 41 | std::cerr << "Error : Shader Creation failed." << std::endl; 42 | } 43 | 44 | const GLchar* shaderSource; 45 | GLint shaderLength; 46 | 47 | shaderSource = text.c_str(); 48 | shaderLength = text.length(); 49 | 50 | glShaderSource(shader,1,&shaderSource,&shaderLength); 51 | glCompileShader(shader); 52 | 53 | CheckShaderError(shader,GL_COMPILE_STATUS,false,"Error Shader compilation failed"); 54 | 55 | return shader; 56 | } 57 | 58 | std::string Shader::LoadShader(const std::string& fileName) 59 | { 60 | std::ifstream file; 61 | file.open((fileName).c_str()); 62 | 63 | std::string output; 64 | std::string line; 65 | 66 | if(file.is_open()) 67 | { 68 | while(file.good()) 69 | { 70 | getline(file, line); 71 | output.append(line + "\n"); 72 | } 73 | } 74 | else 75 | { 76 | std::cerr << "Unable to load shader: " << fileName << std::endl; 77 | } 78 | 79 | return output; 80 | } 81 | 82 | void Shader::CheckShaderError(GLuint shader, GLuint flag, bool isProgram, const std::string& errorMessage) 83 | { 84 | GLint success = 0; 85 | GLchar error[1024] = { 0 }; 86 | 87 | if(isProgram) 88 | glGetProgramiv(shader, flag, &success); 89 | else 90 | glGetShaderiv(shader, flag, &success); 91 | 92 | if(success == GL_FALSE) 93 | { 94 | if(isProgram) 95 | glGetProgramInfoLog(shader, sizeof(error), NULL, error); 96 | else 97 | glGetShaderInfoLog(shader, sizeof(error), NULL, error); 98 | 99 | std::cerr << errorMessage << ": '" << error << "'" << std::endl; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /examples/medium/draw/mesh.cpp: -------------------------------------------------------------------------------- 1 | #include "mesh.h" 2 | 3 | Mesh::Mesh(std::vector meshData) 4 | { 5 | int numVerts = meshData.size(); 6 | _drawCount = numVerts/8; 7 | 8 | _model = glm::mat4(); 9 | 10 | glGenVertexArrays(1,&_vao); 11 | glBindVertexArray(_vao); 12 | 13 | glGenBuffers(1,&_vbo); 14 | glBindBuffer(GL_ARRAY_BUFFER,_vbo); 15 | glBufferData(GL_ARRAY_BUFFER,numVerts * sizeof(GLfloat),&meshData.front(),GL_STATIC_DRAW); 16 | 17 | 18 | glEnableVertexAttribArray(0); 19 | glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,6 * sizeof(GL_FLOAT),(GLvoid*)0); 20 | glEnableVertexAttribArray(1); 21 | glVertexAttribPointer(1,3,GL_FLOAT,GL_FALSE,6 * sizeof(GL_FLOAT),(GLvoid*)(3*sizeof(GLfloat))); 22 | 23 | glBindVertexArray(0); 24 | } 25 | 26 | Mesh::~Mesh() 27 | { 28 | glDeleteBuffers(1,&_vbo); 29 | glDeleteVertexArrays(1,&_vao); 30 | } 31 | 32 | void Mesh::Draw(GLuint program) 33 | { 34 | glBindVertexArray(_vao); 35 | 36 | glActiveTexture(GL_TEXTURE0); 37 | glBindTexture(GL_TEXTURE_2D, _texture); 38 | glUniform1i(glGetUniformLocation(program,"tex"),0); 39 | 40 | GLint modelLoc = glGetUniformLocation(program, "model"); 41 | glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(_model)); 42 | 43 | glDrawArrays(GL_TRIANGLES,0,_drawCount); 44 | 45 | glBindVertexArray(0); 46 | } 47 | 48 | void Mesh::addTexture(const char *path){ 49 | 50 | glGenTextures(1,&_texture); 51 | glBindTexture(GL_TEXTURE_2D, _texture); 52 | 53 | // Set the _texture wrapping parametersusing different buffer objects for texture and vertices 54 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // Set _texture wrapping to GL_REPEAT (usually basic wrapping method) 55 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 56 | // Set _texture filtering parameters 57 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 58 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 59 | // Load image, create _texture and generate mipmaps 60 | int width,height; 61 | unsigned char* image = SOIL_load_image(path, &width, &height, 0, SOIL_LOAD_RGB); 62 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image); 63 | glGenerateMipmap(GL_TEXTURE_2D); 64 | 65 | SOIL_free_image_data(image); 66 | glBindTexture(GL_TEXTURE_2D,0); 67 | 68 | glBindVertexArray(_vao); 69 | glEnableVertexAttribArray(2); 70 | glVertexAttribPointer(2,2,GL_FLOAT,GL_FALSE,8 * sizeof(GLfloat),(GLvoid*)(sizeof(GLfloat) * 6)); 71 | glBindVertexArray(0); 72 | } 73 | 74 | void Mesh::Translate(glm::vec3 transVec) 75 | { 76 | _model = glm::translate(_model, transVec); 77 | } 78 | 79 | void Mesh::Rotate(float angle, glm::vec3 axis) 80 | { 81 | _model = glm::rotate(_model, glm::radians(angle), axis); 82 | } 83 | 84 | void Mesh::Scale(glm::vec3 scaleVec) 85 | { 86 | _model = glm::scale(_model, scaleVec); 87 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cook 2 | 3 | A small and fast build system for your C and C++ projects. 4 | 5 | ### Installation 6 | 7 | ```bash 8 | git clone https://github.com/hellozee/cook 9 | cd cook 10 | make 11 | ``` 12 | 13 | 14 | 15 | ### How to use it? 16 | 17 | It is simple just like a we have `Makefile` for make, here we will use a `Recipe` file for doing the same thing. 18 | 19 | #### Syntax: 20 | 21 | Cook is pretty strict on syntax, we have little blocks of what I call entity, there are 2 kinds of entity one is normal entity and another is a special entity for the compiler. Entities have have properties which are called identifiers like the normal entities have `file` and `deps` identifiers. 22 | 23 | - `file ` : Location of the file which this entity is about 24 | - `deps` : Dependencies of the above mentioned file 25 | 26 | On the other hand the special entity for compiler has more than just 2 identifiers, which are `binary` `name` `start` `ldflags` `includes` `others`. 27 | 28 | - `binary` : The compiler binary which will be used to compile the program 29 | - `name` : Name of the generated executable 30 | - `start` : The root entity, or better say the main entity 31 | - `ldflags` : Linker directives, enter them as you would enter them in the terminal 32 | - `includes` : Same as Linker directives but for mentioning special include folders. 33 | - `others` : Some other flags like `-Wall` 34 | 35 | So how do we separate normal entity from the special compiler entity? Simple, there is special name given to this entity which is `#` , it is reserved and hence can't be used for normal entities, also naming an entity is compulsory as it also be used for figuring out the dependencies since the same name would be used to in the `deps` identifier. Linebreaks are used as delimiter but you can use `;` if you want to mention multiple identifiers in a single line. 36 | 37 | ##### Example: 38 | 39 | ``` 40 | entity #{ 41 | binary = g++; 42 | name = GLWindow; 43 | start = main; 44 | ldflags = -lSDL2 -lGLEW -lGL -lSOIL; 45 | includes = ; 46 | others = -Wall -Wextra; 47 | } 48 | 49 | entity main{ 50 | file = main.cpp; 51 | deps = camera display mesh shader; 52 | } 53 | 54 | entity camera{ 55 | file = ui/camera.cpp; 56 | deps = ; 57 | } 58 | 59 | entity display{ 60 | file = ui/display.cpp; 61 | deps = ; 62 | } 63 | 64 | entity mesh{ 65 | file = draw/mesh.cpp; 66 | deps = ; 67 | } 68 | 69 | entity shader{ 70 | file = draw/shader.cpp; 71 | deps = ; 72 | } 73 | ``` 74 | 75 | This is the `Recipe` file I am using for practicing `OpenGL` , you can try it on my OpenGL Practice [repository](https://github.com/hellozee/gl-practice) also this is available in examples folder. 76 | 77 | After creating the `Recipe` file you just execute Cook in the directory containing the `Recipe` file. 78 | 79 | **Note:** This only works for C/C++ 80 | 81 | ### Usage Flags: 82 | 83 | - `--help` : To show this help message 84 | - `--clean` : To clean the cached data 85 | 86 | ### ToDos: 87 | 88 | - Implement `+=` and `-=` operator 89 | - Add an `import` feature to import other Recipes and recursively cook them 90 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at hellozee@disroot.org. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /worker/worker.go: -------------------------------------------------------------------------------- 1 | package worker 2 | 3 | import ( 4 | "bytes" 5 | "io/ioutil" 6 | "os" 7 | "os/exec" 8 | "strings" 9 | 10 | lg "../logger" 11 | mg "../manager" 12 | ps "../parser" 13 | ) 14 | 15 | //Worker Data Structure to hold flags necessary for the worker object 16 | type Worker struct { 17 | Logger *lg.Logger 18 | } 19 | 20 | //CompileFirst Function for compiling the files for the first time 21 | func (wor *Worker) CompileFirst(par ps.Parser, man mg.Manager) error { 22 | //Iteratively generate .o files 23 | 24 | for key, value := range man.FileList { 25 | wor.Logger.ReportSuccess("Compiling " + value) 26 | cmd := exec.Command(par.CompilerDetails.Binary, "-c", value, 27 | "-o", "Cooking/"+key+".o") 28 | err := checkCommand(cmd, wor) 29 | 30 | if err != nil { 31 | wor.Logger.ReportError(err.Error()) 32 | return err 33 | } 34 | } 35 | wor.Logger.ReportSuccess("Successfully Compiled all the files") 36 | return nil 37 | } 38 | 39 | /*CompareAndCompile Function for comparing the hash and the compiling if 40 | the hash did not match */ 41 | func (wor *Worker) CompareAndCompile(par ps.Parser, man *mg.Manager) error { 42 | for key, value := range man.FileList { 43 | 44 | file, err := ioutil.ReadFile(key) 45 | 46 | if err != nil { 47 | wor.Logger.ReportError(err.Error()) 48 | return err 49 | } 50 | 51 | if !mg.CheckHash(file, man.OldFileTimings[value]) { 52 | 53 | wor.Logger.ReportSuccess("Compiling " + value) 54 | cmd := exec.Command(par.CompilerDetails.Binary, "-c", value, 55 | "-o", "Cooking/"+key+".o") 56 | err = checkCommand(cmd, wor) 57 | 58 | if err != nil { 59 | wor.Logger.ReportError(err.Error()) 60 | return err 61 | } 62 | 63 | man.OldFileTimings[value] = mg.HashFile(file) 64 | 65 | } 66 | 67 | man.HashJSONnew.Body.Entity = append(man.HashJSONnew.Body.Entity, 68 | mg.Entity{File: value, Hash: man.OldFileTimings[value]}) 69 | } 70 | wor.Logger.ReportSuccess("Successfully Compiled all the files") 71 | return nil 72 | } 73 | 74 | //Link Function to link the object files generated 75 | func (wor *Worker) Link(par ps.Parser) error { 76 | 77 | //Compile all the generated .o files under the Cooking directory 78 | wor.Logger.ReportSuccess("Linking files") 79 | args := []string{par.CompilerDetails.Binary, "-o", par.CompilerDetails.Name, 80 | par.CompilerDetails.Includes, par.CompilerDetails.OtherFlags, 81 | "Cooking/*.o", par.CompilerDetails.LdFlags} 82 | cmd := exec.Command(os.Getenv("SHELL"), "-c", strings.Join(args, " ")) 83 | err := checkCommand(cmd, wor) 84 | wor.Logger.ReportSuccess("Successfully Linked files") 85 | return err 86 | } 87 | 88 | //checkCommand Function to run a command and report any errors 89 | func checkCommand(cmd *exec.Cmd, wor *Worker) error { 90 | var out bytes.Buffer 91 | var stderr bytes.Buffer 92 | cmd.Stdout = &out 93 | cmd.Stderr = &stderr 94 | err := cmd.Run() 95 | wor.Logger.ReportWarning(out.String()) 96 | wor.Logger.ReportError(stderr.String()) 97 | if err != nil { 98 | wor.Logger.ReportError(err.Error()) 99 | return err 100 | } 101 | wor.Logger.ReportSuccess("Ran Successfully " + strings.Join(cmd.Args, " ")) 102 | return nil 103 | } 104 | 105 | //NewWorker Function to create a new worker 106 | func NewWorker(log *lg.Logger) Worker { 107 | wor := Worker{ 108 | Logger: log, 109 | } 110 | 111 | return wor 112 | } 113 | -------------------------------------------------------------------------------- /examples/medium/mesh/cube.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /* 3 | std::vector defaultCube = { 4 | -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 5 | 0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 6 | 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 7 | 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 8 | -0.5f, 0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 9 | -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 10 | 11 | -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 12 | 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 13 | 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 14 | 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 15 | -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 16 | -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 17 | 18 | -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 19 | -0.5f, 0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 20 | -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 21 | -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 22 | -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 23 | -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 24 | 25 | 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 26 | 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 27 | 0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 28 | 0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 29 | 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 30 | 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 31 | 32 | -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 33 | 0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 34 | 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 35 | 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 36 | -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 37 | -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 38 | 39 | -0.5f, 0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 40 | 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 41 | 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 42 | 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 43 | -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 44 | -0.5f, 0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f 45 | }; 46 | */ 47 | /* Cube with normals */ 48 | 49 | std::vector defaultCube = { 50 | -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 51 | 0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 52 | 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 53 | 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 54 | -0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 55 | -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 56 | 57 | -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 58 | 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 59 | 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 60 | 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 61 | -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 62 | -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 63 | 64 | -0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 65 | -0.5f, 0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 66 | -0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 67 | -0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 68 | -0.5f, -0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 69 | -0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 70 | 71 | 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 72 | 0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 73 | 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 74 | 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 75 | 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 76 | 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 77 | 78 | -0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, 79 | 0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, 80 | 0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, 81 | 0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, 82 | -0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, 83 | -0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, 84 | 85 | -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 86 | 0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 87 | 0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 88 | 0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 89 | -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 90 | -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f 91 | }; -------------------------------------------------------------------------------- /manager/manager.go: -------------------------------------------------------------------------------- 1 | package manager 2 | 3 | import ( 4 | "encoding/json" 5 | "hash/crc32" 6 | "io/ioutil" 7 | "os" 8 | 9 | lg "../logger" 10 | ps "../parser" 11 | ) 12 | 13 | //Entity Data Structure for holding the file name and hash of an entity 14 | type Entity struct { 15 | File string `json:"file"` 16 | Hash uint32 `json:"hash"` 17 | } 18 | 19 | //Parent Data Structure to hold multiple Entity elements 20 | type Parent struct { 21 | Body struct { 22 | Entity []Entity `json:"entity"` 23 | } `json:"body"` 24 | } 25 | 26 | //Manager Data Structure to hold and operate on details.json 27 | type Manager struct { 28 | FileData string 29 | NewFileTimings map[string]uint32 30 | OldFileTimings map[string]uint32 31 | FileList map[string]string 32 | HashJSONold Parent 33 | HashJSONnew Parent 34 | Logger *lg.Logger 35 | } 36 | 37 | //ReadDetails Reading from the details.json file 38 | func (man *Manager) ReadDetails() error { 39 | jsonFile, err := os.Open("Cooking/details.json") 40 | defer jsonFile.Close() 41 | 42 | bytes, _ := ioutil.ReadAll(jsonFile) 43 | err = json.Unmarshal(bytes, &man.HashJSONold) 44 | 45 | if err != nil { 46 | //Someone has tampered with the JSON file 47 | os.Remove("Cooking/details.json") 48 | man.Logger.ReportError(err.Error()) 49 | return err 50 | } 51 | 52 | for _, item := range man.HashJSONold.Body.Entity { 53 | man.OldFileTimings[item.File] = item.Hash 54 | } 55 | man.Logger.ReportSuccess("Successfully read details.json") 56 | return nil 57 | } 58 | 59 | //WriteDetails Writing the new data onto details.json 60 | func (man *Manager) WriteDetails() error { 61 | jsonData, err := json.MarshalIndent(man.HashJSONnew, "", " ") 62 | 63 | if err != nil { 64 | man.Logger.ReportError(err.Error()) 65 | return err 66 | } 67 | 68 | file, err := os.OpenFile("Cooking/details.json", 69 | os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644) 70 | 71 | defer file.Close() 72 | 73 | if err != nil { 74 | man.Logger.ReportError(err.Error()) 75 | return err 76 | } 77 | 78 | _, err = file.Write(jsonData) 79 | 80 | if err != nil { 81 | man.Logger.ReportError(err.Error()) 82 | return err 83 | } 84 | man.Logger.ReportSuccess("Successfully written to details.json") 85 | return nil 86 | } 87 | 88 | //GenerateFileList Generating the files list which we are going to compile 89 | func (man *Manager) GenerateFileList(par ps.Parser, tag string) error { 90 | details := par.FileDetails[tag] 91 | 92 | _, err := os.Stat(details.File) 93 | 94 | if err != nil { 95 | man.Logger.ReportError(err.Error()) 96 | return err 97 | } 98 | 99 | man.FileList[tag] = details.File 100 | 101 | if details.Deps == nil { 102 | return nil 103 | } 104 | 105 | for _, name := range details.Deps { 106 | err = man.GenerateFileList(par, name) 107 | 108 | if err != nil { 109 | man.Logger.ReportError(err.Error()) 110 | return err 111 | } 112 | } 113 | 114 | man.Logger.ReportSuccess("Successfully generated file list") 115 | 116 | return nil 117 | } 118 | 119 | //GenerateList Generate a brand new details.json 120 | func (man *Manager) GenerateList() error { 121 | for _, value := range man.FileList { 122 | file, err := ioutil.ReadFile(value) 123 | if err != nil { 124 | man.Logger.ReportError(err.Error()) 125 | return err 126 | } 127 | hash := HashFile(file) 128 | man.NewFileTimings[value] = hash 129 | man.HashJSONnew.Body.Entity = append(man.HashJSONnew.Body.Entity, 130 | Entity{File: value, Hash: hash}) 131 | } 132 | man.Logger.ReportSuccess("Successfully generated details.json") 133 | return nil 134 | } 135 | 136 | //NewManager Helper function to create a new manager 137 | func NewManager(log *lg.Logger) (Manager, error) { 138 | temp, err := ioutil.ReadFile("Recipe") 139 | 140 | if err != nil { 141 | //Missing Recipe File 142 | log.ReportError(err.Error()) 143 | return Manager{}, err 144 | } 145 | 146 | recipe := string(temp) 147 | 148 | man := Manager{ 149 | FileData: recipe, 150 | NewFileTimings: make(map[string]uint32), 151 | OldFileTimings: make(map[string]uint32), 152 | FileList: make(map[string]string), 153 | Logger: log, 154 | } 155 | man.Logger.ReportSuccess("Successfully created a Manager Object") 156 | return man, nil 157 | } 158 | 159 | //HashFile Obtaining the has of the passed file 160 | func HashFile(file []byte) uint32 { 161 | hash := crc32.ChecksumIEEE(file) 162 | return hash 163 | } 164 | 165 | //CheckHash Comparing hashes of the passed file with the previous hash 166 | func CheckHash(file []byte, hash uint32) bool { 167 | generatedHash := crc32.ChecksumIEEE(file) 168 | return generatedHash == hash 169 | } 170 | -------------------------------------------------------------------------------- /parser/parser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "errors" 5 | "strconv" 6 | "strings" 7 | 8 | lg "../logger" 9 | ) 10 | 11 | //compiler Data Structure to hold the details for the compiler 12 | type compiler struct { 13 | Binary string 14 | Name string 15 | Start string 16 | LdFlags string 17 | Includes string 18 | OtherFlags string 19 | } 20 | 21 | //params Data Structure to hold the details for the file entity 22 | type params struct { 23 | File string 24 | Deps []string 25 | } 26 | 27 | //Parser Data Structure for holding parser details and parsed object 28 | type Parser struct { 29 | input []item 30 | pos int 31 | currentItem item 32 | prevItem item 33 | nextItem item 34 | CompilerDetails compiler 35 | FileDetails map[string]params 36 | Logger *lg.Logger 37 | } 38 | 39 | // next Function to shift to the next item in the list 40 | func (par *Parser) next() item { 41 | par.prevItem = par.currentItem 42 | par.currentItem = par.nextItem 43 | par.pos++ 44 | par.nextItem = par.input[par.pos] 45 | return par.currentItem 46 | } 47 | 48 | // Parse Function to parse the the Recipe File 49 | func (par *Parser) Parse() error { 50 | isCompiler := false 51 | enityName := "" 52 | identifier := itemNULL 53 | params := "" 54 | 55 | for par.nextItem.typ != itemEOF { 56 | par.next() 57 | if par.currentItem.typ == itemEquals && 58 | par.nextItem.typ != itemString && 59 | par.prevItem.typ == itemEntity { 60 | return par.reportError("entity") 61 | } 62 | 63 | if par.currentItem.typ == itemSemicolon { 64 | if par.nextItem.typ < itemKeyWord && 65 | par.nextItem.typ != itemRightBrace { 66 | return par.reportError("}") 67 | } 68 | if isCompiler { 69 | par.fillCompilerDetails(identifier, params) 70 | } else { 71 | par.fillFileDetails(enityName, identifier, params) 72 | } 73 | } 74 | 75 | if par.currentItem.typ == itemLeftBrace && 76 | par.nextItem.typ < itemKeyWord { 77 | return par.reportError("identifier") 78 | } 79 | 80 | if par.currentItem.typ == itemRightBrace && 81 | par.nextItem.typ != itemEOF && 82 | par.nextItem.typ != itemEntity { 83 | return par.reportError("entity") 84 | } 85 | 86 | if par.currentItem.typ == itemString && 87 | par.prevItem.typ == itemEntity { 88 | if par.nextItem.typ != itemLeftBrace { 89 | return par.reportError("{") 90 | } 91 | if par.currentItem.val == "#" { 92 | isCompiler = true 93 | } else { 94 | isCompiler = false 95 | } 96 | enityName = par.currentItem.val 97 | } else if par.currentItem.typ == itemString { 98 | if par.nextItem.typ != itemSemicolon { 99 | return par.reportError(";") 100 | } 101 | params = par.currentItem.val 102 | } 103 | 104 | if par.currentItem.typ == itemEntity { 105 | if par.nextItem.typ != itemString { 106 | return par.reportError("entity name") 107 | } 108 | 109 | if par.currentItem.val == "#" { 110 | isCompiler = true 111 | } else { 112 | isCompiler = false 113 | } 114 | 115 | enityName = par.currentItem.val 116 | } 117 | 118 | if par.currentItem.typ > itemKeyWord { 119 | if par.nextItem.typ != itemEquals { 120 | return par.reportError("=") 121 | } 122 | 123 | identifier = par.currentItem.typ 124 | } 125 | } 126 | par.Logger.ReportSuccess("Successfully parsed Recipe file") 127 | return nil 128 | } 129 | 130 | //reportError Function for reporting syntax errors 131 | func (par *Parser) reportError(expected string) error { 132 | syntaxError := errors.New("Syntax error on line " + strconv.Itoa(par.currentItem.line) + 133 | ": Expected " + expected + " , found " + par.nextItem.val) 134 | par.Logger.ReportError(syntaxError.Error()) 135 | return syntaxError 136 | } 137 | 138 | //fillCompilerDetails Function to store the compiler details 139 | func (par *Parser) fillCompilerDetails(identifier itemType, param string) { 140 | switch { 141 | case identifier == itemBinary: 142 | par.CompilerDetails.Binary = param 143 | case identifier == itemName: 144 | par.CompilerDetails.Name = param 145 | case identifier == itemStart: 146 | par.CompilerDetails.Start = param 147 | case identifier == itemLdFlags: 148 | par.CompilerDetails.LdFlags = param 149 | case identifier == itemIncludes: 150 | par.CompilerDetails.Includes = param 151 | case identifier == itemOthers: 152 | par.CompilerDetails.OtherFlags = param 153 | } 154 | } 155 | 156 | //fillFileDetails Function to fill the file details 157 | func (par *Parser) fillFileDetails(name string, identifier itemType, param string) { 158 | var temp params 159 | 160 | if identifier == itemFile { 161 | temp.File = param 162 | } else if param != "" { 163 | temp = par.FileDetails[name] 164 | } 165 | 166 | if param == "" { 167 | return 168 | } 169 | 170 | if identifier == itemDeps { 171 | paramArray := strings.Split(param, " ") 172 | temp.Deps = paramArray 173 | } 174 | 175 | par.FileDetails[name] = temp 176 | } 177 | 178 | //NewParser Function to help create a parser 179 | func NewParser(file string, log *lg.Logger) Parser { 180 | lex := newLexer(file) 181 | lex.analyze() 182 | par := Parser{ 183 | input: lex.items, 184 | pos: 0, 185 | nextItem: lex.items[0], 186 | FileDetails: make(map[string]params), 187 | Logger: log, 188 | } 189 | return par 190 | } 191 | -------------------------------------------------------------------------------- /parser/lexer.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "strings" 5 | "unicode/utf8" 6 | ) 7 | 8 | //item Data Structure for holding a single item 9 | type item struct { 10 | typ itemType 11 | pos int 12 | val string 13 | line int 14 | } 15 | 16 | //itemType Substituting int with itemType for better readability 17 | type itemType int 18 | 19 | //itemEnum Enum for holding the various item types 20 | const ( 21 | // Literal terminator symbols 22 | itemEOF itemType = iota 23 | itemNULL 24 | itemEquals 25 | itemSemicolon 26 | itemLeftBrace 27 | itemRightBrace 28 | itemString 29 | itemEntity 30 | itemlineBreak 31 | itemKeyWord 32 | itemBinary 33 | itemName 34 | itemStart 35 | itemLdFlags 36 | itemIncludes 37 | itemOthers 38 | itemFile 39 | itemDeps 40 | ) 41 | 42 | //eof Constant for determining the end of file 43 | const eof = -1 44 | 45 | //key Map for holding various keywords with respect to item enum 46 | var key = map[string]itemType{ 47 | "entity": itemEntity, 48 | "binary": itemBinary, 49 | "name": itemName, 50 | "start": itemStart, 51 | "ldflags": itemLdFlags, 52 | "includes": itemIncludes, 53 | "others": itemOthers, 54 | "file": itemFile, 55 | "deps": itemDeps, 56 | } 57 | 58 | //lexer Data Structure for holding the Lexer 59 | type lexer struct { 60 | input string 61 | pos int 62 | start int 63 | width int 64 | items []item 65 | line int 66 | } 67 | 68 | //analyze Function to perform lexical analysis on the stream 69 | func (lex *lexer) analyze() { 70 | for lex.peek() != eof { 71 | lex.next() 72 | lex.isKeyword() 73 | if lex.peek() == eof { 74 | break 75 | } 76 | lex.isDelimiter() 77 | } 78 | 79 | lex.items = append(lex.items, item{typ: itemEOF, pos: lex.pos + 1, 80 | val: "EOF", line: lex.line}) 81 | } 82 | 83 | //next Function to shift the next rune in the stream 84 | func (lex *lexer) next() rune { 85 | if lex.pos >= len(lex.input) { 86 | return eof 87 | } 88 | 89 | nextRune, runeWidth := utf8.DecodeRuneInString(lex.input[lex.pos:]) 90 | lex.width = runeWidth 91 | lex.pos += lex.width 92 | 93 | if isWhiteSpace(nextRune) { 94 | return lex.next() 95 | } 96 | 97 | if nextRune == '\n' { 98 | lex.line++ 99 | } 100 | return nextRune 101 | } 102 | 103 | //peek Function to check the next rune while mainting the current position 104 | func (lex *lexer) peek() rune { 105 | nextRune := lex.next() 106 | lex.backup() 107 | return nextRune 108 | } 109 | 110 | //backup Function to back one rune from the current position of the Lexer 111 | func (lex *lexer) backup() { 112 | lex.pos -= lex.width 113 | 114 | if lex.width == 1 && lex.input[lex.pos] == '\n' { 115 | lex.line-- 116 | } 117 | } 118 | 119 | /*isKeyword Function to to determine whether the given character or 120 | the stream of characters is a keyword or not, if yes then 121 | the appropriate item is pushed into the lexer data structure */ 122 | func (lex *lexer) isKeyword() { 123 | value := strings.TrimSpace(lex.input[lex.start:lex.pos]) 124 | 125 | if typeOf, ok := key[value]; ok { 126 | tempItem := item{ 127 | typ: typeOf, 128 | pos: lex.start, 129 | val: value, 130 | line: lex.line, 131 | } 132 | 133 | lex.items = append(lex.items, tempItem) 134 | lex.start = lex.pos 135 | } 136 | } 137 | 138 | /*isDelimiter Function to to determine whether the given character or 139 | the stream of characters is a delimiter or not, if yes then 140 | the appropriate item is pushed into the lexer data structure */ 141 | func (lex *lexer) isDelimiter() { 142 | switch lex.input[lex.pos] { 143 | case '{': 144 | tempItem := item{ 145 | typ: itemString, 146 | pos: lex.start, 147 | val: strings.TrimSpace(lex.input[lex.start:lex.pos]), 148 | line: lex.line, 149 | } 150 | lex.items = append(lex.items, tempItem) 151 | 152 | tempItem = item{ 153 | typ: itemLeftBrace, 154 | pos: lex.pos, 155 | val: "{", 156 | line: lex.line, 157 | } 158 | lex.items = append(lex.items, tempItem) 159 | 160 | lex.start = lex.pos + 1 161 | 162 | case '}': 163 | tempItem := item{ 164 | typ: itemRightBrace, 165 | pos: lex.pos, 166 | val: "}", 167 | line: lex.line, 168 | } 169 | lex.items = append(lex.items, tempItem) 170 | 171 | lex.start = lex.pos + 1 172 | 173 | case '\n': 174 | if lex.items[len(lex.items)-1].typ == itemEquals { 175 | tempItem := item{ 176 | typ: itemString, 177 | pos: lex.start, 178 | val: strings.TrimSpace(lex.input[lex.start:lex.pos]), 179 | line: lex.line, 180 | } 181 | lex.items = append(lex.items, tempItem) 182 | 183 | tempItem = item{ 184 | typ: itemSemicolon, 185 | pos: lex.pos, 186 | val: ";", 187 | line: lex.line, 188 | } 189 | lex.items = append(lex.items, tempItem) 190 | lex.start = lex.pos + 1 191 | } 192 | case ';': 193 | tempItem := item{ 194 | typ: itemString, 195 | pos: lex.start, 196 | val: strings.TrimSpace(lex.input[lex.start:lex.pos]), 197 | line: lex.line, 198 | } 199 | lex.items = append(lex.items, tempItem) 200 | 201 | tempItem = item{ 202 | typ: itemSemicolon, 203 | pos: lex.pos, 204 | val: ";", 205 | line: lex.line, 206 | } 207 | lex.items = append(lex.items, tempItem) 208 | lex.start = lex.pos + 1 209 | 210 | case '=': 211 | if lex.items[len(lex.items)-1].typ != itemEquals { 212 | tempItem := item{ 213 | typ: itemEquals, 214 | pos: lex.pos, 215 | val: "=", 216 | line: lex.line, 217 | } 218 | lex.items = append(lex.items, tempItem) 219 | lex.start = lex.pos + 1 220 | } 221 | } 222 | } 223 | 224 | //newLexer Function to create a new Lexer 225 | func newLexer(file string) *lexer { 226 | lex := lexer{ 227 | input: file, 228 | pos: 0, 229 | start: 0, 230 | width: len(file), 231 | line: 0, 232 | } 233 | 234 | return &lex 235 | } 236 | 237 | //isWhiteSpace Function to determine if the give character is a white space or not 238 | func isWhiteSpace(currentRune rune) bool { 239 | return currentRune == ' ' || currentRune == '\t' || currentRune == '\r' 240 | } 241 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | Cook 294 | Copyright (C) 2018 Kuntal Majumder 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------