# Share a texture across multiple windows

**URL:** <https://discourse.libcinder.org/t/share-a-texture-across-multiple-windows/953>\
**Category:** Using Cinder\
**Created:** [November 15, 2017, 11:40pm UTC](https://discourse.libcinder.org/t/share-a-texture-across-multiple-windows/953 "2017-11-15T23:40:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vincent\_rioux](https://avatars.discourse-cdn.com/v4/letter/v/bc79bd/32.png) [@vincent\_rioux](https://discourse.libcinder.org/u/vincent_rioux)\
**Post date:** [November 15, 2017, 11:40pm UTC](https://discourse.libcinder.org/t/share-a-texture-across-multiple-windows/953/1 "2017-11-15T23:40:32Z")

</div>

Dear list,  
I don’t manage to use a single texture on two separate windows.  
I have been reading various threads on this forum and tried various solutions (including threaded buffers (concurrentcircularbuffers)).  
I tried to use gl::Context::getCurrent() and context-\>makeCurrent(); functions without any success on a Linux box (ubuntu 17.10).  
Below a very simple example to start with.  
The image is only shown on the second window which i understand as being the latest opengl context before the texture is loaded on the GPU.  
Any advices most welcome !  
thanks by advance,  
Vincent

```auto
#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"
using namespace ci;
using namespace ci::app;
using namespace std;

class TestApp : public App {
public:	
	WindowRef win1, win2;
	gl::TextureRef mtex;
	ImageSourceRef img;
	void setup(){		
		win1 = getWindow();
		win1->getSignalDraw().connect( std::bind( &TestApp::draw1, this ) );
 		win2 = createWindow();
		win2->getSignalDraw().connect( std::bind( &TestApp::draw2, this ) );
		img = loadImage( loadResource ("e08.tga")) ;
		mtex = gl::Texture2d::create(img);
	}
	void draw1() {
		gl::clear( Color(0,0,0));
		if( mtex ) gl::draw(mtex);
	}
	void draw2() {
		gl::clear( Color(0,0,0));
		if (mtex) gl::draw(mtex);
	}
};
CINDER_APP(TestApp, RendererGl())

```

---

<div class="post-metadata">

**Author:** ![petros](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/petros/32/26_2.png) [@petros](https://discourse.libcinder.org/u/petros)\
**Post date:** [November 16, 2017, 7:03pm UTC](https://discourse.libcinder.org/t/share-a-texture-across-multiple-windows/953/2 "2017-11-16T19:03:05Z")

</div>

This deserves a github issue.

Context sharing between windows on Linux is not implemented it seems.The window to share context with should be passed as an argument to `glfwCreateWindow` which [does not currently happen](https://github.com/cinder/Cinder/blob/master/src/cinder/app/linux/WindowImplLinuxGlfw.cpp#L83-L93) and instead `NULL` is passed essentially disabling sharing.

Cheers,  
Petros

---

<div class="post-metadata">

**Author:** ![gabor\_papp](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gabor_papp/32/769_2.png) [@gabor\_papp](https://discourse.libcinder.org/u/gabor_papp)\
**Post date:** [November 16, 2017, 9:44pm UTC](https://discourse.libcinder.org/t/share-a-texture-across-multiple-windows/953/3 "2017-11-16T21:44:24Z")

</div>

I made some modifications in the past to share Fbo textures across multiple windows in Linux.

> **[gaborpapp / Cinder - d6ed3d2](https://bitbucket.org/gaborpapp/cinder/commits/d6ed3d2d1a1d8a0b43f97176d30d9d35966c85f9?at=raj)**
>
> Sharing OpenGL context between windows in Linux/glfw

It is not perfect as I remember. It needed the Fbo to be created before the second window.

Gabor

---

<div class="post-metadata">

**Author:** ![vincent\_rioux](https://avatars.discourse-cdn.com/v4/letter/v/bc79bd/32.png) [@vincent\_rioux](https://discourse.libcinder.org/u/vincent_rioux)\
**Post date:** [November 16, 2017, 11:11pm UTC](https://discourse.libcinder.org/t/share-a-texture-across-multiple-windows/953/4 "2017-11-16T23:11:04Z")

</div>

I tried to change the createWindow method but got into problems with WindowRef and GLFWwindow handling. too complex for me… thanks anyway it helped me understand that it was feasible 🙂

---

<div class="post-metadata">

**Author:** ![vincent\_rioux](https://avatars.discourse-cdn.com/v4/letter/v/bc79bd/32.png) [@vincent\_rioux](https://discourse.libcinder.org/u/vincent_rioux)\
**Post date:** [November 16, 2017, 11:11pm UTC](https://discourse.libcinder.org/t/share-a-texture-across-multiple-windows/953/5 "2017-11-16T23:11:29Z")

</div>

This is working very nicely as far as i can tell.  
Thanks a lot Gabor !

---

<div class="post-metadata">

**Author:** ![andrewfb](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/andrewfb/32/2_2.png) [@andrewfb](https://discourse.libcinder.org/u/andrewfb)\
**Post date:** [November 22, 2017, 5:10am UTC](https://discourse.libcinder.org/t/share-a-texture-across-multiple-windows/953/6 "2017-11-22T05:10:52Z")

</div>

I’ve created a PR which hopefully will address this. It’s a little more elaborate than yours @gabor_papp though the net result should be the same; just a bit more future-proofed for when we (likely) eventually allow users to opt-out of sharing.

[https://github.com/cinder/Cinder/pull/1936](https://github.com/cinder/Cinder/pull/1936)
