Esempio n. 1
0
void Application::init(const unsigned int& width, const unsigned int& height, HGLRC mainWindowContext) {

    m_width = width; m_height = height;

    glfwSetErrorCallback(error_callback);
    if (!glfwInit())
        exit(EXIT_FAILURE);

    m_window = glfwCreateWindow(width, height, "Simple GL App", NULL, NULL);
    if (!m_window)
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    glfwMakeContextCurrent(m_window);

	HGLRC currWindowContext = glfwGetWGLContext(m_window);
	wglShareLists(mainWindowContext, currWindowContext);

    glfwSetKeyCallback(m_window, key_callback);
    glfwSetWindowSizeCallback(m_window, WindowSizeCB);
    glfwSetCursorPosCallback(m_window, EventMousePos);
    glfwSetScrollCallback(m_window, EventMouseWheel);
    glfwSetMouseButtonCallback(m_window, (GLFWmousebuttonfun)EventMouseButton);
    glfwSetKeyCallback(m_window, (GLFWkeyfun)EventKey);

    // - Directly redirect GLFW char events to AntTweakBar
    glfwSetCharCallback(m_window, (GLFWcharfun)EventChar);

    if (glewInit() != GLEW_OK){
        std::cout << "cannot intialize the glew.\n";
        exit(EXIT_FAILURE);
    }

    init();

    GLenum e = glGetError();
    //glEnable(GL_DEPTH);
    e = glGetError();
    glEnable(GL_DEPTH_TEST);
    e = glGetError();
}
void OpenGLWindow::Init()
{
	// OpenGL
	//auto surface = new QOffscreenSurface();
	//surface->setFormat(format);
	//surface->create();
	//setSwapInterval

	QSurfaceFormat format;
	format.setVersion(4, 0);
	format.setSwapInterval(0);
	format.setProfile(QSurfaceFormat::CoreProfile);
	setFormat(format);

	auto glfwCTX = glfwGetWGLContext(Engine::Window->window);
	auto window = glfwGetWin32Window(Engine::Window->window);

	auto newNative = new QWGLNativeContext(glfwCTX, window);
	QOpenGLContext* qtctx = new QOpenGLContext();
	//qtctx->setFormat(format);
	qtctx->setNativeHandle(QVariant::fromValue<QWGLNativeContext>(*newNative));
	bool created = qtctx->create();
	bool value = qtctx->makeCurrent(this);

	// Test
	auto nativeHandle = qtctx->nativeHandle();
	auto windowsNative = nativeHandle.value<QWGLNativeContext>();

	// Share context
	qtGLContext = new QOpenGLContext(this);
	//qtGLContext->setFormat(format);
	qtGLContext->setShareContext(qtctx);
	bool success = qtGLContext->create();

	nativeHandle = qtGLContext->nativeHandle();
	windowsNative = nativeHandle.value<QWGLNativeContext>();

	bool sharing = qtGLContext->areSharing(qtctx, qtGLContext);
	bool sharing2 = qtGLContext->shareContext();
}
Esempio n. 3
0
HGLRC window::get_native_context()
{
   return glfwGetWGLContext((GLFWwindow*)m_window);
}