Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Set `$PROJECT_DIR` as project directory
- 2. Download [GLFW Source package](https://github.com/glfw/glfw/releases/download/3.3.8/glfw-3.3.8.zip)
- 3. Extract `glfw-3.3.8.zip` folder to `$PROJECT_DIR`
- 4. `mkdir -p $PROJECT_DIR/glfw-3.3.8/build`
- 5. `cd $PROJECT_DIR/glfw-3.3.8/build`
- 6. `cmake ..`
- 7. `cmake --build .`
- 8. `mkdir -p $PROJECT_DIR/References/Include`
- 9. `mkdir -p $PROJECT_DIR/References/Libs`
- 10. `ln -s src/libglfw3.a $PROJECT_DIR/References/Libs/`
- 11. `ln -s ../include/GLFW $PROJECT_DIR/References/Include/`
- 12. `cd $PROJECT_DIR`
- 13. `mkdir -p GLAD`
- 14. Generate [GLAD](https://glad.dav1d.de/#language=c&specification=gl&api=gl%3D3.3&api=gles1%3Dnone&api=gles2%3Dnone&api=glsc2%3Dnone&profile=core&loader=on) and download `glad.zip`
- 15. Extract `glad.zip` to `$PROJECT_DIR/GLAD/`
- 16. `ln -s GLAD/include/glad References/Include/`
- 17. `ln -s GLAD/include/KHR References/Include/`
- 18. `mkdir -p HelloWindow/src/`
- 19. `cp GLAD/src/glac.c HelloWindow/src/`
- ```CMake
- # $PROJECT_DIR/HelloWindow/CMakeLists.txt
- cmake_minimum_required(VERSION 3.0)
- project(HelloWindow)
- file(GLOB_RECURSE sources src/*.c src/*.cpp src/*.h src/*.hpp)
- add_executable(HelloWindow ${sources})
- target_include_directories(HelloWindow PRIVATE ${CMAKE_SOURCE_DIR}/../References/Include)
- target_link_libraries(HelloWindow
- ${CMAKE_SOURCE_DIR}/../References/Libs/libglfw3.a
- GL
- X11
- pthread
- Xrandr
- Xi
- dl
- )
- ```
- ```cpp
- // $PROJECT_DIR/HelloWindow/src/main.cpp
- #include <glad/glad.h>
- #include <GLFW/glfw3.h>
- #include <iostream>
- void framebuffer_size_callback(GLFWwindow *window, int width, int height)
- {
- glViewport(0, 0, width, height);
- }
- void processInput(GLFWwindow *window)
- {
- if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
- glfwSetWindowShouldClose(window, true);
- }
- int main()
- {
- glfwInit();
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- // glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
- GLFWwindow *window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
- if (window == NULL)
- {
- std::cout << "Failed to create GLFW window" << std::endl;
- glfwTerminate();
- return -1;
- }
- glfwMakeContextCurrent(window);
- if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
- {
- std::cout << "Failed to initialize GLAD" << std::endl;
- return -1;
- }
- glViewport(0, 0, 800, 600);
- glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
- while (!glfwWindowShouldClose(window))
- {
- processInput(window);
- glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
- glfwSwapBuffers(window);
- glfwPollEvents();
- }
- glfwTerminate();
- return 0;
- }
- ```
- 20. `mkdir -p HelloWindow/build`
- 21. `cd HelloWindow/build`
- 22. `cmake .. && cmake --build .`
- 23. `./HelloWindow`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement