#ifndef GLAD #define GLAD #include #endif #include #include #include #include #include #include #include #include #include #include "shader.hpp" #include "game.hpp" #include "texture.hpp" #include "mainMenu.hpp" #include "text.hpp" //Is called when the window is resized void framebuffer_resize(GLFWwindow* win, int width, int height){ glViewport(0,0,width,height); } const char* vsFileName = "shaders/vertex_shader.glsl"; const char* fsFileName = "shaders/fragment_shader.glsl"; unsigned int Text::texture; Shader Text::shader; int main(){ //OpenGL stuff glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); #ifdef __APPLE__ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); #endif GLFWwindow* win = glfwCreateWindow(640,320,"Minicraft",NULL,NULL); if(win==NULL){ std::cerr << "Error while creating window" << std::endl; glfwTerminate(); return -1; } glfwMakeContextCurrent(win); if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { std::cerr << "Error while initialising GLAD" << std::endl; return -1; } //When the window is resized it calls framebuffer_resize glfwSetFramebufferSizeCallback(win,framebuffer_resize); //Makes sure that things that are closer are drawn on top //of things that are further glEnable(GL_DEPTH_TEST); //Makes sure see-through textures are see-through glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); unsigned int VBO, VAO, EBO; unsigned int shaderProgram; Text::initFont(); Button b = Button("Create World", 0, -0.5,0.5,0.25); Control* control = new mainMenu(win); //Main loop while(!glfwWindowShouldClose(win)){ Control* newControl = control->handle(win); if(newControl){ control->shutdown(); delete control; control =newControl; } int width,height; glfwGetWindowSize(win,&width,&height); float screenRatio = (float)height/(float)width; //Clear the screen glClearColor(0.0,0.0,1.0f,1.0f/*blue*/); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); control->draw(screenRatio); glfwSwapBuffers(win); glfwPollEvents(); } control->shutdown(); //delete control; glfwTerminate(); return 0; }