当前位置: 首页>>代码示例>>C++>>正文


C++ QOpenGLFunctions_2_1::glColor3ubv方法代码示例

本文整理汇总了C++中QOpenGLFunctions_2_1::glColor3ubv方法的典型用法代码示例。如果您正苦于以下问题:C++ QOpenGLFunctions_2_1::glColor3ubv方法的具体用法?C++ QOpenGLFunctions_2_1::glColor3ubv怎么用?C++ QOpenGLFunctions_2_1::glColor3ubv使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QOpenGLFunctions_2_1的用法示例。


在下文中一共展示了QOpenGLFunctions_2_1::glColor3ubv方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: draw

//override draw function
void ccMouseCircle::draw(CC_DRAW_CONTEXT& context)
{
	//only draw when visible
	if (!ccMouseCircle::isVisible())
		return;

	//only draw in 2D foreground mode
	if (!MACRO_Foreground(context) || !MACRO_Draw2D(context))
		return;

	//get the set of OpenGL functions (version 2.1)
	QOpenGLFunctions_2_1 *glFunc = context.glFunctions<QOpenGLFunctions_2_1>();
	assert(glFunc != nullptr);

	if (glFunc == nullptr)
		return;

	//test viewport parameters
	const ccViewportParameters& params = context.display->getViewportParameters();
	glFunc->glPushAttrib(GL_LINE_BIT);

	float relativeZoom = 1.0f;
	float dx = 0.0f;
	float dy = 0.0f;
	if (!m_params.perspectiveView) //ortho mode
	{
		//Screen pan & pivot compensation
		float totalZoom = m_params.zoom / m_params.pixelSize;
		m_winTotalZoom = params.zoom / params.pixelSize;
		relativeZoom = m_winTotalZoom / totalZoom;

		CCVector3d dC = m_params.cameraCenter - params.cameraCenter;
		
		CCVector3d P = m_params.pivotPoint - params.pivotPoint;
		m_params.viewMat.apply(P);

		static_cast<float>(dC.x + P.x);
		static_cast<float>(dC.y + P.y);

		dx *= m_winTotalZoom;
		dy *= m_winTotalZoom;
	}

	//thick dotted line
	glFunc->glLineWidth(2);
	glFunc->glLineStipple(1, 0xAAAA);
	glFunc->glEnable(GL_LINE_STIPPLE);

	const unsigned char* defaultColor = m_selected ? ccColor::red.rgba : context.textDefaultCol.rgb;
	glFunc->glColor3ubv(ccColor::red.rgba);

	//get height & width
	int halfW = static_cast<int>(context.glW / 2.0f);
	int halfH = static_cast<int>(context.glH / 2.0f);
	
	//get mouse position
	QPoint p = m_owner->asWidget()->mapFromGlobal(QCursor::pos());
	int mx = p.x(); //mouse x-coord
	int my = 2*halfH - p.y(); //mouse y-coord in OpenGL coordinates (origin at bottom left, not top left)
	
	//calculate circle location
	int cx = dx+mx-halfW;
	int cy = dy+my-halfH;

	//draw circle
	glFunc->glBegin(GL_LINE_LOOP);
	for (int n = 0; n < ccMouseCircle::RESOLUTION; n++)
	{
		glFunc->glVertex2f(ccMouseCircle::UNIT_CIRCLE[n][0] * ccMouseCircle::RADIUS + cx, ccMouseCircle::UNIT_CIRCLE[n][1] * ccMouseCircle::RADIUS + cy);
	}
	glFunc->glEnd();
	glFunc->glPopAttrib();
}
开发者ID:luca-penasa,项目名称:trunk,代码行数:74,代码来源:ccMouseCircle.cpp

示例2: tab


