Hi,
I am not a true beginner in OpenGL as I know the basic things, but I would like to perform a more complex task.
Let say I have an OpenGL app running on Win7, it’s AppA. I have not a full control on that app but I can get the texture IDs it is using. Then I would like to code another app (AppB) to use the texture from AppA. AppB is a DLL.
The running process is as follow :
- Start AppA
- AppA sends the texture ID to AppB throught a DLL
- AppA starts AppB (set pixel format, create window) throught a DLL.
Then AppA and AppB will work in parallel.
AppA and AppB have a different pixel format (AppB uses Quadbuffer stereo). Each app have its own window (so DeviceContext, right ?).
My problem : I cannot get the texture to work in AppB.
My attemps
(in every attemp I am binding the texture from AppA using its ID in “glBindTexture( GL_TEXTURE_2D, tid)”):
a) Directly use the texture in AppB with a glBindTexture and the textureID (tid) from AppA => not working.
b) Init AppB with the same RenderContext as AppA (using freeglut : “glutSetOption(GLUT_RENDERING_CONTEXT, GLUT_USE_CURRENT_CONTEXT)”) => not working.
c) I tried to make the two RCs to share data with “wglShareLists(…)”.
AppB is a DLL, here is its init function.
void EXPORT_API initStereoWindow()
{
int argc = 1;
char* argv[] = {"plugin"};
glutInit(&argc, argv);
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE , GLUT_ACTION_CONTINUE_EXECUTION);
//glutSetOption(GLUT_RENDERING_CONTEXT, GLUT_USE_CURRENT_CONTEXT);
HGLRC originalRC = 0, quadRC = 0;
originalRC = wglGetCurrentContext();
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_STEREO);
gWindowId = glutCreateWindow("StereoRenderer");
quadRC = wglGetCurrentContext();
bool ok = originalRC == quadRC; // ok is false
ok = wglShareLists(originalRC , quadRC); // ok is true
glutDisplayFunc(display);
}
So, AppA starts, load AppB DLL, then calls the “initStereoWindow()” function. That function use “wglShareLists(…)” to make the RCs share data.
==> not working.
In each case, AppA calls the “glutMainLoopEvent()” (freeglut function equivalent to non-blocking “glutMainLoop()”) before swap its buffer.
One more thing, in case c) the clearcolor in AppV is the same as that in AppA. Since I did not set it (with glClearColor), I assume that data is shared between the apps.
Someone know how can I acheive that ?
In a simple form : I would like to share texture between two app (one that I can control only to call DLL, another one that I have coded).
Thanks in advance.
Appendix
Display and helper function
void drawTexture(unsigned int tid)
{
glEnable( GL_TEXTURE_2D );
//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glBindTexture( GL_TEXTURE_2D, tid);
glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0); glVertex2d(-1.0,-1.0);
glTexCoord2d(1.0,0.0); glVertex2d(+1.0,-1.0);
glTexCoord2d(1.0,1.0); glVertex2d(+1.0,+1.0);
glTexCoord2d(0.0,1.0); glVertex2d(-1.0,+1.0);
glEnd();
glDisable(GL_TEXTURE_2D);
}
void EXPORT_API display(void)
{
glPushMatrix();
glDrawBuffer(GL_BACK_LEFT);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
drawTexture(gLeftTexId);
glDrawBuffer(GL_BACK_RIGHT);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0, 0, -2.0f);
drawTexture(gRightTexId);
glPopMatrix();
glutSwapBuffers();
}