Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package volvis;
- import com.jogamp.opengl.GL;
- import com.jogamp.opengl.GL2;
- import com.jogamp.opengl.util.texture.Texture;
- import com.jogamp.opengl.util.texture.awt.AWTTextureIO;
- import gui.RaycastRendererPanel;
- import gui.TransferFunction2DEditor;
- import gui.TransferFunctionEditor;
- import java.awt.image.BufferedImage;
- import util.TFChangeListener;
- import util.VectorMath;
- import volume.GradientVolume;
- import volume.Volume;
- import volume.VoxelGradient;
- /**
- *
- * @author michel
- */
- public class RaycastRenderer extends Renderer implements TFChangeListener {
- private Volume volume = null;
- private GradientVolume gradients = null;
- public static int renderingMethod = 0;
- RaycastRendererPanel panel;
- TransferFunction tFunc;
- TransferFunctionEditor tfEditor;
- TransferFunction2DEditor tfEditor2D;
- public RaycastRenderer() {
- panel = new RaycastRendererPanel(this);
- panel.setSpeedLabel("0");
- }
- public void setVolume(Volume vol) {
- System.out.println("Assigning volume");
- volume = vol;
- System.out.println("Computing gradients");
- gradients = new GradientVolume(vol);
- // set up image for storing the resulting rendering
- // the image width and height are equal to the length of the volume diagonal
- int imageSize = (int) Math.floor(Math.sqrt(vol.getDimX() * vol.getDimX() + vol.getDimY() * vol.getDimY()
- + vol.getDimZ() * vol.getDimZ()));
- if (imageSize % 2 != 0) {
- imageSize = imageSize + 1;
- }
- image = new BufferedImage(imageSize, imageSize, BufferedImage.TYPE_INT_ARGB);
- // create a standard TF where lowest intensity maps to black, the highest to white, and opacity increases
- // linearly from 0.0 to 1.0 over the intensity range
- tFunc = new TransferFunction(volume.getMinimum(), volume.getMaximum());
- // uncomment this to initialize the TF with good starting values for the orange dataset
- tFunc.setTestFunc();
- tFunc.addTFChangeListener(this);
- tfEditor = new TransferFunctionEditor(tFunc, volume.getHistogram());
- tfEditor2D = new TransferFunction2DEditor(volume, gradients);
- tfEditor2D.addTFChangeListener(this);
- System.out.println("Finished initialization of RaycastRenderer");
- }
- public RaycastRendererPanel getPanel() {
- return panel;
- }
- public TransferFunction2DEditor getTF2DPanel() {
- return tfEditor2D;
- }
- public TransferFunctionEditor getTFPanel() {
- return tfEditor;
- }
- /*
- Get voxel using floor
- */
- short getVoxel(double[] coord) {
- if (coord[0] <= 0 || coord[0] > volume.getDimX() || coord[1] <= 0 || coord[1] >= volume.getDimY()
- || coord[2] <= 0 || coord[2] > volume.getDimZ()) {
- return 0;
- }
- int x = (int) Math.floor(coord[0]);
- int y = (int) Math.floor(coord[1]);
- int z = (int) Math.floor(coord[2]);
- return volume.getVoxel(x, y, z);
- }
- /*
- Get voxel using linear interpolation
- */
- double getVoxelInterpolatedGivenVolume(double[] coord, Volume volume) {
- if (coord[0] <= 0 || coord[0] >= volume.getDimX() || coord[1] <= 0 || coord[1] >= volume.getDimY()
- || coord[2] <= 0 || coord[2] >= volume.getDimZ()) {
- return 0;
- }
- int x_floor = Math.max((int) Math.floor(coord[0]), 0);
- int x_ceil = Math.min((int) Math.ceil(coord[0]), volume.getDimX()-1);
- int y_floor = Math.max((int) Math.floor(coord[1]), 0);
- int y_ceil = Math.min((int) Math.ceil(coord[1]), volume.getDimY()-1);
- int z_floor = Math.max((int) Math.floor(coord[2]), 0);
- int z_ceil = Math.min((int) Math.ceil(coord[2]), volume.getDimZ()-1);
- short s0 = volume.getVoxel(x_floor, y_floor, z_floor);
- short s1 = volume.getVoxel(x_ceil, y_floor, z_floor);
- short s2 = volume.getVoxel(x_floor, y_ceil, z_floor);
- short s3 = volume.getVoxel(x_ceil, y_ceil, z_floor);
- short s4 = volume.getVoxel(x_floor, y_floor, z_ceil);
- short s5 = volume.getVoxel(x_ceil, y_floor, z_ceil);
- short s6 = volume.getVoxel(x_floor, y_ceil, z_ceil);
- short s7 = volume.getVoxel(x_ceil, y_ceil, z_ceil);
- double alpha = (coord[0] - x_floor)/(x_ceil - x_floor);
- double beta = (coord[1] - y_floor)/(y_ceil - y_floor);
- double gamma = (coord[2] - z_floor)/(z_ceil - z_floor);
- return (1 - alpha)*(1 - beta)*(1-gamma)*s0
- + alpha*(1 - beta)*(1 - gamma)*s1
- + (1 - alpha)*beta*(1 - gamma)*s2
- + alpha*beta*(1 - gamma) * s3
- + (1 - alpha)*(1 - beta)*gamma*s4
- + alpha*(1 - beta) * gamma * s5
- + (1 - alpha)*beta*gamma*s6
- + alpha*beta*gamma*s7;
- }
- void slicer(double[] viewMatrix) {
- // clear image
- for (int j = 0; j < image.getHeight(); j++) {
- for (int i = 0; i < image.getWidth(); i++) {
- image.setRGB(i, j, 0);
- }
- }
- // vector uVec and vVec define a plane through the origin,
- // perpendicular to the view vector viewVec
- double[] viewVec = new double[3];
- double[] uVec = new double[3];
- double[] vVec = new double[3];
- VectorMath.setVector(viewVec, viewMatrix[2], viewMatrix[6], viewMatrix[10]);
- VectorMath.setVector(uVec, viewMatrix[0], viewMatrix[4], viewMatrix[8]);
- VectorMath.setVector(vVec, viewMatrix[1], viewMatrix[5], viewMatrix[9]);
- // image is square
- int imageCenter = image.getWidth() / 2;
- double[] pixelCoord = new double[3];
- double[] volumeCenter = new double[3];
- VectorMath.setVector(volumeCenter, volume.getDimX() / 2, volume.getDimY() / 2, volume.getDimZ() / 2);
- // sample on a plane through the origin of the volume data
- double max = volume.getMaximum();
- TFColor voxelColor = new TFColor();
- for (int j = 0; j < image.getHeight(); j++) {
- for (int i = 0; i < image.getWidth(); i++) {
- pixelCoord[0] = uVec[0] * (i - imageCenter) + vVec[0] * (j - imageCenter)
- + volumeCenter[0];
- pixelCoord[1] = uVec[1] * (i - imageCenter) + vVec[1] * (j - imageCenter)
- + volumeCenter[1];
- pixelCoord[2] = uVec[2] * (i - imageCenter) + vVec[2] * (j - imageCenter)
- + volumeCenter[2];
- int val = getVoxel(pixelCoord);
- // Map the intensity to a grey value by linear scaling
- voxelColor.r = val/max;
- voxelColor.g = voxelColor.r;
- voxelColor.b = voxelColor.r;
- voxelColor.a = val > 0 ? 1.0 : 0.0; // this makes intensity 0 completely transparent and the rest opaque
- // Alternatively, apply the transfer function to obtain a color
- // voxelColor = tFunc.getColor(val);
- // BufferedImage expects a pixel color packed as ARGB in an int
- int c_alpha = voxelColor.a <= 1.0 ? (int) Math.floor(voxelColor.a * 255) : 255;
- int c_red = voxelColor.r <= 1.0 ? (int) Math.floor(voxelColor.r * 255) : 255;
- int c_green = voxelColor.g <= 1.0 ? (int) Math.floor(voxelColor.g * 255) : 255;
- int c_blue = voxelColor.b <= 1.0 ? (int) Math.floor(voxelColor.b * 255) : 255;
- int pixelColor = (c_alpha << 24) | (c_red << 16) | (c_green << 8) | c_blue;
- image.setRGB(i, j, pixelColor);
- }
- }
- }
- void mip(double[] viewMatrix) {
- // clear image
- for (int j = 0; j < image.getHeight(); j++) {
- for (int i = 0; i < image.getWidth(); i++) {
- image.setRGB(i, j, 0);
- }
- }
- if (!interactiveMode){
- // vector uVec and vVec define a plane through the origin,
- // perpendicular to the view vector viewVec
- double[] viewVec = new double[3];
- double[] uVec = new double[3];
- double[] vVec = new double[3];
- VectorMath.setVector(viewVec, viewMatrix[2], viewMatrix[6], viewMatrix[10]);
- VectorMath.setVector(uVec, viewMatrix[0], viewMatrix[4], viewMatrix[8]);
- VectorMath.setVector(vVec, viewMatrix[1], viewMatrix[5], viewMatrix[9]);
- // image is square
- int imageCenter = image.getWidth() / 2;
- double[] pixelCoord = new double[3];
- double[] volumeCenter = new double[3];
- VectorMath.setVector(volumeCenter, volume.getDimX() / 2, volume.getDimY() / 2, volume.getDimZ() / 2);
- // sample on a plane through the origin of the volume data
- double max = volume.getMaximum();
- TFColor voxelColor = new TFColor();
- for (int j = 0; j < image.getHeight(); j++) {
- for (int i = 0; i < image.getWidth(); i++) {
- int val = 0;
- int maxVal = 0;
- for (int d = -100; d
- < 100; d = d + 2) {
- pixelCoord[0] = d * viewVec[0] + uVec[0] * (i - imageCenter) + vVec[0] * (j - imageCenter)
- + volumeCenter[0];
- pixelCoord[1] = d * viewVec[1] + uVec[1] * (i - imageCenter) + vVec[1] * (j - imageCenter)
- + volumeCenter[1];
- pixelCoord[2] = d * viewVec[2] + uVec[2] * (i - imageCenter) + vVec[2] * (j - imageCenter)
- + volumeCenter[2];
- maxVal = Math.max((int) Math.ceil(getVoxelInterpolatedGivenVolume(pixelCoord, volume)), maxVal);
- }
- val = maxVal;
- // Map the intensity to a grey value by linear scaling
- voxelColor.r = val / max;
- voxelColor.g = voxelColor.r;
- voxelColor.b = voxelColor.r;
- voxelColor.a = val > 0 ? 1.0 : 0.0; // this makes intensity 0 completely transparent and the rest opaque
- // Alternatively, apply the transfer function to obtain a color
- // voxelColor = tFunc.getColor(val);
- // BufferedImage expects a pixel color packed as ARGB in an int
- int c_alpha = voxelColor.a <= 1.0 ? (int) Math.floor(voxelColor.a * 255) : 255;
- int c_red = voxelColor.r <= 1.0 ? (int) Math.floor(voxelColor.r * 255) : 255;
- int c_green = voxelColor.g <= 1.0 ? (int) Math.floor(voxelColor.g * 255) : 255;
- int c_blue = voxelColor.b <= 1.0 ? (int) Math.floor(voxelColor.b * 255) : 255;
- int pixelColor = (c_alpha << 24) | (c_red << 16) | (c_green << 8) | c_blue;
- image.setRGB(i, j, pixelColor);
- }
- }
- }
- }
- void composite(double[] viewMatrix) {
- // clear image
- for (int j = 0; j < image.getHeight(); j++) {
- for (int i = 0; i < image.getWidth(); i++) {
- image.setRGB(i, j, 0);
- }
- }
- if (!interactiveMode){
- // vector uVec and vVec define a plane through the origin,
- // perpendicular to the view vector viewVec
- double[] viewVec = new double[3];
- double[] uVec = new double[3];
- double[] vVec = new double[3];
- VectorMath.setVector(viewVec, viewMatrix[2], viewMatrix[6], viewMatrix[10]);
- VectorMath.setVector(uVec, viewMatrix[0], viewMatrix[4], viewMatrix[8]);
- VectorMath.setVector(vVec, viewMatrix[1], viewMatrix[5], viewMatrix[9]);
- // image is square
- int imageCenter = image.getWidth() / 2;
- double[] pixelCoord = new double[3];
- double[] volumeCenter = new double[3];
- VectorMath.setVector(volumeCenter, volume.getDimX() / 2, volume.getDimY() / 2, volume.getDimZ() / 2);
- TFColor voxelColor = new TFColor();
- for (int j = 0; j < image.getHeight(); j++) {
- for (int i = 0; i < image.getWidth(); i++) {
- double Cr = 0;
- double Cg = 0;
- double Cb = 0;
- for (int d = -100; d
- < 100; d = d + 2) {
- pixelCoord[0] = d * viewVec[0] + uVec[0] * (i - imageCenter) + vVec[0] * (j - imageCenter)
- + volumeCenter[0];
- pixelCoord[1] = d * viewVec[1] + uVec[1] * (i - imageCenter) + vVec[1] * (j - imageCenter)
- + volumeCenter[1];
- pixelCoord[2] = d * viewVec[2] + uVec[2] * (i - imageCenter) + vVec[2] * (j - imageCenter)
- + volumeCenter[2];
- int thisVal = (int) Math.ceil(getVoxelInterpolatedGivenVolume(pixelCoord, volume));
- TFColor ci = tFunc.getColor(thisVal);
- Cr = ci.a * ci.r + (1 - ci.a) * Cr;
- Cg = ci.a * ci.g + (1 - ci.a) * Cg;
- Cb = ci.a * ci.b + (1 - ci.a) * Cb;
- }
- voxelColor.r = Cr;
- voxelColor.g = Cg;
- voxelColor.b = Cb;
- voxelColor.a = 100;
- // BufferedImage expects a pixel color packed as ARGB in an int
- int c_alpha = voxelColor.a <= 1.0 ? (int) Math.floor(voxelColor.a * 255) : 255;
- int c_red = voxelColor.r <= 1.0 ? (int) Math.floor(voxelColor.r * 255) : 255;
- int c_green = voxelColor.g <= 1.0 ? (int) Math.floor(voxelColor.g * 255) : 255;
- int c_blue = voxelColor.b <= 1.0 ? (int) Math.floor(voxelColor.b * 255) : 255;
- int pixelColor = (c_alpha << 24) | (c_red << 16) | (c_green << 8) | c_blue;
- image.setRGB(i, j, pixelColor);
- }
- }
- }
- }
- void twoDTransfer(double[] viewMatrix) {
- // clear image
- for (int j = 0; j < image.getHeight(); j++) {
- for (int i = 0; i < image.getWidth(); i++) {
- image.setRGB(i, j, 0);
- }
- }
- if (!interactiveMode){
- // vector uVec and vVec define a plane through the origin,
- // perpendicular to the view vector viewVec
- double[] viewVec = new double[3];
- double[] uVec = new double[3];
- double[] vVec = new double[3];
- VectorMath.setVector(viewVec, viewMatrix[2], viewMatrix[6], viewMatrix[10]);
- VectorMath.setVector(uVec, viewMatrix[0], viewMatrix[4], viewMatrix[8]);
- VectorMath.setVector(vVec, viewMatrix[1], viewMatrix[5], viewMatrix[9]);
- // image is square
- int imageCenter = image.getWidth() / 2;
- double[] pixelCoord = new double[3];
- double[] volumeCenter = new double[3];
- VectorMath.setVector(volumeCenter, volume.getDimX() / 2, volume.getDimY() / 2, volume.getDimZ() / 2);
- TFColor colorSetting = tfEditor2D.triangleWidget.color;
- double radius = tfEditor2D.triangleWidget.radius;
- double baseIntensity = tfEditor2D.triangleWidget.baseIntensity;
- System.out.println(radius);
- System.out.println(baseIntensity);
- System.out.println(colorSetting.a);
- TFColor voxelColor = new TFColor(0,0,0,255);
- for (int j = 0; j < image.getHeight(); j++) {
- for (int i = 0; i < image.getWidth(); i++) {
- voxelColor.a = 0;
- voxelColor.r = 0;
- voxelColor.g = 0;
- voxelColor.b = 0;
- for (int d = -100; d
- < 100; d = d + 1) {
- pixelCoord[0] = d * viewVec[0] + uVec[0] * (i - imageCenter) + vVec[0] * (j - imageCenter)
- + volumeCenter[0];
- pixelCoord[1] = d * viewVec[1] + uVec[1] * (i - imageCenter) + vVec[1] * (j - imageCenter)
- + volumeCenter[1];
- pixelCoord[2] = d * viewVec[2] + uVec[2] * (i - imageCenter) + vVec[2] * (j - imageCenter)
- + volumeCenter[2];
- if (pixelCoord[0] <= 0 || pixelCoord[0] >= volume.getDimX() || pixelCoord[1] <= 0 || pixelCoord[1] >= volume.getDimY()
- || pixelCoord[2] <= 0 || pixelCoord[2] >= volume.getDimZ()) {
- } else {
- VoxelGradient gradient;
- // Get the x,y and z coordinates for this sample
- int x = (int) pixelCoord[0];
- int y = (int) pixelCoord[1];
- int z = (int) pixelCoord[2];
- // Get the gradient for this voxel
- gradient = gradients.getGradient(x, y, z);
- // Get the intensity for this voxel
- double intensity = getVoxel(pixelCoord);
- // The factor that we apply to the gradient
- double alpha;
- // Maximum opacity
- if (gradient.mag == 0f && intensity == baseIntensity) {
- alpha = colorSetting.a;
- } else if (gradient.mag > 0 && (intensity - (radius * gradient.mag) <= baseIntensity) ||
- intensity + (radius * gradient.mag) >= baseIntensity) {
- alpha = colorSetting.a * (1d - (1d / radius) * Math.abs((baseIntensity - intensity) / (gradient.mag)));
- } else {
- alpha = 0;
- }
- voxelColor.r = voxelColor.r * (1 - alpha) + colorSetting.r * alpha;
- voxelColor.g = voxelColor.g * (1 - alpha) + colorSetting.g * alpha;
- voxelColor.b = voxelColor.b * (1 - alpha) + colorSetting.b * alpha;
- voxelColor.a = voxelColor.a * (1 - alpha) + alpha;
- }
- }
- // BufferedImage expects a pixel color packed as ARGB in an int
- int c_alpha = voxelColor.a <= 1.0 ? (int) Math.floor(voxelColor.a * 255) : 255;
- int c_red = voxelColor.r <= 1.0 ? (int) Math.floor(voxelColor.r * 255) : 255;
- int c_green = voxelColor.g <= 1.0 ? (int) Math.floor(voxelColor.g * 255) : 255;
- int c_blue = voxelColor.b <= 1.0 ? (int) Math.floor(voxelColor.b * 255) : 255;
- int pixelColor = (c_alpha << 24) | (c_red << 16) | (c_green << 8) | c_blue;
- image.setRGB(i, j, pixelColor);
- }
- }
- }
- }
- private void drawBoundingBox(GL2 gl) {
- gl.glPushAttrib(GL2.GL_CURRENT_BIT);
- gl.glDisable(GL2.GL_LIGHTING);
- gl.glColor4d(1.0, 1.0, 1.0, 1.0);
- gl.glLineWidth(1.5f);
- gl.glEnable(GL.GL_LINE_SMOOTH);
- gl.glHint(GL.GL_LINE_SMOOTH_HINT, GL.GL_NICEST);
- gl.glEnable(GL.GL_BLEND);
- gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
- gl.glBegin(GL.GL_LINE_LOOP);
- gl.glVertex3d(-volume.getDimX() / 2.0, -volume.getDimY() / 2.0, volume.getDimZ() / 2.0);
- gl.glVertex3d(-volume.getDimX() / 2.0, volume.getDimY() / 2.0, volume.getDimZ() / 2.0);
- gl.glVertex3d(volume.getDimX() / 2.0, volume.getDimY() / 2.0, volume.getDimZ() / 2.0);
- gl.glVertex3d(volume.getDimX() / 2.0, -volume.getDimY() / 2.0, volume.getDimZ() / 2.0);
- gl.glEnd();
- gl.glBegin(GL.GL_LINE_LOOP);
- gl.glVertex3d(-volume.getDimX() / 2.0, -volume.getDimY() / 2.0, -volume.getDimZ() / 2.0);
- gl.glVertex3d(-volume.getDimX() / 2.0, volume.getDimY() / 2.0, -volume.getDimZ() / 2.0);
- gl.glVertex3d(volume.getDimX() / 2.0, volume.getDimY() / 2.0, -volume.getDimZ() / 2.0);
- gl.glVertex3d(volume.getDimX() / 2.0, -volume.getDimY() / 2.0, -volume.getDimZ() / 2.0);
- gl.glEnd();
- gl.glBegin(GL.GL_LINE_LOOP);
- gl.glVertex3d(volume.getDimX() / 2.0, -volume.getDimY() / 2.0, -volume.getDimZ() / 2.0);
- gl.glVertex3d(volume.getDimX() / 2.0, -volume.getDimY() / 2.0, volume.getDimZ() / 2.0);
- gl.glVertex3d(volume.getDimX() / 2.0, volume.getDimY() / 2.0, volume.getDimZ() / 2.0);
- gl.glVertex3d(volume.getDimX() / 2.0, volume.getDimY() / 2.0, -volume.getDimZ() / 2.0);
- gl.glEnd();
- gl.glBegin(GL.GL_LINE_LOOP);
- gl.glVertex3d(-volume.getDimX() / 2.0, -volume.getDimY() / 2.0, -volume.getDimZ() / 2.0);
- gl.glVertex3d(-volume.getDimX() / 2.0, -volume.getDimY() / 2.0, volume.getDimZ() / 2.0);
- gl.glVertex3d(-volume.getDimX() / 2.0, volume.getDimY() / 2.0, volume.getDimZ() / 2.0);
- gl.glVertex3d(-volume.getDimX() / 2.0, volume.getDimY() / 2.0, -volume.getDimZ() / 2.0);
- gl.glEnd();
- gl.glBegin(GL.GL_LINE_LOOP);
- gl.glVertex3d(-volume.getDimX() / 2.0, volume.getDimY() / 2.0, -volume.getDimZ() / 2.0);
- gl.glVertex3d(-volume.getDimX() / 2.0, volume.getDimY() / 2.0, volume.getDimZ() / 2.0);
- gl.glVertex3d(volume.getDimX() / 2.0, volume.getDimY() / 2.0, volume.getDimZ() / 2.0);
- gl.glVertex3d(volume.getDimX() / 2.0, volume.getDimY() / 2.0, -volume.getDimZ() / 2.0);
- gl.glEnd();
- gl.glBegin(GL.GL_LINE_LOOP);
- gl.glVertex3d(-volume.getDimX() / 2.0, -volume.getDimY() / 2.0, -volume.getDimZ() / 2.0);
- gl.glVertex3d(-volume.getDimX() / 2.0, -volume.getDimY() / 2.0, volume.getDimZ() / 2.0);
- gl.glVertex3d(volume.getDimX() / 2.0, -volume.getDimY() / 2.0, volume.getDimZ() / 2.0);
- gl.glVertex3d(volume.getDimX() / 2.0, -volume.getDimY() / 2.0, -volume.getDimZ() / 2.0);
- gl.glEnd();
- gl.glDisable(GL.GL_LINE_SMOOTH);
- gl.glDisable(GL.GL_BLEND);
- gl.glEnable(GL2.GL_LIGHTING);
- gl.glPopAttrib();
- }
- @Override
- public void visualize(GL2 gl) {
- if (volume == null) {
- return;
- }
- drawBoundingBox(gl);
- gl.glGetDoublev(GL2.GL_MODELVIEW_MATRIX, viewMatrix, 0);
- long startTime = System.currentTimeMillis();
- switch(renderingMethod){
- case 0:
- slicer(viewMatrix);
- break;
- case 1:
- mip(viewMatrix);
- break;
- case 2:
- composite(viewMatrix);
- break;
- case 3:
- twoDTransfer(viewMatrix);
- break;
- default:
- slicer(viewMatrix);
- break;
- }
- long endTime = System.currentTimeMillis();
- double runningTime = (endTime - startTime);
- panel.setSpeedLabel(Double.toString(runningTime));
- Texture texture = AWTTextureIO.newTexture(gl.getGLProfile(), image, false);
- gl.glPushAttrib(GL2.GL_LIGHTING_BIT);
- gl.glDisable(GL2.GL_LIGHTING);
- gl.glEnable(GL.GL_BLEND);
- gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
- // draw rendered image as a billboard texture
- texture.enable(gl);
- texture.bind(gl);
- double halfWidth = image.getWidth() / 2.0;
- gl.glPushMatrix();
- gl.glLoadIdentity();
- gl.glBegin(GL2.GL_QUADS);
- gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- gl.glTexCoord2d(0.0, 0.0);
- gl.glVertex3d(-halfWidth, -halfWidth, 0.0);
- gl.glTexCoord2d(0.0, 1.0);
- gl.glVertex3d(-halfWidth, halfWidth, 0.0);
- gl.glTexCoord2d(1.0, 1.0);
- gl.glVertex3d(halfWidth, halfWidth, 0.0);
- gl.glTexCoord2d(1.0, 0.0);
- gl.glVertex3d(halfWidth, -halfWidth, 0.0);
- gl.glEnd();
- texture.disable(gl);
- texture.destroy(gl);
- gl.glPopMatrix();
- gl.glPopAttrib();
- if (gl.glGetError() > 0) {
- System.out.println("some OpenGL error: " + gl.glGetError());
- }
- }
- private BufferedImage image;
- private double[] viewMatrix = new double[4 * 4];
- @Override
- public void changed() {
- for (int i=0; i < listeners.size(); i++) {
- listeners.get(i).changed();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement