# How to get GL\_CLAMP\_TO\_BORDER effect?

**URL:** <https://community.khronos.org/t/how-to-get-gl-clamp-to-border-effect/104085>\
**Category:** OpenGL: Basic Coding\
**Created:** [May 29, 2019, 2:39pm UTC](https://community.khronos.org/t/how-to-get-gl-clamp-to-border-effect/104085 "2019-05-29T14:39:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![HistogramOfLaplace](https://community.khronos.org/letter_avatar_proxy/v4/letter/h/43a26b/32.png) [@HistogramOfLaplace](https://community.khronos.org/u/HistogramOfLaplace)\
**Post date:** [May 29, 2019, 2:39pm UTC](https://community.khronos.org/t/how-to-get-gl-clamp-to-border-effect/104085/1 "2019-05-29T14:39:00Z")

</div>

![image](https://community.khronos.org/uploads/default/original/2X/a/ac8e50049bb324cb900000b290c798947938fc94.png)

Hi All,

I am very new to OpenGL and for an application I am loading images as textures. One issue I am having is that I get this undesired ‘GL\_CLAMP\_TO\_EDGE’ result (please look at attachment) when zooming out of my texture. The ‘GL\_CLAMP\_TO\_BORDER’ result is exactly what I need but it is no longer in OpenGL. Does anyone know how I can achieve this?

---

<div class="post-metadata">

**Author:** ![Alfonse\_Reinheart](https://community.khronos.org/user_avatar/community.khronos.org/alfonse_reinheart/32/4357_2.png) [@Alfonse\_Reinheart](https://community.khronos.org/u/Alfonse_Reinheart)\
**Post date:** [May 29, 2019, 2:46pm UTC](https://community.khronos.org/t/how-to-get-gl-clamp-to-border-effect/104085/2 "2019-05-29T14:46:02Z")

</div>

`GL_CLAMP_TO_BORDER` has never been removed; [that clamps to the border color](https://www.khronos.org/opengl/wiki/Sampler_Object#Edge_value_sampling). It’s `GL_CLAMP` (which clamped to the border _texels_) which was removed, since border texels no longer exist.

---

<div class="post-metadata">

**Author:** ![HistogramOfLaplace](https://community.khronos.org/letter_avatar_proxy/v4/letter/h/43a26b/32.png) [@HistogramOfLaplace](https://community.khronos.org/u/HistogramOfLaplace)\
**Post date:** [May 29, 2019, 2:51pm UTC](https://community.khronos.org/t/how-to-get-gl-clamp-to-border-effect/104085/3 "2019-05-29T14:51:07Z")

</div>

Thanks for getting back.

These are my texture parameters:

```
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //read outside texture width (clamping method)
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //read outside texture height(clamping method)

```

Is it possible for me to get the desired effect I need through adjusting parameters on here?

---

<div class="post-metadata">

**Author:** ![GClements](https://community.khronos.org/letter_avatar_proxy/v4/letter/g/e0b2c6/32.png) [@GClements](https://community.khronos.org/u/GClements)\
**Post date:** [May 29, 2019, 2:59pm UTC](https://community.khronos.org/t/how-to-get-gl-clamp-to-border-effect/104085/4 "2019-05-29T14:59:10Z")

</div>

Are you using OpenGL ES, which has `GL_CLAMP_TO_EDGE` but lacks `GL_CLAMP_TO_BORDER` (and in fact lacks border colours altogether)?

If you are, you’ll have to implement this in the fragment shader: check whether either texture coordinate lies outside the range [0,1] and if so, use a colour read from a uniform variable in place of the value sampled from the texture. If you’re using mipmaps, note that the texture() call needs to be outside of the conditional in order for implicit derivatives (required for mipmap level selection) to be calculated correctly.

If you’re using desktop OpenGL, just use `GL_CLAMP_TO_BORDER` instead of `GL_CLAMP`, and use `glTexParameter(GL_TEXTURE_BORDER_COLOR)` to set the border colour.

---

<div class="post-metadata">

**Author:** ![Alfonse\_Reinheart](https://community.khronos.org/user_avatar/community.khronos.org/alfonse_reinheart/32/4357_2.png) [@Alfonse\_Reinheart](https://community.khronos.org/u/Alfonse_Reinheart)\
**Post date:** [May 29, 2019, 3:01pm UTC](https://community.khronos.org/t/how-to-get-gl-clamp-to-border-effect/104085/5 "2019-05-29T15:01:22Z")

</div>

> [@HistogramOfLaplace](#):
>
> Is it possible for me to get the desired effect I need through adjusting parameters on here?

Yes: you adjust `GL_CLAMP` to `GL_CLAMP_TO_BORDER`.

---

<div class="post-metadata">

**Author:** ![HistogramOfLaplace](https://community.khronos.org/letter_avatar_proxy/v4/letter/h/43a26b/32.png) [@HistogramOfLaplace](https://community.khronos.org/u/HistogramOfLaplace)\
**Post date:** [May 29, 2019, 3:04pm UTC](https://community.khronos.org/t/how-to-get-gl-clamp-to-border-effect/104085/6 "2019-05-29T15:04:08Z")

</div>

Thanks GClements, yes that was my issue I am not seeing GL\_CLAMP\_TO\_BORDER.  
I will try what you have mentioned.

---

<div class="post-metadata">

**Author:** ![arekkusu](https://community.khronos.org/user_avatar/community.khronos.org/arekkusu/32/66_2.png) [@arekkusu](https://community.khronos.org/u/arekkusu)\
**Post date:** [May 29, 2019, 5:07pm UTC](https://community.khronos.org/t/how-to-get-gl-clamp-to-border-effect/104085/7 "2019-05-29T17:07:12Z")

</div>

> [@Alfonse\_Reinheart](#):
>
> `GL_CLAMP` (which clamped to the border _texels_ )

Both CLAMP and CLAMP\_TO\_BORDER clamp to border texels (if they exist, else border color.) The difference is CLAMP [clamps the filter weight half-way into the border](http://www.bluevoid.com/opengl/sig99/advanced99/notes/node64.html).

For OpenGL ES there are NV, EXT, and OES [extensions](https://www.khronos.org/registry/OpenGL/index_es.php) restoring CLAMP\_TO\_BORDER.
