I would like to be able to use OpenGL inside the QuarterWidget, FreeCAD use to glue Coin3D to OpenCascade scene. I can retrieve the following objects via python:
def GetQuarterWidget(self): #From FreeCAD forum
views = []
self.mainWindow=Gui.getMainWindow()
for w in self.mainWindow.findChild(QtGui.QMdiArea).findChildren(QtGui.QWidget):
if w.inherits("SIM::Coin3D::Quarter::QuarterWidget"):
views.append(w)
return views
def getMdiWindow(self) #From FreeCAD forum
mw = Gui.getMainWindow()
mdi = mw.findChild(PySide2.QtWidgets.QMdiArea)
but I don't know how to be able to draw to the scene using OpenGL code... Say hello world code (drawing only a triangle)?
My goal is to be able to make a link to the scene so I can draw all my new object using OpenGL directly, not COIN3D, or using SDL2 library ..etc.
I appreciate any hint to achieve that. I use python but I accept getting cpp code also.
Thank you very much
EDIT: I managed to draw hello world triangle inside the scene .. how good is the code? I am not sure yet. below is the code .
from OpenGL.GL import *
from OpenGL.GLU import *
import PySide2
import FreeCADGui as Gui
import pivy.coin as coin
import PySide.QtCore as QtCore
import PySide.QtGui as QtGui
from PySide2.QtOpenGL import * #as QtOPENGL
from OpenGL.WGL import *
def drawOpenGl(arg1,arg2):
glTranslatef(-2.5, 0.5, -6.0)
glColor3f( 1.0, 1.5, 0.0 )
glPolygonMode(GL_FRONT, GL_FILL)
glBegin(GL_TRIANGLES)
glVertex3f(2.0,-1.2,0.0)
glVertex3f(2.6,0.0,0.0)
glVertex3f(2.9,-1.2,0.0)
glEnd()
def drawsomething():
w_view = Gui.ActiveDocument.ActiveView
Root_SceneGraph = w_view.getSceneGraph()
calback_=coin.SoCallback()
calback_.setCallback(drawOpenGl)
Root_SceneGraph.addChild(calback_)
drawsomething()
please notice that you need to install pyopengl inside freecad (not your pc/linux/mac version of pip or python) by running FreeCAD's python.
FREECAD_DIR/bin/Scripts/pip install pyopengl