QGLViewer (For Visual Studio) 的配置

1. 首先安装Qt,网上很多教程可自行搜索。

2. 在qt主页上下载并安装Qt Add-in.

3. 下载并安装QGLViewer,点击打开链接 http://www.libqglviewer.com/index.html

- 用binary installer先安装一遍

- 下载 libQGLViewer-2.5.0.zip , 编译并生成QGLViewerd2.lib、QGLViewer2.lib和QGLViewerd2.dll、QGLViewer2.dll等文件。把dll文件拷贝到system路径下。

Note:这些lib和all文件在后续的配置中要用到,且注意release和debug的库文件不可混用,否则会产生错误(惨痛的教训。。。)。

4. 在Visual Studio里新建一个Qt Application Project。

5. 拷贝QGLViewer上的sample code,创建一个simpleViewer project。

6.  Incldue Directories: QTDIR\4.8.5\include\QtOpenGL; QTDIR\4.8.5\include\QtXml; LibQGLViewerDIR

     Library Directories: 把QGLViewerd2.lib、QGLViewer2.lib的路径添加到Debug和Release相应的目录下

7. Linker->Additional Dependencies: 

Debug: 

QGLViewerd2.lib
QtXmld4.lib
qtmaind.lib
QtCored4.lib
QtGuid4.lib
QtOpenGLd4.lib
opengl32.lib
glu32.lib


Release:

QGLViewer2.lib

QtXml4.lib

qtmain.lib
QtCore4.lib
QtGui4.lib
QtOpenGL4.lib
opengl32.lib
glu32.lib

8. 运行QGLViewer自带的例程,测试是否配置成功。

simpleViewer.h

#include <QGLViewer/qglviewer.h>

class Viewer : public QGLViewer
{
protected :
  virtual void draw();
  virtual void init();
  virtual QString helpString() const;
};

simpleViewer.cpp

#include "simpleViewer.h"

using namespace std;

// Draws a spiral
void Viewer::draw()
{
  const float nbSteps = 200.0;

  glBegin(GL_QUAD_STRIP);
  for (int i=0; i<nbSteps; ++i)
	{
	  const float ratio = i/nbSteps;
	  const float angle = 21.0*ratio;
	  const float c = cos(angle);
	  const float s = sin(angle);
	  const float r1 = 1.0 - 0.8f*ratio;
	  const float r2 = 0.8f - 0.8f*ratio;
	  const float alt = ratio - 0.5f;
	  const float nor = 0.5f;
	  const float up = sqrt(1.0-nor*nor);
	  glColor3f(1.0-ratio, 0.2f , ratio);
	  glNormal3f(nor*c, up, nor*s);
	  glVertex3f(r1*c, alt, r1*s);
	  glVertex3f(r2*c, alt+0.05f, r2*s);
	}
  glEnd();
}

void Viewer::init()
{
  // Restore previous viewer state.
  restoreStateFromFile();

  // Opens help window
  help();
}

QString Viewer::helpString() const
{
  QString text("<h2>S i m p l e V i e w e r</h2>");
  text += "Use the mouse to move the camera around the object. ";
  text += "You can respectively revolve around, zoom and translate with the three mouse buttons. ";
  text += "Left and middle buttons pressed together rotate around the camera view direction axis<br><br>";
  text += "Pressing <b>Alt</b> and one of the function keys (<b>F1</b>..<b>F12</b>) defines a camera keyFrame. ";
  text += "Simply press the function key again to restore it. Several keyFrames define a ";
  text += "camera path. Paths are saved when you quit the application and restored at next start.<br><br>";
  text += "Press <b>F</b> to display the frame rate, <b>A</b> for the world axis, ";
  text += "<b>Alt+Return</b> for full screen mode and <b>Control+S</b> to save a snapshot. ";
  text += "See the <b>Keyboard</b> tab in this window for a complete shortcut list.<br><br>";
  text += "Double clicks automates single click actions: A left button double click aligns the closer axis with the camera (if close enough). ";
  text += "A middle button double click fits the zoom of the camera and the right button re-centers the scene.<br><br>";
  text += "A left button double click while holding right button pressed defines the camera <i>Revolve Around Point</i>. ";
  text += "See the <b>Mouse</b> tab and the documentation web pages for details.<br><br>";
  text += "Press <b>Escape</b> to exit the viewer.";
  return text;
}

main.cpp

#include "simpleViewer.h"
#include <qapplication.h>

int main(int argc, char** argv)
{
  // Read command lines arguments.
  QApplication application(argc,argv);

  // Instantiate the viewer.
  Viewer viewer;

  viewer.setWindowTitle("simpleViewer");

  // Make the viewer window visible on screen.
  viewer.show();

  // Run main loop.
  return application.exec();
}





评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值