青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

OpenGL Polygon Offset

OpenGL

Polygon Offset



Tutorials > OpenGL > Polygon?Offset

LINK:http://www.zeuscmd.com/tutorials/opengl/15-PolygonOffset.php
ull Source

Introduction

Polygon Offset It is often quite useful to accentuate the edges of your objects by rendering your object once in fill mode and once in line mode. This often produces unsatisfactory results as the line may move into and out of the polygon. This effect is commonly known as stitching.

You may have also noticed in the past that when rendering two polygons that overlap each other, Z-fighting occurs and parts of each polygon are rendered.

The results of stitching and z-fighting can be seen in the figures below.

Stitching Effect Stitching Effect
Stitching Effect Z-Fighting Effect

This tutorial expands on tutorial 13 and shows how you can overcome these effects by making use of polygon offsets.

Contents of main.cpp :


One variable is kept to indicate whether polygon offsets are currently being used. This will allow you to toggle polygon offsets on and off to see exactly how this technique improves the program.

				bool offset = true;

The drawBox function remains exactly the same except that the calls to change the current color have been removed.

				void drawBox()
{
	glBegin(GL_QUADS);
		// FRONTglVertex3f(-0.5f, -0.5f,  0.5f);
		glVertex3f( 0.5f, -0.5f,  0.5f);
		glVertex3f( 0.5f,  0.5f,  0.5f);
		glVertex3f(-0.5f,  0.5f,  0.5f);
		// BACKglVertex3f(-0.5f, -0.5f, -0.5f);
		glVertex3f(-0.5f,  0.5f, -0.5f);
		glVertex3f( 0.5f,  0.5f, -0.5f);
		glVertex3f( 0.5f, -0.5f, -0.5f);
		// LEFTglVertex3f(-0.5f, -0.5f,  0.5f);
		glVertex3f(-0.5f,  0.5f,  0.5f);
		glVertex3f(-0.5f,  0.5f, -0.5f);
		glVertex3f(-0.5f, -0.5f, -0.5f);
		// RIGHTglVertex3f( 0.5f, -0.5f, -0.5f);
		glVertex3f( 0.5f,  0.5f, -0.5f);
		glVertex3f( 0.5f,  0.5f,  0.5f);
		glVertex3f( 0.5f, -0.5f,  0.5f);
		// TOPglVertex3f(-0.5f,  0.5f,  0.5f);
		glVertex3f( 0.5f,  0.5f,  0.5f);
		glVertex3f( 0.5f,  0.5f, -0.5f);
		glVertex3f(-0.5f,  0.5f, -0.5f);
		// BOTTOMglVertex3f(-0.5f, -0.5f,  0.5f);
		glVertex3f(-0.5f, -0.5f, -0.5f);
		glVertex3f( 0.5f, -0.5f, -0.5f);
		glVertex3f( 0.5f, -0.5f,  0.5f);
	glEnd();
}

To show the effects of z-fighting, we will be displaying some polygons on top of a cube. A drawPolygon function has therefore been created to simplify creation of multiple quads.

				void drawPolygon()
{
	glBegin(GL_QUADS);
		glVertex3f(-0.5f, -0.5f,  0.0f);
		glVertex3f( 0.5f, -0.5f,  0.0f);
		glVertex3f( 0.5f,  0.5f,  0.0f);
		glVertex3f(-0.5f,  0.5f,  0.0f);
	glEnd();
}

The beginning of our display function remains the same.

				void display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	gluLookAt(
		0.0f, 0.0f, 3.0f,
		0.0f, 0.0f, 0.0f,
		0.0f, 1.0f, 0.0f);

	glRotatef(xrot, 1.0f, 0.0f, 0.0f);
	glRotatef(yrot, 0.0f, 1.0f, 0.0f);

The object we will be creating can be seen at the beginning of this tutorial. It is a red cube, outlined by a black line. The one side of the red cube has 3 overlapping polygons on top of it.

