Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define GLEW_STATIC
- #include <GL/glew.h>
- #include <windows.h>
- #include <GLFW/glfw3.h>
- #include "stellarEngine.h"
- Engine::Engine(int width, int height, std::string title_bar_text, bool fullscreen, bool resizable, int vm, int vn, GLuint prof, GLuint forcom)
- {
- //variable assigning
- std::cout << "Starting OpenStellar Engine! Please wait while it initializes!" << std::endl;
- std::cout << "Assigning Variables!" << std::endl;
- if (resizable)
- {
- resizable = GL_TRUE;
- }
- else
- {
- resizable = GL_FALSE;
- }
- screenTitleBarText = title_bar_text;
- if (fullscreen == true)
- {
- screenFullscreen = glfwGetPrimaryMonitor();
- }
- else
- {
- screenFullscreen = nullptr;
- }
- major = vm;
- minor = vn;
- profile = prof;
- forwardCompat = forcom;
- screenWidth = width;
- screenHeight = height;
- if (!GLFWinitialize())
- {
- std::cout << "ERROR_CODE::0::ERROR::GLFW - GLFW failed to initialize!" << std::endl;
- }
- std::cout << "Creating game window!" << std::endl;
- const char * titleText = screenTitleBarText.c_str();
- window = glfwCreateWindow(screenWidth, screenHeight, titleText, nullptr, nullptr);
- if (window == nullptr)
- {
- std::cout << "ERROR_CODE::1::ERROR::GLFW - GLFW failed window creation!" << std::endl;
- glfwTerminate();
- }
- glfwMakeContextCurrent(window);
- std::cout << "Setting up GLEW!" << std::endl;
- glewExperimental = GL_TRUE;
- if (glewInit() != GLEW_OK)
- {
- std::cout << "ERROR_CODE::2::ERROR::GLEW - Glew failed to initialize!" << std::endl;
- }
- int wid, hei;
- glfwGetFramebufferSize(window, &wid, &hei);
- glViewport(0, 0, wid, hei);
- }
- bool Engine::GLFWinitialize()
- {
- std::cout << "Setting up GLFW!" << std::endl;
- if (!glfwInit())
- {
- return false;
- }
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, major);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minor);
- glfwWindowHint(GLFW_OPENGL_PROFILE, profile);
- glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, forwardCompat);
- glfwWindowHint(GLFW_RESIZABLE, resizable);
- return true;
- }
- void Engine::RunGameLoop()
- {
- std::cout << "Starting game loop!" << std::endl;
- while (!glfwWindowShouldClose(this->window))
- {
- glfwSwapBuffers(this->window);
- glfwPollEvents();
- }
- std::cout << "Game loop stopped!" << std::endl;
- }
- void Engine::Stop()
- {
- std::cout << "Stopping game loop!" << std::endl;
- glfwSetWindowShouldClose(this->window, GL_TRUE);
- }
- void Engine::CleanUp()
- {
- std::cout << "Cleaning Up!" << std::endl;
- glfwTerminate();
- }
- GLFWwindow* Engine::getWindow()
- {
- return window;
- }
- bool Engine::windowShouldClose()
- {
- return glfwWindowShouldClose(window);
- }
- std::string Engine::getPath() {
- char buffer[MAX_PATH];
- GetModuleFileName(NULL, buffer, MAX_PATH);
- std::string::size_type pos = std::string(buffer).find_last_of("\\/");
- return std::string(buffer).substr(0, pos);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement