I am a bit of an openGL novice and I am trying to get texture sharing to work between two openGL views. I created two NSOpenGL view classes and then in the interface builder I created a window that had one of each openGL view. The first view has code in its prepareOpenGl that sets up the texture and assigns it to a global variable, the second view re-intializes its openGlContext to be one that is shared with the orginal view that created the texture, then in the prepareOpenGL of the second view I call glBindTexture on the global texture. When I run my application I only see a texture on the first view and the second view just shows an untextured object. It seems my texture sharing is not working. I am wondering if my general strategy is flawed or if I am just missing a little detail. I have included what seems to be the most important code snipets.
-(void)prepareOpenGL {
//prepareOPenGL of the first view
glEnable( GL_TEXTURE_2D );
glEnable(GL_DEPTH_TEST);
//makeImage() creates a silly little texture pattern
makeImage();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &texName);
glBindTexture(GL_TEXTURE_2D, &texName);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
glShadeModel(GL_SMOOTH);
}
-(void)prepareOpenGL {
//prepareOpenGL of the second view
glEnable( GL_TEXTURE_2D );
glEnable(GL_DEPTH_TEST);
glBindTexture(GL_TEXTURE_2D, &texName);
glShadeModel(GL_SMOOTH);
}
- (id)initWithFrame:(NSRect)frame {
if(self = [super initWithFrame:frame])
{
printf("InitWithFrame: \n");
NSOpenGLContext* context = [[[NSOpenGLContext alloc] initWithFormat:[NSOpenGLView defaultPixelFormat] shareContext:[otherView openGLContext]] autorelease];
[self setOpenGLContext:context];
}
return self;
}
When I refer to the "second view" I mean the one the is trying to use the texture of the original view.