diff --git a/src/fixedfunction.cc b/src/fixedfunction.cc new file mode 100644 index 0000000..42b3ac9 --- /dev/null +++ b/src/fixedfunction.cc @@ -0,0 +1,60 @@ +#include +#include +#include +void triangle() { + glClearColor(1.0f, 1.0f, 0.0f, 0.0f); + + glClear(GL_COLOR_BUFFER_BIT); + + glBegin(GL_TRIANGLES); + glColor3f(1.0f, 0.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, 0.0f); + + glColor3f(0.0f, 1.0f, 0.0f); + glVertex3f(0.0f, 1.0f, 0.0f); + + glColor3f(0.0f, 0.0f, 1.0f); + glVertex3f(1.0f, -1.0f, 0.0f); + glEnd(); +} + + +void framebuffer_size_callback(GLFWwindow* window, int width, int height) { + glViewport(0,0, width, height); +} + +int main() { + glfwInit(); + + // Set OpenGL version to 1.2. + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); + + // Create a GLFW window. + GLFWwindow* window = glfwCreateWindow(800, 600, "Fixed Function OpenGL 1.2", nullptr, nullptr); + + // Fail if the window has failed to create. + if (window == nullptr) { + const char* description; + glfwGetError(&description); + std::cout << "Failed to create GLFW window.\n" << description << std::endl; + return -1; + } + + glfwMakeContextCurrent(window); + + glMatrixMode(GL_PROJECTION); + glViewport(0,0, 800, 600); + + glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); + + while (!glfwWindowShouldClose(window)) { + triangle(); + + glfwSwapBuffers(window); + glfwPollEvents(); + } + + glfwTerminate(); + return 0; +} diff --git a/src/meson.build b/src/meson.build index a50a53d..0058d3a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -2,4 +2,5 @@ sources = [ 'main.cc' ] -exe = executable('main', sources, dependencies: [glfw, libepoxy]) +executable('main', sources, dependencies: [glfw, libepoxy]) +executable('fixedfunction', ['fixedfunction.cc'], dependencies: [glfw, libepoxy])