graphics submodule
This commit is contained in:
parent
aafd64137f
commit
72740547d1
|
@ -36,14 +36,13 @@ find_package(Boost 1.56 REQUIRED COMPONENTS
|
||||||
set(EXE_1_NAME loader)
|
set(EXE_1_NAME loader)
|
||||||
file(
|
file(
|
||||||
GLOB EXE_1_SOURCES
|
GLOB EXE_1_SOURCES
|
||||||
src/main.cpp
|
src/*.cpp
|
||||||
include/glad/glad.h
|
|
||||||
)
|
)
|
||||||
set(CMAKE_BINARY_DIR "bin")
|
set(CMAKE_BINARY_DIR "bin")
|
||||||
|
|
||||||
add_executable(${EXE_1_NAME} ${EXE_1_SOURCES} ${PROJECT_HEADERS}
|
add_executable(${EXE_1_NAME} ${EXE_1_SOURCES} ${PROJECT_HEADERS}
|
||||||
${PROJECT_SHADERS} ${VENDORS_SOURCES})
|
${PROJECT_SHADERS} ${VENDORS_SOURCES})
|
||||||
target_link_libraries(${EXE_1_NAME} glfw ${GLAD_LIBRARIES} Boost::program_options)
|
target_link_libraries(${EXE_1_NAME} glfw Boost::program_options)
|
||||||
target_include_directories(${EXE_1_NAME} PRIVATE include)
|
target_include_directories(${EXE_1_NAME} PRIVATE include)
|
||||||
set_target_properties(${EXE_1_NAME} PROPERTIES
|
set_target_properties(${EXE_1_NAME} PROPERTIES
|
||||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${EXE_1_NAME})
|
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${EXE_1_NAME})
|
||||||
|
|
4
build.sh
4
build.sh
|
@ -3,4 +3,6 @@ set -e
|
||||||
flags="-DGLFW_USE_WAYLAND=ON" # compile glfw for wayland instead of X11
|
flags="-DGLFW_USE_WAYLAND=ON" # compile glfw for wayland instead of X11
|
||||||
cmake $flags .
|
cmake $flags .
|
||||||
cmake --build .
|
cmake --build .
|
||||||
./bin/loader/loader
|
echo -e "running the program, passing the given args"
|
||||||
|
echo -e "========================================"
|
||||||
|
./run.sh $@
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
#include <glad/glad.c>
|
||||||
|
// glad must be loaded before GLFW
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
#include "graphics.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
void processInput(GLFWwindow *window) {
|
||||||
|
// if user presses ESC, close the window
|
||||||
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||||
|
glfwSetWindowShouldClose(window, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void framebuffer_size_callback(GLFWwindow *window, int width, int height) {
|
||||||
|
glViewport(0, 0, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
int mainWindow() {
|
||||||
|
/* graphics stuff */
|
||||||
|
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, "Shader Loader", NULL, NULL);
|
||||||
|
if (window == NULL) {
|
||||||
|
printf("Failed to create GLFW window\n");
|
||||||
|
glfwTerminate();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
|
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||||
|
printf("Failed to initialize GLAD\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
|
||||||
|
float vertices[] = {-0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f, 0.0f, 0.5f, 0.0f};
|
||||||
|
|
||||||
|
unsigned int VBO;
|
||||||
|
|
||||||
|
glGenBuffers(1, &VBO);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
while (!glfwWindowShouldClose(window)) {
|
||||||
|
processInput(window);
|
||||||
|
|
||||||
|
glClearColor(0.8f, 0.4f, 0.1f, 1.0f);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
glfwSwapBuffers(window);
|
||||||
|
glfwPollEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
glfwTerminate();
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
int mainWindow();
|
73
src/main.cpp
73
src/main.cpp
|
@ -1,65 +1,40 @@
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
#include <glad/glad.c>
|
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <unistd.h>
|
|
||||||
|
#include "graphics.hpp"
|
||||||
|
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
void framebuffer_size_callback(GLFWwindow *window, int width, int height);
|
|
||||||
void processInput(GLFWwindow *window);
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
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, "Shader Loader", NULL, NULL);
|
printf("argc:\t\t%d\n", argc);
|
||||||
if (window == NULL) {
|
for (int i = 0; i < argc; i++) {
|
||||||
printf("Failed to create GLFW window\n");
|
printf("argv[%d]:\t%s\n", i, argv[i]);
|
||||||
glfwTerminate();
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
glfwMakeContextCurrent(window);
|
std::cout << std::endl;
|
||||||
|
|
||||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
po::options_description desc("Allowed options");
|
||||||
printf("Failed to initialize GLAD\n");
|
desc.add_options()("help", "produce help message")(
|
||||||
return -1;
|
"compression", po::value<int>(), "set compression level");
|
||||||
|
|
||||||
|
po::variables_map vm;
|
||||||
|
/* po::store(po::parse_command_line(ac, av, desc), vm); */
|
||||||
|
po::notify(vm);
|
||||||
|
|
||||||
|
if (vm.count("help")) {
|
||||||
|
std::cout << desc << "\n";
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
if (vm.count("compression")) {
|
||||||
|
std::cout << "Compression level was set to " << vm["compression"].as<int>()
|
||||||
float vertices[] = {-0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f, 0.0f, 0.5f, 0.0f};
|
<< ".\n";
|
||||||
|
} else {
|
||||||
unsigned int VBO;
|
std::cout << "Compression level was not set.\n";
|
||||||
|
|
||||||
glGenBuffers(1, &VBO);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(window)) {
|
|
||||||
processInput(window);
|
|
||||||
|
|
||||||
glClearColor(0.8f, 0.4f, 0.1f, 1.0f);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
|
||||||
glfwPollEvents();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwTerminate();
|
int result = mainWindow();
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void processInput(GLFWwindow *window) {
|
return result;
|
||||||
// if user presses ESC, close the window
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
|
||||||
glfwSetWindowShouldClose(window, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void framebuffer_size_callback(GLFWwindow *window, int width, int height) {
|
|
||||||
glViewport(0, 0, width, height);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue