#include #include #include #include #include "../include/RenderBackend/OpenGL/VertexShader.hpp" #include "../include/RenderBackend/OpenGL/PixelShader.hpp" #include "../include/RenderBackend/OpenGL/DeviceMemory.hpp" using namespace amalgine; using namespace std; int main() { if(!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); return -1; } glfwWindowHint(GLFW_SAMPLES, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); GLFWwindow *window = glfwCreateWindow(1920, 1080, "Amalgine", nullptr, nullptr); if(!window) { fprintf(stderr, "Failed to open GLFW window\n"); glfwTerminate(); return -1; } glfwMakeContextCurrent(window); glewExperimental = true; if(glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initialize GLEW\n"); glfwTerminate(); return -1; } glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); f32 verticesRaw[] = { 0.0f, 0.5f, 0.5f, -0.5f, -0.5f, -0.5f }; DataView vertices(verticesRaw, 6); DeviceMemory triangle; triangle.copyStatic(vertices); VertexShader vertexShader; ShaderInputVec2 inputPosition = vertexShader.defineInputVec2("position"); vertexShader.defineMain([&inputPosition]() { return ShaderVec4(inputPosition, 0.0f, 1.0f); }); PixelShader pixelShader; ShaderOutputVec4 outColor = pixelShader.defineOutputVec4("outColor"); pixelShader.defineMain([&outColor]() { outColor = ShaderVec4(1.0f, 1.0f, 1.0f, 1.0f); }); string vertexShaderSource = vertexShader.build(); printf("Vertex shader source:\n%s", vertexShaderSource.c_str()); string pixelShaderSource = pixelShader.build(); printf("Pixel shader source:\n%s", pixelShaderSource.c_str()); while(!glfwWindowShouldClose(window)) { if(glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS) glfwSetWindowShouldClose(window, GL_TRUE); glfwSwapBuffers(window); glfwPollEvents(); } return 0; }