Transparency of QGLWindow
-
Hi,
I require help in creating a transparent QGLWindow. Here is what I am doing.
- I have derived a class from QGLWidget and drawing a few symbols using paintGL().
- THe idea is to integrate this with QGIS, so that the symbols drawn will be visible on the map. The QGIS used QT v 4.7
- While creating the instance of the GLWidget class for creating a QGLWindow, the QGLWindow covers up the map canvas window and I’m unable to view the map in the background.
- Is there a way to make the QGLWindow transparent, so that the map in the background becomes visible.
- Is it possible to create the QGLWindow as a layer on the map.
I have enclosed the code for reference.
Any help is greatly appreciated.Thanks
Regards
Sridhar@
GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent)
{
…..
}
void GLWidget::initializeGL()
{
….
}void GLWidget::resizeGL(int w, int h)
{
….}
void GLWidget::drawSymbol (float x_center, float y_center, float w, float h, int n)
{
float theta, angle_increment;
float x, y;
float fianlval=0.0;
double PI_2 =6.24;
if (n <= 0)
n = 1;
angle_increment = (PI_2) / n;
glPushMatrix ();
glTranslatef (x_center, y_center, 0);
glScalef(0.5f, 0.5f, 0.0f); // Make the shape half as wide, the same height and twice as deep
glBegin (GL_LINE_STRIP);
for (theta = 0.0f; theta < (PI_2); theta += angle_increment)
{
x = (w/2) * cos (theta);
y = (h/2) * sin (theta);
glColor3f(1,0,0);
glVertex2f (x, y);
fianlval = theta;
}
glEnd ();
glPopMatrix ();
glPushMatrix ();glBegin (GL_LINES);
glVertex2f(x_center, y_center-25);
glVertex2f((x_center), (y_center-38));
glEnd ();
glPopMatrix ();
glPushMatrix ();glTranslatef (x_center, y_center-48, 0);
glScalef(0.6f, 0.3f, 0.0f);
glBegin (GL_LINE_STRIP);for (theta = 0.1f; theta < (PI_2/2); theta += angle_increment) { x = (w/3) * cos (theta); y = (h/3) * sin (theta);
glColor3f(1,0,0);
glVertex2f (x, y);
}
glEnd ();
glPopMatrix ();}
void GLWidget::paintGL()
{
float angle =0.0;
lat+=0.5;lon+=5;lat1+=0.5;lon1+=5;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
drawSymbol(lat1,lon1,30.0,100.0,300);}
int main(int argc, char ** argv)
{
QgsApplication app(argc, argv, true);
mMapCanvas = new QgisCanvas( this, "theMapCanvas" );
GLWidget * drawing = new GLWidget(mMapCanvas);
drawing->resize(1000,800);
drawing->setParent(mMapCanvas);
mMapCanvas->show ();
return app.exec();
}
@