1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#include <engine.h>
#include <scene.h>
#include <window.h>
#include "TestSDKHelpers.h"
#include <GLFW/glfw3.h>
#include <iostream>
int TestSDKExternalWindowGLFW(int argc, char* argv[])
{
// setup glfw window
if (!glfwInit())
{
std::cerr << "Can't initialize GLFW." << std::endl;
return EXIT_FAILURE;
}
glfwSetErrorCallback([](int error, const char* desc) {
std::cerr << "GLFW error " << error << ": " << desc << std::endl;
});
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(300, 300, "F3D GLFW External Window", nullptr, nullptr);
if (!window)
{
std::cerr << "Can't create GLFW window." << std::endl;
return EXIT_FAILURE;
}
glfwMakeContextCurrent(window);
f3d::engine eng = f3d::engine::createExternal(glfwGetProcAddress);
eng.getWindow().setSize(300, 300);
// key callback
glfwSetKeyCallback(window, [](GLFWwindow* window, int key, int scancode, int action, int mods) {
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
{
glfwSetWindowShouldClose(window, 1);
}
});
eng.getScene().add(std::string(argv[1]) + "/data/cow.vtp");
while (!glfwWindowShouldClose(window) && glfwGetTime() < 1.0)
{
eng.getWindow().render();
glfwSwapBuffers(window);
glfwPollEvents();
}
// Ideally, we should not test the content of the window, but the GLFW framebuffer itself
// There is currently no API in GLFW that allows to do that unfortunately
if (!TestSDKHelpers::RenderTest(
eng.getWindow(), std::string(argv[1]) + "baselines/", argv[2], "TestSDKExternalWindowGLFW"))
{
return EXIT_FAILURE;
}
glfwTerminate();
return EXIT_SUCCESS;
}
|