Polygon offsets can be used in a number of ways to reduce the errors caused by these overlapping primitives. One possible solution is to offset the polygons of the cube to make it slightly smaller. This will allow the lines and additional polygons from being rendered without interfering with the cube.

There are three different ways to enable polygon offset, one for each rasterization mode (GL_POINT, GL_LINE and GL_FILL). This is specified by a single call to glEnable with one of the parameters, GL_POLYGON_OFFSET_POINT, GL_POLYGON_OFFSET_LINE and GL_POLYGON_OFFSET_FILL respectively.

The cube will first be rendered, so we pass the GL_POLYGON_OFFSET_FILL flag onto the glEnable function.

				if (offset)
	{
		glEnable(GL_POLYGON_OFFSET_FILL);

It is necessary to specify how much a polygon must be offset. This is achieved with a call to the glPolygonOffset function. This function accepts 2 parameters, GLfloatfactor and GLfloatunits.

The depth value of each fragment is added to an offset value which is calculate in the following way?:

offset = (m * factor) + (r * units)

where m is the maximum depth slope of the polygon and r is the smallest value guaranteed to produce a resolvable difference in window coordinate depth values. The value r is an implementation-specific constant.

A positive offset will push the object away from you whereas a negative offset will pull the object towards you.

The depth slope is the change in z (depth) value divided by the change in either x or y coordinates as you traverse the polygon. Therefore, polygons that are parallel to the near and far clipping planes will have a depth slope of zero. The closer the depth slope is to 0, the smaller the offset needs to be.

There is quite a bit of maths involved but luckily it is often good enough to simply use values such as 1.0 or 0.0 for the factor and units parameters, which is what we will be doing in this tutorial. As we want the polygons of the cube to be pushed away from us, we pass positive 1 as both parameters to glPolygonOffset.

				glPolygonOffset(1.0f, 1.0f);
	}

The cube is then rendered as per normal in the GL_FILL rasterization mode. After this has been done, polygon offset is disabled.

				glColor3f(1.0f, 0.0f, 0.0f);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	drawBox();

	if (offset)
		glDisable(GL_POLYGON_OFFSET_FILL);

The green and yellow polygons on the front of the cube can now be rendered without worrying about z-fighting.

				glColor3f(0.0f, 1.0f, 0.0f);
	glPushMatrix();
		glTranslatef(-0.25f, -0.25f, 0.5f);
		glScalef(0.5f, 0.5f, 0.5f);
		drawPolygon();
	glPopMatrix();

	glColor3f(1.0f, 1.0f, 0.0f);
	glPushMatrix();
		glTranslatef(0.25f, 0.25f, 0.5f);
		glScalef(0.5f, 0.5f, 0.5f);
		drawPolygon();
	glPopMatrix();

If we now try to render the blue polygon, it will cause z-fighting with the green and yellow polygons on the front of the cube.

A way around this is to pull the blue polygon towards us to prevent z-fighting with both the cube and the front polygons. This is done by passing -1 as both parameters to the glPolygonOffset function.

				if (offset)
	{
		glEnable(GL_POLYGON_OFFSET_FILL);
		glPolygonOffset(-1.0f, -1.0f);
	}

	glColor3f(0.0f, 0.0f, 1.0f);
	glPushMatrix();
		glTranslatef(0.0f, 0.0f, 0.5f);
		glScalef(0.5f, 0.5f, 0.5f);
		drawPolygon();
	glPopMatrix();

	if (offset)
		glDisable(GL_POLYGON_OFFSET_FILL);

If we were to now render the outline of the cube, stitching would occur with the front polygons. The lines can therefore be pulled towards us in the same way that the blue polygon was. The only difference is that now we need to pass GL_POLYGON_OFFSET_LINE onto the glEnable function instead.

				if (offset)
	{
		glEnable(GL_POLYGON_OFFSET_LINE);
		glPolygonOffset(-1.0f, -1.0f);
	}

	glColor3f(0.0f, 0.0f, 0.0f);
	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	drawBox();

	if (offset)
		glDisable(GL_POLYGON_OFFSET_LINE);
		
	glFlush();
}

