第一个QGLViewer程序

环境:vs2017 + qt5.11 + QGLViewer2.7.1

1、新建QtGUIApplication

新建一个QtGUIApplication(勾上opengl或者自己配置opengl32.lib,glu32.lib)

2、 配置QGLViewer

配置QGLViewer(包含目录、库目录、附加依赖项)

release模式QGLViewer2.lib(release模式QGLViewerd2.lib) 

3、加入QGLViewer窗口

ui文件(Form Files/mainwindow.ui)

 文件中填上头文件,运行报错

缺少XML module,Qt Project Settings->Qt Modules

 

 ok,跑起来了

4、绘制图像

头文件mainwindow.h中添加:

protected Q_SLOTS:
	void draw();

 mainwindow.cpp文件中添加:

void MainWindow::draw() {
	//官方图像镇楼
	// Draws a spiral
	const float nbSteps = 200.0;
	glBegin(GL_QUAD_STRIP);
	for (float i = 0; i < nbSteps; ++i) {
		float ratio = i / nbSteps;
		float angle = 21.0 * ratio;
		float c = cos(angle);
		float s = sin(angle);
		float r1 = 1.0 - 0.8 * ratio;
		float r2 = 0.8 - 0.8 * ratio;
		float alt = ratio - 0.5;
		const float nor = .5;
		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.05, r2 * s);
	}
	glEnd();
}

初始化时连接viewer和draw函数:

MainWindow::MainWindow(QWidget *parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);
	connect(ui.viewer, SIGNAL(drawNeeded()), this, SLOT(draw()));
}

运行(官方图镇楼)

源码:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值