Improved Datum Visuals.

DepthTest works correctly.
Datum label selection colour works correctly. 
Made labels slightly smaller to prevent stretch

git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5052 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
mrlukeparry 2011-10-22 08:50:30 +00:00
parent d6cd29e392
commit 87dd7826c7
2 changed files with 45 additions and 19 deletions

View File

@ -227,7 +227,8 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action)
SoState *state = action->getState();
if (!shouldGLRender(action))
return;
if(action->handleTransparency(true))
return;
drawImage();
SbVec2s size;
@ -239,22 +240,22 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action)
int srch = size[1];
state->push();
glPixelStorei(GL_UNPACK_ROW_LENGTH, srcw);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_DEPTH_TEST);
glPushAttrib(GL_ENABLE_BIT | GL_PIXEL_MODE_BIT | GL_COLOR_BUFFER_BIT);
glDisable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D); // Enable Textures
glEnable(GL_BLEND);
// Copy the text bitmap into memory and bind
GLuint myTexture;
// generate a texture
glGenTextures(1, &myTexture);
glBindTexture(GL_TEXTURE_2D, myTexture);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@ -262,27 +263,29 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Create the quad to hold texture
glBegin(GL_QUADS);
const SbViewVolume & vv = SoViewVolumeElement::get(state);
float scale = vv.getWorldToScreenScale(SbVec3f(0.f,0.f,0.f), 0.5f);
float scale = vv.getWorldToScreenScale(SbVec3f(0.f,0.f,0.f), 0.4f);
float aspectRatio = (float) srcw / (float) srch;
float height = scale / (float) srch;
float width = aspectRatio * (float) height;
this->bbx = width;
this->bby = height;
this->bby = height;
glBegin(GL_QUADS);
glColor3f(1.f, 1.f, 1.f);
glTexCoord2f(0.f, 1.f); glVertex2f(-width/ 2, height / 2);
glTexCoord2f(0.f, 0.f); glVertex2f(-width / 2,-height / 2);
glTexCoord2f(1.f, 0.f); glVertex2f( width/ 2,-height / 2);
glTexCoord2f(1.f, 1.f); glVertex2f( width / 2, height / 2);
glEnd();
// Reset the Mode
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glPopAttrib();
state->pop();
}

View File

@ -732,6 +732,7 @@ bool ViewProviderSketch::mouseMove(const SbVec3f &point, const SbVec3f &normal,
if (preselectChanged) {
this->drawConstraintIcons();
this->updateColor();
return true;
}
return false;
case STATUS_SELECT_Point:
@ -1323,12 +1324,33 @@ void ViewProviderSketch::updateColor(void)
for (int i=0; i < edit->constrGroup->getNumChildren(); i++) {
SoSeparator *s = dynamic_cast<SoSeparator *>(edit->constrGroup->getChild(i));
SoMaterial *m = dynamic_cast<SoMaterial *>(s->getChild(0));
if (edit->SelConstraintSet.find(i) != edit->SelConstraintSet.end())
m->diffuseColor = SelectColor;
else if (edit->PreselectConstraint == i)
m->diffuseColor = PreselectColor;
else
m->diffuseColor = ConstraintColor;
// Check Constraint Type
ConstraintType type = this->getSketchObject()->Constraints.getValues()[i]->Type;
bool hasDatumLabel = (type == Sketcher::Angle ||
type == Sketcher::Radius ||
type == Sketcher::Distance || type == Sketcher::DistanceX || type == Sketcher::DistanceY);
if (edit->SelConstraintSet.find(i) != edit->SelConstraintSet.end()) {
m->diffuseColor = SelectColor;
if(hasDatumLabel) {
SoDatumLabel *l = dynamic_cast<SoDatumLabel *>(s->getChild(4));
l->textColor = SelectColor;
}
} else if (edit->PreselectConstraint == i) {
m->diffuseColor = PreselectColor;
if(hasDatumLabel) {
SoDatumLabel *l = dynamic_cast<SoDatumLabel *>(s->getChild(4));
l->textColor = PreselectColor;
}
}
else {
m->diffuseColor = ConstraintColor;
if(hasDatumLabel) {
SoDatumLabel *l = dynamic_cast<SoDatumLabel *>(s->getChild(4));
l->textColor = ConstraintColor;
}
}
}
// end editing
@ -2365,6 +2387,7 @@ void ViewProviderSketch::rebuildConstraintsVisual(void)
SoDatumLabel *text = new SoDatumLabel();
//text->justification = SoDatumLabel::CENTER;
text->string = "";
text->textColor = ConstraintColor;
sep->addChild(text);
edit->vConstrType.push_back((*it)->Type);