Hello,
I don’t know if this is the right forum for this or if this is an OpenGL specific question but hopefully someone can help.
So I made this really nice looking OpenGL sphere with lighting and everything and I’m trying to draw some stuff over it but it’s not layering properly. Basically, I want to draw things in the following order: the sphere on the bottom, an ofCvGrayscaleImage in the middle, and a red circle on the top.
Here’s the draw() method:
//--------------------------------------------------------------
void testApp::draw() {
ofEnableAlphaBlending();
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
ofEnableSmoothing();
// draw the mask
glEnable(GL_LIGHTING);
glPushMatrix();
glTranslatef(ofGetWidth()/2, ofGetHeight()/2, 0);
glScalef(ofGetHeight()/2-MARGIN, ofGetHeight()/2-MARGIN, 1.0);
glutSolidSphere(1.0, 50, 50);
glPopMatrix();
glDisable(GL_LIGHTING);
// draw the frame first
ofFill();
ofSetColor(0xffffff);
glPushMatrix();
glTranslatef((WIDTH-HEIGHT+MARGIN)/2, MARGIN, 0);
glScalef((ofGetHeight()-MARGIN*2.0)/HEIGHT, (ofGetHeight()-MARGIN*2.0)/HEIGHT, 1.0);
frameChannel.draw(0, 0);
glPopMatrix();
// draw the mouse
ofSetColor(0xff0000);
ofCircle(mx, my, 10);
ofDisableSmoothing();
ofDisableAlphaBlending();
}
What’s happening though is that the red circle is getting drawn under the cvImage. If I remove the call to glBlendFunc(…) then the red circle is on top of the cvImage, but the 3D sphere doesn’t get displayed anymore. From what I read (and understand), the glBlendFunc(…) is probably the problem but I’ve tried a bunch of different parameters and nothing works. I also tried enabling and disabling the lighting at different points in the code but that doesn’t do it either.
Is the problem that I’m mixing lit elements with non-lit elements?
Is it that I’m mixing 2D with 3D?
Any help would be appreciated as I’m not even sure what the source of the problem is. If anyone feels like messing with the code, you can download the files here.
Thanks!