# Gl\_clamp\_to\_border

**URL:** <https://discourse.processing.org/t/gl-clamp-to-border/43933>\
**Category:** Gallery\
**Created:** [February 17, 2024, 10:22pm UTC](https://discourse.processing.org/t/gl-clamp-to-border/43933 "2024-02-17T22:22:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![clankill3r](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/clankill3r/32/1098_2.png) [@clankill3r](https://discourse.processing.org/u/clankill3r)\
**Post date:** [February 17, 2024, 10:22pm UTC](https://discourse.processing.org/t/gl-clamp-to-border/43933/1 "2024-02-17T22:22:51Z")

</div>

I needed GL\_CLAMP\_TO\_BORDER to work and I thought I share it since it might help someone (me?) in the future.

```java
package glsl_blobscanner;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import processing.core.*;
import processing.opengl.*;

public class GL_CLAMP_TO_BORDER extends PApplet{
    
public static void main(String[] args) {
    PApplet.main(GL_CLAMP_TO_BORDER.class, args);
}

PImage source;

int GL_CLAMP_TO_BORDER = 0x812D;
int GL_TEXTURE_BORDER_COLOR = 0x1004;

PGL pgl;

public void settings() {
    size(512, 512, P2D);
}

public void setup() {

    source = loadImage("debug_05_32x32.png");
    pgl = beginPGL();
    
}

public void draw() {
    background(255);

    Texture source_tex = ((PGraphicsOpenGL)g).getTexture(source);
    source_tex.usingRepeat(false);
    source_tex.bind();
    pgl.texParameteri(source_tex.glTarget, PGL.TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
    pgl.texParameteri(source_tex.glTarget, PGL.TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
    
    float borderColor[] = { 1.0f, 1.0f, 0.0f, 1.0f };
    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(borderColor.length * Float.BYTES);
    byteBuffer.order(ByteOrder.nativeOrder()); // Use the native byte order
    FloatBuffer floatBuffer = byteBuffer.asFloatBuffer();
    floatBuffer.put(borderColor);
    floatBuffer.flip();

    pgl.texParameterfv(source_tex.glTarget, GL_TEXTURE_BORDER_COLOR, floatBuffer); 
    
    source_tex.unbind();

    beginShape();
    texture(source);
    textureMode(NORMAL);
    vertex(64, 64, -0.5f, -0.5f);
    vertex(width-64, 64, 1.5f, -0.5f);
    vertex(width-64, height-64, 1.5f, 1.5f);
    vertex(64, height-64, -0.5f, 1.5f);
    endShape();
}

}

```
