[Kstars-devel] Planet textures with OpenGL
Akarsh Simha
akarshsimha at gmail.com
Mon Apr 4 09:05:50 CEST 2011
Hi
I finally did some research on this problem. It seems to me that the
reason why planet textures do not display in OpenGL is because they
are "bound" too early.
Here's some experimental data -- if I bind (when you create the
texture, it also binds it for the first time to the GL context and
obtains the Texture ID for future binding) the planet textures (for
the first time; remember, only the first time matters -- it reuses the
same texture later) in (or after) SkyMapGLDraw::initializeGL()
(i.e. QGLWidget::initializeGL() ) or SkyMapGLDraw::paintGL(), it
works.
However, if I bind the textures before that, it does not. For
instance, I tried binding the textures both in
SkyMapQDraw::paintEvent() and SkyMapGLDraw::paintEvent(). Then, if I
start KStars up in GL mode, things work fine anyway because they are
initialized in QGLWidget::paintEvent(). However, if I start KStars up
in QPainter mode, and then switch to GL, it doesn't work, because the
textures were initialized in QWidget::paintEvent(), before QGLWidget
took birth.
Now, I think that it is very likely that this has something to do with
QGLWidget being constructed. I don't understand -- it looks natural
that you should be able to first create a context, bind textures onto
that and then get a QGLWidget to use that context -- but I'm not
OpenGL expert, and I don't know any theory here.
Harry, would you have any suggestions on this?
BTW, all the other textures are bound only after the QGLWidget is
constructed -- they are bound just before they are used. However, for
planets, we get KSPlanetBase::init() to create and bind the textures
for the first time, and this seems to be called even before the
GLWidget is initialized (in fact, it WILL certainly be called before
the GLWidget is initialized if you start up in QPainter mode).
While I agree that's cleaner, maybe we could just "set up" the texture
object in KSPlanetBase and bind it (for the first time) only when it
is first required. So until then, the texture instance exists, but is
not ready, and it doesn't have a Texture ID from OpenGL. While
drawing, if we're doing OpenGL, we just check if it is ready and if it
is not, we bind it.
Does this sound okay? Harry, shall I go ahead and make this change?
Regards
Akarsh
More information about the Kstars-devel
mailing list