Re: [osg-users] OSG + Qt4.5 + Textures

2009-04-27 Thread Bence Frenyo
Thanks Roland,
in fact I didn't realize the emoticon has different meaning than look. Sorry 
about that, I'm not shocked at all, just curiously waiting if someone may have 
time/knowledge/whatever it takes... to answer my question, which will pop up 
more and more times from others as well, because OSG _is_ mixed with other 
toolkits.


rosme wrote:
 Note that users in the forum can easily add emoticons through clicking on an 
 image.
 Mailing list users will not see the emoticons but the BBCode that was used. I 
 don't know if these are replaced by an alternative textual representation. 
 Art will have to answer that. Vice versa users in the forum will see 
 emoticons appear in strange locations if source code is posted on the forum.
 
 --
 Roland
 


Cheers
--
Bence

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=10891#10891





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] OSG + Qt4.5 + Textures

2009-04-27 Thread Bence Frenyo
Hi all,
I hope this will help many in the future, I figured out the missing piece for 
this case.


Code:
void MyWidget::paintGL()
{
  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
  glLoadIdentity();

  glPushAttrib(GL_ALL_ATTRIB_BITS);
  glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);

  glShadeModel(GL_SMOOTH);

  osg::State *state = getCamera()-getGraphicsContext()-getState();
  state-reset();
  state-apply(_lastStateSet.get());

  frame();

  // this was the missing step:
  glViewport(0, 0, width(), height());
  glMatrixMode(GL_MODELVIEW);
  glLoadMatrixd(getCamera()-getViewMatrix().ptr());
  glMatrixMode(GL_PROJECTION);
  glLoadMatrixd(getCamera()-getProjectionMatrix().ptr());

  // here you can draw in OSG's 3D space

  
getCamera()-getGraphicsContext()-getState()-captureCurrentState(*_lastStateSet);

  glPopAttrib();
  glPopClientAttrib();

  glMatrixMode(GL_PROJECTION);
  glPopMatrix();
  glMatrixMode(GL_MODELVIEW);
  glPopMatrix();

  // here you can draw in Qt's 2D space
}




I'm actually not sure if everything here is needed, but this works.

Cheers
--
Bence

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=10908#10908





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] OSG + Qt4.5 + Textures

2009-04-24 Thread Bence Frenyo
please...  [Shocked]

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=10802#10802





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] OSG + Qt4.5 + Textures

2009-04-24 Thread Robert Osfield
On Fri, Apr 24, 2009 at 2:48 PM, Bence Frenyo bence.fre...@gmail.com wrote:
 please...  [Shocked]

Shocked by what??

You do a particular combination of stuff and then ask a question about
something that few others know anything about.  Are you expecting us
all to have integrated OSG  and QT 4.5 and do texture maipulation
exactly how you've done?

Are you expecting one the second free support?

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] OSG + Qt4.5 + Textures

2009-04-24 Thread Roland Smeenk

robertosfield wrote:
 
 Shocked by what??
 


Note that users in the forum can easily add emoticons through clicking on an 
image.
Mailing list users will not see the emoticons but the BBCode that was used. I 
don't know if these are replaced by an alternative textual representation. Art 
will have to answer that. Vice versa users in the forum will see emoticons 
appear in strange locations if source code is posted on the forum.

--
Roland

Here are all available emoticons:
 :D 
 :) 
 :(

 :o 
 [Shocked] 
 :? 
 8) 
 [Laughing] 
 :x 
 :P 
 [Embarassed] 
 [Crying or Very sad] 
 [Evil or Very Mad] 
 [Twisted Evil] 
 [Rolling Eyes] 
 [Wink] 
 [Exclamation] 
 [Question] 
 [Idea] 
 [Arrow]
 :| 
 [Mr. Green]

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=10811#10811





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] OSG + Qt4.5 + Textures

2009-04-22 Thread Bence Frenyo
Hi,

I'm new to OSG, but found it handling 3D scenes several magnitudes faster than 
I did :)
So I jumped on integrating it with our existing Qt4.5 based application which 
already
has very complicated UI based on QGraphicsScene with a 3D earth rendered in the
background. 'osgEarth' plugin is just perfect for that job.

However I can't just change everything to OSG, I need to use our original GL 
textures
as well. So I learned from other posts how to save the states for OSG/Qt 
rendering.

I want to draw a texture still in OSG's 3D scene, but that is incorrect. 
Texture coordinates and quad coordinates are not the ones I expect.
It's visible especially when resizing the window.

Here's a short example:


