C++ opengl 纹理过滤之GL_CLAMP

源码还是这样,把背景改下:

https://blog.csdn.net/qq78442761/article/details/81228557

采用GL_CLAMP方式过滤时大于1.0的所有的纹理坐标,会取纹理坐标为1.0上的纹理颜色

源码如下:

void Draw() {
	glClearColor(0.1f, 0.4f, 0.6f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);
	glEnable(GL_TEXTURE_2D);	//开启2D纹理
	glBindTexture(GL_TEXTURE_2D, texture);//将当前纹理设置为新创建的纹理对象
	glBegin(GL_QUADS);
	glColor4ub(255, 255, 255, 255);
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-0.1f, -0.1f, -0.4f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(0.1f, -0.1f, -0.4f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(0.1f, 0.1f, -0.4f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(-0.1f, 0.1f, -0.4f);
	glEnd();
}

运行截图如下:

C++ opengl 纹理过滤之GL_CLAMP_第1张图片

当修改纹理坐标后,如下图:

C++ opengl 纹理过滤之GL_CLAMP_第2张图片

源码如下:

void Draw() {
	glClearColor(0.1f, 0.4f, 0.6f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);
	glEnable(GL_TEXTURE_2D);	//开启2D纹理
	glBindTexture(GL_TEXTURE_2D, texture);//将当前纹理设置为新创建的纹理对象
	glBegin(GL_QUADS);
	glColor4ub(255, 255, 255, 255);
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-0.1f, -0.1f, -0.4f);
	glTexCoord2f(2.0f, 0.0f);
	glVertex3f(0.1f, -0.1f, -0.4f);
	glTexCoord2f(2.0f, 2.0f);
	glVertex3f(0.1f, 0.1f, -0.4f);
	glTexCoord2f(0.0f, 2.0f);
	glVertex3f(-0.1f, 0.1f, -0.4f);
	glEnd();
}

 

采用GL_CLAMP方式过滤时大于1.0的所有的纹理坐标,会取纹理坐标为1.0上的纹理颜色

你可能感兴趣的:(C/C++,OpenGL)