I obtain that effect simply with glColor… If you draw with glColor(1,1,1) you see your texture in the normal state and if you set glColor(1,1,0) before drawing your texture you’ll get the highlighted state…
package test;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLException;
import com.sun.opengl.util.Animator;
import com.sun.opengl.util.texture.Texture;
import com.sun.opengl.util.texture.TextureCoords;
import com.sun.opengl.util.texture.TextureIO;
public class Test {
Frame frame;
GLCanvas glCanvas;
Animator animator;
Texture texture;
TextureCoords coords;
float t;
public Test() {
glCanvas = new GLCanvas();
animator = new Animator(glCanvas);
frame = new Frame();
frame.add(glCanvas);
glCanvas.addGLEventListener(glel);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void showGui() {
frame.setBounds(100, 100, 400, 300);
frame.setVisible(true);
animator.start();
}
GLEventListener glel = new GLEventListener() {
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
}
@Override
public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnable(GL.GL_LINE_SMOOTH);
gl.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST);
gl.glEnable(GL.GL_POINT_SMOOTH);
gl.glHint(GL.GL_POINT_SMOOTH_HINT, GL.GL_NICEST);
gl.glEnable(GL.GL_POLYGON_SMOOTH);
gl.glHint(GL.GL_POLYGON_SMOOTH_HINT, GL.GL_NICEST);
gl.glLineWidth(0.3f);
try {
texture = TextureIO.newTexture(getClass().getResourceAsStream("img.png"), true, "png");
coords = texture.getImageTexCoords();
} catch (GLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
}
@Override
public void display(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
gl.glLoadIdentity();
gl.glOrtho(-3, 3, -2, 2, -1, 1);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
float blue = (float) (0.5 + Math.sin(t += 0.1));
if (blue < 0) {
blue = 0;
}
if (blue > 1) {
blue = 1;
}
texture.enable();
texture.bind();
gl.glColor3f(1, 1, blue); //set the yellow (when blue==0) or white (when blue==1)
gl.glBegin(GL.GL_QUADS);
gl.glTexCoord2f(coords.right(), coords.top());
gl.glVertex2f(1, 1);
gl.glTexCoord2f(coords.left(), coords.top());
gl.glVertex2f(-1, 1);
gl.glTexCoord2f(coords.left(), coords.bottom());
gl.glVertex2f(-1, -1);
gl.glTexCoord2f(coords.right(), coords.bottom());
gl.glVertex2f(1, -1);
gl.glEnd();
texture.disable();
}
};
public static void main(String[] args) {
new Test().showGui();
}
}