Code:
#include QApplication
#include QGLWidget
#include osgViewer/Viewer
#include osgDB/ReadFile

static const double _R = 6378137.; // Earth radius

class OsgAdapterWidget : public QGLWidget, public osgViewer::Viewer
{
  osg::ref_ptrosgViewer::GraphicsWindowEmbedded _gw;
  osg::ref_ptrosg::Node _model;
  osg::ref_ptrosg::StateSet _lastStateSet;
  GLuint _textureID;

public:
  OsgAdapterWidget(QWidget* parent = 0);

  void paintGL();
  void resizeGL(int, int);
};


OsgAdapterWidget::OsgAdapterWidget(QWidget *parent)
: QGLWidget(QGLFormat(QGL::Rgba | QGL::AlphaChannel |
  QGL::SampleBuffers | QGL::DoubleBuffer), parent),
  _lastStateSet(new osg::StateSet)
{
  _gw = new osgViewer::GraphicsWindowEmbedded(0, 0, width(), height());

  getCamera()-setGraphicsContext(_gw.get());
  getCamera()-setClearColor(osg::Vec4f(0., 0., 0., 1.));
  getCamera()-setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  _model = osgDB::readNodeFile(model.earth);
  setSceneData(_model.get());

  QGLWidget::makeCurrent();

  QImage image(image.png);
  glEnable(GL_TEXTURE_2D);
  glGenTextures(1, _textureID);
  glBindTexture(GL_TEXTURE_2D, _textureID);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(), 0,
   GL_BGRA, GL_UNSIGNED_BYTE, image.bits());
}

void OsgAdapterWidget::resizeGL(int w, int h)
{
  glViewport(0, 0, w, h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluOrtho2D(-w/2, w/2, h/2, -h/2);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  _gw-getEventQueue()-windowResize(0, 0, w, h);
  _gw-resized(0, 0, w, h);

  getCamera()-setViewport(new osg::Viewport(0, 0, double(w), double(h)));
  getCamera()-setProjectionMatrixAsPerspective(35., double(w)/double(h), 1., 
4*_R);
  getCamera()-setViewMatrixAsLookAt(osg::Vec3d(3*_R, 0., 0.), osg::Vec3d(0., 
0., 0.), osg::Vec3d(0., 0., 1.));
  update();
}

void OsgAdapterWidget::paintGL()
{
  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
  glLoadIdentity();

  glPushAttrib(GL_ALL_ATTRIB_BITS);
  glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);

  glMatrixMode(GL_TEXTURE);
  glPushMatrix();
  glLoadIdentity();

  glShadeModel(GL_SMOOTH);

  osg::State *state = getCamera()-getGraphicsContext()-getState();
  state-reset();
  state-apply(_lastStateSet.get());

  frame();

  glMatrixMode(GL_TEXTURE);  glPopMatrix();

  // This is not working, texture coordinates are not in 0-1 range
  // and quad seems to be in incorrect position as well.
  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, _textureID);
  glBegin(GL_QUADS);
glTexCoord2d(0., 0.);  glVertex3d(-_R, -_R, _R);
glTexCoord2d(1., 0.);  glVertex3d(_R, -_R, _R);
glTexCoord2d(1., 1.);  glVertex3d(_R, _R, -_R);
glTexCoord2d(0., 1.);  glVertex3d(-_R, _R, -_R);
  glEnd();
  
getCamera()-getGraphicsContext()-getState()-captureCurrentState(*_lastStateSet);

  glPopAttrib();
  glPopClientAttrib();

  glMatrixMode(GL_PROJECTION);  glPopMatrix();
  glMatrixMode(GL_MODELVIEW);   glPopMatrix();

  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, _textureID);
  glBegin(GL_QUADS);
glTexCoord2d(0., 0.);  glVertex2d(-50., -50.);
glTexCoord2d(1., 0.);  glVertex2d(50., -50.);
glTexCoord2d(1., 1.);  glVertex2d(50., 50.);
glTexCoord2d(0., 1.);  glVertex2d(-50., 50.);
  glEnd();
}

int main(int ac, char* av[])
{
  QApplication app(ac, av);
  app.setGraphicsSystem(opengl);
  OsgAdapterWidget mainWindow;
  mainWindow.show();
  return app.exec();
}




You'll need an image.png for the texture and for model.earth you can use 
this:

Code:
map name=TMS Example type=geocentric
image name=metacarta blue marble driver=tms
urlhttp://labs.metacarta.com/wms-c/Basic.py/1.0.0/satellite//url
/image
/map




I'd appreciate some suggestions.
Thank you.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=10619#10619





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org