Our idle function remains the same except that now polygon offset can be toggled on and off by pressing the O key.

				void idle()
{
	.
	.

	if (opengl->isKeyDown('O'))
	{
		opengl->keyUp('O');
		offset = !offset;
	}
}

By enabling and disabling polygon offset, you can clearly see how it affects your program. The result is shown below?:

Orthographic View Perspective View
Polygon Offset Enabled Polygon Offset Disabled

You should now be able to effectively combat z-buffering and stitching. This is a great feature of OpenGL and can be used to greatly enhance the appearance of your application.

Please let me know of any comments you may have : Contact Me

Win32?Source?Files?: Visual Studio Dev-C++
GLUT?Source?Files?: Visual Studio Dev-C++ Unix / Linux

posted on 2006-11-16 11:48 zmj 閱讀(2504) 評論(0)  編輯 收藏 引用

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            99精品热视频只有精品10| 亚洲图片欧美日产| 久久久999精品| 亚洲性人人天天夜夜摸| 亚洲香蕉网站| 亚洲欧美视频在线观看| 亚洲新中文字幕| 一区二区三区视频在线播放| 亚洲激情av| 亚洲高清三级视频| 亚洲黄色影院| 国产精品成人观看视频免费| 亚洲国产一区二区视频 | 国产精品午夜在线观看| 免费成人在线观看视频| 久久精品国产一区二区三| 性欧美暴力猛交另类hd| 午夜精品影院在线观看| 久久精品人人做人人爽| 欧美不卡在线| 国产精品亚洲第一区在线暖暖韩国| 黑人一区二区| 亚洲视频综合在线| 欧美xx视频| 亚洲欧美日本日韩| 欧美国产视频一区二区| 国产日韩欧美在线观看| 99精品国产福利在线观看免费| 午夜精品视频一区| 亚洲高清视频在线| 欧美在线视频一区二区| 欧美日韩国产区| 亚洲国产成人久久| 久久久久综合一区二区三区| 夜夜爽夜夜爽精品视频| 久久久欧美一区二区| 国产精品青草久久| 亚洲精品乱码久久久久久按摩观| 亚洲欧美综合v| 日韩一级精品视频在线观看| 久久影视三级福利片| 欧美日韩性生活视频| 影音先锋亚洲精品| 久久激情一区| 亚洲免费视频在线观看| 欧美日韩三级在线| 一区二区三区精品久久久| 欧美国产日韩一区二区| 久久国产色av| 国产一区视频在线看| 亚洲欧美国产视频| 夜色激情一区二区| 欧美日韩免费观看中文| 日韩午夜免费视频| 亚洲国产一区二区a毛片| 蜜臀av在线播放一区二区三区| 激情欧美国产欧美| 久久综合给合久久狠狠色 | 欧美成人视屏| 久久久精品午夜少妇| 狠狠色丁香久久综合频道| 久久久久.com| 久久婷婷国产综合精品青草| 国产综合色在线视频区| 久久伊人精品天天| 男人插女人欧美| 亚洲精品美女在线观看| 亚洲国产欧美一区二区三区久久| 欧美一区二区视频97| 午夜精品福利一区二区三区av| 欧美三级日韩三级国产三级| 99国产精品| 99re视频这里只有精品| 欧美日韩免费高清一区色橹橹| 亚洲桃花岛网站| 一本久道久久综合婷婷鲸鱼| 欧美日韩在线直播| 西瓜成人精品人成网站| 小嫩嫩精品导航| 欧美日韩国产色综合一二三四| 国产在线视频欧美| 亚洲欧美国产视频| 亚洲一区日韩| 午夜精品久久久久久99热软件| 国产亚洲一区二区精品| 久久久久久久综合日本| 久久深夜福利免费观看| 亚洲精品国产精品久久清纯直播| 亚洲精品国产无天堂网2021| 国产精品美女久久久久久2018| 久久精品中文字幕免费mv| 久久亚洲春色中文字幕| 一本久久综合| 欧美伊久线香蕉线新在线| 亚洲欧洲一区二区三区久久| 一区二区免费在线视频| 狠狠色丁香婷婷综合影院| 亚洲精品亚洲人成人网| 国产一区二区三区高清播放| 亚洲日本成人| 国产一区成人| 夜夜精品视频一区二区| 好吊色欧美一区二区三区视频| 亚洲国产欧美一区| 韩国欧美国产1区| av不卡在线看| 亚洲国产精品热久久| 亚洲一区二区三区乱码aⅴ蜜桃女 亚洲一区二区三区乱码aⅴ | 亚洲视频在线播放| 曰本成人黄色| 亚洲一区二区三区四区在线观看| 亚洲国产高清自拍| 欧美一级午夜免费电影| 亚洲午夜影视影院在线观看| 欧美77777| 麻豆freexxxx性91精品| 国产精品色婷婷久久58| 亚洲精品久久久久久久久久久久久| 国产日韩综合| 亚洲香蕉视频| 亚洲一区二区三区视频| 欧美另类变人与禽xxxxx| 久久精品免费播放| 国产精品男女猛烈高潮激情| 亚洲人屁股眼子交8| 亚洲激情亚洲| 国产精品乱码久久久久久| 亚洲毛片在线看| 久久精品91久久久久久再现| 午夜精品久久| 国产精品久久久亚洲一区| 亚洲欧洲精品一区二区三区| 亚洲国产精品www| 久久在线91| 亚洲国产精品成人一区二区| 亚洲国产一区视频| 麻豆91精品| 欧美国产丝袜视频| 91久久精品一区二区三区| 欧美电影在线免费观看网站| 免费成人在线视频网站| 影音先锋国产精品| 久久综合福利| 亚洲国产精品激情在线观看| 亚洲国产三级在线| 欧美国产日产韩国视频| 亚洲精品国产精品国自产观看浪潮| 日韩一级黄色片| 国产精品久久久久久久免费软件| 亚洲淫片在线视频| 玖玖玖国产精品| 亚洲精选一区| 国产精品乱子久久久久| 欧美一区二区日韩一区二区| 久久中文字幕一区| 一区二区成人精品| 国产日产高清欧美一区二区三区| 久久精品人人爽| 亚洲免费成人av| 久久久999精品| 亚洲精品美女久久7777777| 国产精品国产三级国产| 久久国产精品72免费观看| 亚洲丰满在线| 欧美一区激情| 日韩视频中文字幕| 国产啪精品视频| 欧美激情精品久久久久久变态| 99视频精品全国免费| 久久久久久久久久看片| 日韩午夜精品| 国产亚洲午夜高清国产拍精品| 久久亚洲风情| 亚洲精品免费在线播放| 久久精品亚洲一区二区| 亚洲人体一区| 国产精品亚洲аv天堂网| 久久视频国产精品免费视频在线| 一区二区三区不卡视频在线观看| 久久久精品国产99久久精品芒果| 亚洲日本乱码在线观看| 这里是久久伊人| 欧美成人精品不卡视频在线观看 | 欧美精品18| 午夜精品久久久久99热蜜桃导演| 欧美成人一区二区在线| 欧美制服第一页| 中文在线资源观看网站视频免费不卡 | 欧美一级片一区| 亚洲黄色免费网站| 久久亚洲精品一区| 欧美性猛交视频| 久久字幕精品一区| 亚洲视频专区在线| 亚洲第一黄网| 国产日韩一区| 亚洲福利在线看| 老司机aⅴ在线精品导航| 久久久久五月天| 亚洲一区二区三区免费在线观看|