[question] texture handling in fragment shader

I make texture with glBindTexture.
How to send texture to uniform sampler2D variable?
and how to get current texel?

thanks for reading.

  public static void sendUniform1i(int id, String name, int value){
    int location =  getUniformLocation(id, name);
    if(checkGLError(location, name)== 0) return;

    ARBShaderObjects.glUniform1iARB(location, value);

  private static int getUniformLocation(int id, String name) {
    ByteBuffer buffer = BufferUtils.createByteBuffer(name.length() + 1);

    return ARBShaderObjects.glGetUniformLocationARB(id, buffer);
  private static int checkGLError(int location, String name){
    if(location == -1){
      System.out.println("Error: couldn't loacte " + name);
      return 0;
    return 1;
      GLShaders.sendUniform1i(appearance.getOGLSLShadersID(), "Bump", 0);
      GLShaders.sendUniform1i(appearance.getOGLSLShadersID(), "Base", 1);
      GLShaders.sendUniform1i(appearance.getOGLSLShadersID(), "Cube", 2);
uniform samplerCube Cube;
uniform sampler2D   Bump,
varying mat3        normalMatrix;
varying vec3        eyeVector;

void main()
  vec3 bump       = vec3(texture2D(Bump, vec2(gl_TexCoord[0]))* 2.0 - 1.0),
       normal     = normalize(normalMatrix*bump);

  vec3 reflection = normalize((2.0*dot(eyeVector, normal)*normal - eyeVector)); 
  vec4 base       = texture2D(Base, vec2(gl_TexCoord[0])),
       cube       = textureCube(Cube, reflection);

  gl_FragColor    = cube*base*1.6; 

I’m using Java as main development language for my projects so I’m not sure that helps you out in any form.
PS: to get a texture fragment color you use

vec4 color = texture2D(Base, vec2(gl_TexCoord[0]));

But don’t forget to pass the gl_TexCoord[n] in your vertex shader using

  gl_TexCoord[0] = gl_MultiTexCoord0;

Thank you for your kindness. Java Cool Dude.
Have a nice day. :slight_smile:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.