synchronzie laptop and pc

This commit is contained in:
Krzysztof Rudnicki 2022-09-07 18:34:50 +02:00
parent 1860ab5848
commit 0f293adb96
4 changed files with 33 additions and 28 deletions

View File

@ -8,54 +8,57 @@
#include "constants.hpp"
#include "misc.hpp"
void configureGLFW(const int GLFWMajorVersion, const int GLFWMinorVersion) {
void configureGLFW(const int GLFWMajorVersion, const int GLFWMinorVersion)
{
// first argument tells us what option to configure
// second is to what we set the value of this option
// see: https://www.glfw.org/docs/latest/window.html#window_hints
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, GLFWMajorVersion);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, GLFWMinorVersion);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// we set GLFW to 3.3 CORE
// core profile gives us access to smaller subset of OGL without backwards compatible features
// we set GLFW to 3.3 CORE
// core profile gives us access to smaller subset of OGL without backwards compatible features
// if we are on Mac OS X we need this for our code to work
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
// if we are on Mac OS X we need this for our code to work
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
}
void instantiateGLFWwindow() {
void instantiateGLFWwindow()
{
// Initialize GLFW
glfwInit();
configureGLFW(constants::GLFW_MAJOR_VERSION, constants::GLFW_MINOR_VERSION);
}
const GLFWwindow* createWindowObject() {
// First two arguments are width and height
GLFWwindow *createWindowObject()
{
// First two arguments are width and height
// Third is the name of the window
// We ignore last two
const GLFWwindow* window = glfwCreateWindow(constants::MAIN_WINDOW_WIDTH, constants::MAIN_WINDOW_HEIGHT, constants::MAIN_WINDOW_NAME, NULL, NULL);
GLFWwindow *window = glfwCreateWindow(constants::MAIN_WINDOW_WIDTH, constants::MAIN_WINDOW_HEIGHT, constants::MAIN_WINDOW_NAME, NULL, NULL);
return window;
}
int initializeGLAD()
int initializeGLAD()
{
// we load address of OGL OS-specific function pointers
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
print("Failed to initialize GLAD");
return -1;
}
}
return 0;
}
// resizes viewport when user resizes window
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
void framebuffer_size_callback(GLFWwindow *window, int width, int height)
{
glViewport(0, 0, width, height);
}
}
void viewPort(GLFWwindow* window)
void viewPort(GLFWwindow *window)
{
// We tell OGL size of rendering window
// First two define left corner of window
@ -64,17 +67,17 @@ void viewPort(GLFWwindow* window)
glViewport(0, 0, constants::MAIN_WINDOW_WIDTH, constants::MAIN_WINDOW_HEIGHT);
// processed coordinates are between -1 and 1 so here we map:
// (-1 to 1) to (0, constants::MAIN_WINDOW_WIDTH) and (0, constants::MAIN_WINDOW_HEIGHT)
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
// we call framebuffer_size_callback on every window resize
}
GLFWwindow* prepareForRender()
GLFWwindow *prepareForRender()
{
instantiateGLFWwindow();
GLFWwindow* window = createWindowObject();
GLFWwindow *window = createWindowObject();
// function returns GLFWWindow object
if (window == NULL)
{
print("Failed to create GLFW window");
@ -83,8 +86,9 @@ GLFWwindow* prepareForRender()
}
// we make context of this window main context of current thread
glfwMakeContextCurrent(window);
if(initializeGLAD() == -1) return NULL;
if (initializeGLAD() == -1)
return NULL;
viewPort(window);
return window;
}

View File

@ -4,10 +4,10 @@
void configureGLFW(const int GLFWMajorVersion, const int GLFWMinorVersion);
void instantiateGLFWwindow();
const GLFWwindow* createWindowObject();
GLFWwindow *createWindowObject();
int initializeGLAD();
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void viewPort(GLFWwindow* window);
GLFWwindow* prepareForRender();
void framebuffer_size_callback(GLFWwindow *window, int width, int height);
void viewPort(GLFWwindow *window);
GLFWwindow *prepareForRender();
#endif

Binary file not shown.

View File

@ -16,8 +16,9 @@
int main()
{
// changed in glfwWindowShouldClose
GLFWwindow* window = prepareForRender();
if(window == NULL) return -1;
GLFWwindow *window = prepareForRender();
if (window == NULL)
return -1;
renderLoop(window);
// clean GLFW resources