//.........这里部分代码省略.........
												255 - context.labelDefaultBkgCol.g,
												255 - context.labelDefaultBkgCol.b);
		}

		//label title
		context.display->displayText(	title,
										xStart+xStartRel,
										yStart+yStartRel,
										ccGenericGLDisplay::ALIGN_DEFAULT,
										0,
										defaultTextColor.rgb,
										&titleFont);
		yStartRel -= margin;
		
		if (m_showFullBody)
		{
#ifdef DRAW_CONTENT_AS_TAB
			int xCol = xStartRel;
			for (int c=0; c<tab.colCount; ++c)
			{
				int width = tab.colWidth[c] + 2*tabMarginX;
				int height = rowHeight + 2*tabMarginY;

				int yRow = yStartRel;
				int actualRowCount = std::min(tab.rowCount,tab.colContent[c].size());

				bool labelCol = ((c & 1) == 0);
				const unsigned char* textColor = labelCol ? ccColor::white.rgba : defaultTextColor.rgb;
				
				for (int r=0; r<actualRowCount; ++r)
				{
					if (r && (r % 3) == 0)
						yRow -= margin;

					if (labelCol)
					{
						//draw background
						int rgbIndex = (r % 3);
						if (rgbIndex == 0)
							glFunc->glColor3ubv(ccColor::red.rgba);
						else if (rgbIndex == 1)
							glFunc->glColor3ubv(c_darkGreen.rgba);
						else if (rgbIndex == 2)
							glFunc->glColor3ubv(ccColor::blue.rgba);

						glFunc->glBegin(GL_QUADS);
						glFunc->glVertex2i(m_labelROI.left() + xCol, -m_labelROI.top() + yRow);
						glFunc->glVertex2i(m_labelROI.left() + xCol, -m_labelROI.top() + yRow - height);
						glFunc->glVertex2i(m_labelROI.left() + xCol + width, -m_labelROI.top() + yRow - height);
						glFunc->glVertex2i(m_labelROI.left() + xCol + width, -m_labelROI.top() + yRow);
						glFunc->glEnd();
					}

					const QString& str = tab.colContent[c][r];

					int xShift = 0;
					if (labelCol)
					{
						//align characters in the middle
						xShift = (tab.colWidth[c] - QFontMetrics(bodyFont).width(str)) / 2;
					}
					else
					{
						//align digits on the right
						xShift = tab.colWidth[c] - QFontMetrics(bodyFont).width(str);
					}

					context.display->displayText(	str,
													xStart + xCol + tabMarginX + xShift,
													yStart + yRow - rowHeight, ccGenericGLDisplay::ALIGN_DEFAULT, 0, textColor, &bodyFont);

					yRow -= height;
				}

				xCol += width;
			}
#else
			if (!body.empty())
			{
				//display body
				yStartRel -= margin;
				for (int i=0; i<body.size(); ++i)
				{
					yStartRel -= rowHeight;
					context.display->displayText(body[i],xStart+xStartRel,yStart+yStartRel,ccGenericGLDisplay::ALIGN_DEFAULT,0,defaultTextColor.rgb,&bodyFont);
				}
			}
#endif //DRAW_CONTENT_AS_TAB
		}
	}

	glFunc->glPopAttrib();

	glFunc->glPopMatrix();

	if (pushName)
	{
		glFunc->glPopName();
	}
}
开发者ID:stephaniewxk,项目名称:trunk,代码行数:101,代码来源:cc2DLabel.cpp

示例3: DrawColorRamp


//.........这里部分代码省略.........

		//(x,y): current display area coordinates (top-left corner)
		int x = halfW-xShift-scaleWidth;
		int y = halfH-yShift-scaleMaxHeight;

		if (keyValues.size() > 1)
		{
			int histoStart = x + scaleWidth + std::min(std::max(scaleWidth / 8, 3), static_cast<int>(15 * renderZoom));

			glFunc->glBegin(GL_LINES);
			for (int j=0; j<scaleMaxHeight; ++j)
			{
				double baseValue = sortedKeyValues.front() + (j * maxRange) / scaleMaxHeight;
				double value = baseValue;
				if (logScale)
				{
					value = exp(value*c_log10);
				}
				const ColorCompType* col = sf->getColor(static_cast<ScalarType>(value));
				if (!col)
				{
					//special case: if we have user-defined labels, we want all the labels to be displayed with their associated color
					if (customLabels)
					{
						assert(sf->getColorScale() && !sf->getColorScale()->isRelative());
						col = sf->getColorScale()->getColorByValue(value, ccColor::lightGrey.rgba);
					}
					else
					{
						col = ccColor::lightGrey.rgba;
					}
				}
				assert(col);
				glFunc->glColor3ubv(col);

				glFunc->glVertex2i(x,y+j);
				glFunc->glVertex2i(x+scaleWidth,y+j);

				if (showHistogram)
				{
					double bind = (value - sf->displayRange().min())*(histogram.size() - 1) / sf->displayRange().maxRange();
					int bin = static_cast<int>(floor(bind));

					double hVal = 0.0;
					if (bin >= 0 && bin < static_cast<int>(histogram.size())) //in symmetrical case we can get values outside of the real SF range
					{
						hVal = histogram[bin];
						if (bin+1 < static_cast<int>(histogram.size()))
						{
							//linear interpolation
							double alpha = bind-static_cast<double>(bin);
							hVal = (1.0-alpha) * hVal + alpha * histogram[bin+1];
						}
					}

					int xSpan = std::max(static_cast<int>(hVal / histogram.maxValue * (scaleWidth/2)),1);
					glFunc->glVertex2i(histoStart,y+j);
					glFunc->glVertex2i(histoStart+xSpan,y+j);
				}
			}
			glFunc->glEnd();
		}
		else
		{
			//if there's a unique (visible) scalar value, we only draw a square!
			double value = sortedKeyValues.front();
开发者ID:Puwong,项目名称:CloudCompare,代码行数:67,代码来源:ccRenderingTools.cpp

示例4: title

void cc2DViewportLabel::drawMeOnly(CC_DRAW_CONTEXT& context)
{
	//2D foreground only
	if (!MACRO_Foreground(context) || !MACRO_Draw2D(context))
		return;
	
	//get the set of OpenGL functions (version 2.1)
	QOpenGLFunctions_2_1 *glFunc = context.glFunctions<QOpenGLFunctions_2_1>();
	assert( glFunc != nullptr );
	
	if ( glFunc == nullptr )
		return;
	
	//test viewport parameters
	const ccViewportParameters& params = context.display->getViewportParameters();

	//general parameters
	if (	params.perspectiveView != m_params.perspectiveView
		||	params.objectCenteredView != m_params.objectCenteredView
		||	params.pixelSize != m_params.pixelSize)
	{
			return;
	}

	//test base view matrix
	for (unsigned i = 0; i < 12; ++i)
		if (fabs(params.viewMat.data()[i] - m_params.viewMat.data()[i]) > ZERO_TOLERANCE)
			return;

	if (m_params.perspectiveView)
	{
		if (params.fov != m_params.fov || params.perspectiveAspectRatio != m_params.perspectiveAspectRatio)
			return;

		if ((params.pivotPoint - m_params.pivotPoint).norm() > ZERO_TOLERANCE
			|| (params.cameraCenter - m_params.cameraCenter).norm() > ZERO_TOLERANCE)
			return;
	}
	else
	{
		if (params.orthoAspectRatio != m_params.orthoAspectRatio)
			return;
	}

	glFunc->glPushAttrib(GL_LINE_BIT);

	float relativeZoom = 1.0f;
	float dx = 0, dy = 0;
	if (!m_params.perspectiveView) //ortho mode
	{
		//Screen pan & pivot compensation
		float totalZoom = m_params.zoom / m_params.pixelSize;
		float winTotalZoom = params.zoom / params.pixelSize;
		relativeZoom = winTotalZoom / totalZoom;

		CCVector3d dC = m_params.cameraCenter - params.cameraCenter;

		CCVector3d P = m_params.pivotPoint - params.pivotPoint;
		m_params.viewMat.apply(P);

		dx = static_cast<float>(dC.x + P.x);
		dy = static_cast<float>(dC.y + P.y);

		dx *= winTotalZoom;
		dy *= winTotalZoom;
	}

	//thick dotted line
	glFunc->glLineWidth(2);
	glFunc->glLineStipple(1, 0xAAAA);
	glFunc->glEnable(GL_LINE_STIPPLE);

	const unsigned char* defaultColor = m_selected ? ccColor::red.rgba : context.textDefaultCol.rgb;
	glFunc->glColor3ubv(defaultColor);

	glFunc->glBegin(GL_LINE_LOOP);
	glFunc->glVertex2f(dx + m_roi[0] * relativeZoom, dy + m_roi[1] * relativeZoom);
	glFunc->glVertex2f(dx + m_roi[2] * relativeZoom, dy + m_roi[1] * relativeZoom);
	glFunc->glVertex2f(dx + m_roi[2] * relativeZoom, dy + m_roi[3] * relativeZoom);
	glFunc->glVertex2f(dx + m_roi[0] * relativeZoom, dy + m_roi[3] * relativeZoom);
	glFunc->glEnd();

	glFunc->glPopAttrib();

	//title
	QString title(getName());
	if (!title.isEmpty())
	{
		QFont titleFont(context.display->getTextDisplayFont()); //takes rendering zoom into account!
		titleFont.setBold(true);
		QFontMetrics titleFontMetrics(titleFont);
		int titleHeight = titleFontMetrics.height();

		int xStart = (int)(dx + 0.5f*(float)context.glW + std::min<float>(m_roi[0], m_roi[2])*relativeZoom);
		int yStart = (int)(dy + 0.5f*(float)context.glH + std::min<float>(m_roi[1], m_roi[3])*relativeZoom);

		context.display->displayText(title, xStart, yStart - 5 - titleHeight, ccGenericGLDisplay::ALIGN_DEFAULT, 0, defaultColor, &titleFont);
	}
}
开发者ID:3660628,项目名称:trunk,代码行数:99,代码来源:cc2DViewportLabel.cpp


注:本文中的QOpenGLFunctions_2_1::glColor3ubv方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。