I followed the Shiffmans tutorial about recursion to end up with this:
As you can see its not perfect and I think the code can be optimized. How do I get rid of the thick lines that should´t be there? And if you get an idea of how I could optimize this code tell me please!
This was made with processing 3.3.6 and the code is the following:
void setup() {
size(800, 800);
}
void draw() {
background(255);
fill(0);
noStroke();
rectMode(CENTER);
Serpinski(width/2, height/2, width/3);
}
void Serpinski(int x, int y, int d) {
rect(x, y, d, d);
if (d > 1) {
Serpinski(int(x+ d), y, d*1/3);
Serpinski(int(x- d), y, d*1/3);
Serpinski(x, int(y+ d), d*1/3);
Serpinski(x, int(y- d), d*1/3);
Serpinski(int(x+ d), int(y+ d), d*1/3);
Serpinski(int(x- d), int(y- d), d*1/3);
Serpinski(int(x+ d), int(y- d), d*1/3);
Serpinski(int(x- d), int(y+ d), d*1/3);
}
}
As mentioned in the comments, changing the Sierpinski method so it deals with float values instead of int will help.
void setup() {
size(800, 800);
}
void draw() {
background(255);
fill(0);
noStroke();
rectMode(CENTER);
Serpinski(width/2, height/2, width/3);
}
void Serpinski(float x, float y, float d) {
rect(x, y, d, d);
if (d > 1) {
Serpinski( x+ d, y, d/3);
Serpinski( x- d, y, d/3);
Serpinski( x, y+ d, d/3);
Serpinski( x, y- d, d/3);
Serpinski( x+ d, y+ d, d/3);
Serpinski( x- d, y- d, d/3);
Serpinski( x+ d, y- d, d/3);
Serpinski( x- d, y+ d, d/3);
}
}
However, due to the way the pixel information is handled, you will find that the graphic representation is still not "exact" when you get down to the smaller rectangles. One way to achieve that is to change the size of the sketch to one that is a power of 3:
size(729, 729);
As for optimization, you could call the Sierpinski method in setup(), that way it only gets computed once rather than every time draw() is called.
Like this?
void setup() {
size(729, 729);
fill(0);
background(255);
centerRectangle(0, 0, width);
rectangles(width/3, height/3, width/3);
}
void centerRectangle(int x, int y, int s) {
float delta = s/3;
noStroke();
rect(x+delta, y+delta, delta, delta);
}
void rectangles(int x, int y, int s) {
if (s < 1) return;
int xc = x-s;
int yc = y-s;
for (int row = 0; row < 3; row++) {
for (int col = 0; col < 3; col++) {
if (!(row == 1 && col == 1)) {
int xx = xc+row*s;
int yy = yc+col*s;
centerRectangle(xx, yy, s);
rectangles(xx+s/3, yy+s/3, s/3);
}
}
}
}
Related
I've been trying to port an optimization routine from R to Rcpp. The Rcpp version isn't producing what I expect and I'm stumped as to what the problem might be. For context, the problem is to compute the inverse cdf of a "gamma(shape, scale) + normal(0, sigma^2)" distribution. In particular, given a value c, find x such that P(W' <= x) = c, where W' has the distribution described. Notice that P(W' <= x) = \int_W P(W' <= x | W) * f_W(W) dW, where W ~ gamma(shape, scale) and W' | W ~ normal(W, sigma^2).
I'm using RcppNumerical (https://stackoverflow.com/a/39449199/2875572) for integration (this seems to be working fine, as the test results indicate). It's the call to optimize that is producing the mysterious results.
R test functions:
IntegrateRTest <- function(x, SIGMA, SHAPE, SCALE) {
sapply(x,
function(x) {
integrate(f = function(W) {
# P(W' <= x | W) * f_W(W)
pnorm(x, mean = W, sd = SIGMA) * dgamma(W, shape = SHAPE, scale = SCALE)
}, 0, Inf)$value
})
}
OptimizeRTest <- function(c, SIGMA, SHAPE, SCALE) {
optimize(f = function(x) {
rhs <- integrate(f = function(W) {
# P(W' <= x | W) * f_W(W)
pnorm(x, mean = W, sd = SIGMA) *
dgamma(W, shape = SHAPE, scale = SCALE)
}, 0, Inf)$value
(c - rhs)^2
},
lower = -10,
upper = 10)
}
The Rcpp script:
#include <Rcpp.h>
#include <RcppNumerical.h>
// [[Rcpp::depends(RcppEigen)]]
// [[Rcpp::depends(RcppNumerical)]]
using namespace Rcpp;
// utility function for vectorized exponentiation
NumericVector vecpow(const NumericVector base, const NumericVector exp) {
NumericVector out(base.size());
std::transform(base.begin(), base.end(),
exp.begin(), out.begin(), static_cast<double(*)(double, double)>(::pow));
return out;
}
class Mintegrand: public Numer::Func {
private:
const double x;
const double SIGMA;
const double SHAPE;
const double SCALE;
public:
Mintegrand(double x_, double sigma_, double shape_, double scale_) : x(x_), SIGMA(sigma_), SHAPE(shape_), SCALE(scale_) {}
double operator()(const double& W) const
{
// P(W' <= x | W) * f_W(W)
return R::pnorm5(x, W, SIGMA, true, false) * R::dgamma(W, SHAPE, SCALE, false);
}
};
NumericVector objective(NumericVector x,
double c,
double SIGMA,
double SHAPE,
double SCALE) {
// for loop is to "vectorize" this function (required by stats::optimize)
NumericVector rhs(x.length());
for (int i = 0; i < x.length(); ++i) {
Mintegrand f(x[i], SIGMA, SHAPE, SCALE);
double err_est;
int err_code;
// compute P(W' <= x) = \int_W P(W' <= x | W) * f_W(W) dW
rhs[i] = Numer::integrate(f, 0.0, R_PosInf, err_est, err_code);
}
return vecpow(c - rhs, 2.0);
}
// [[Rcpp::export]]
NumericVector IntegrateTest(NumericVector x,
double SIGMA,
double SHAPE,
double SCALE) {
NumericVector rhs(x.length());
for (int i = 0; i < x.length(); ++i) {
Mintegrand f(x[i], SIGMA, SHAPE, SCALE);
double err_est;
int err_code;
// compute P(W' <= x) = \int_W P(W' <= x | W) * f_W(W) dW
rhs[i] = Numer::integrate(f, 0.0, R_PosInf, err_est, err_code);
}
return rhs;
}
// [[Rcpp::export]]
List OptimizeTest(double c,
double SIGMA,
double SHAPE,
double SCALE) {
Environment stats("package:stats");
Function optimize = stats["optimize"];
return optimize(_["f"] = InternalFunction(&objective),
_["c"] = c,
_["SIGMA"] = SIGMA,
_["SHAPE"] = SHAPE,
_["SCALE"] = SCALE,
_["lower"] = -10.0,
_["upper"] = 10.0);
}
Test results:
all.equal(IntegrateTest(seq(0, 1, .01), SIGMA = .4, SHAPE = .9, SCALE = .5),
IntegrateRTest(seq(0, 1, .01), SIGMA = .4, SHAPE = .9, SCALE = .5))
# TRUE
OptimizeTest(.9, SIGMA = .4, SHAPE = 9, SCALE = .5)
OptimizeRTest(.9, SIGMA = .4, SHAPE = 9, SCALE = .5)
# gives very different results
I wanted to add some lighting to the 3D mesh so that the back surface is visible. But when I added Ambient Light to it, some of the minor details of the graph became invisible. How can I add some lighting to the mesh so that the back surface is visible but the minor details don't vanish away?
Before adding light:
After adding light:
import java.util.logging.Logger;
import javafx.scene.DepthTest;
import javafx.scene.image.Image;
import javafx.scene.image.PixelWriter;
import javafx.scene.image.WritableImage;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.CullFace;
import javafx.scene.shape.DrawMode;
import javafx.scene.shape.MeshView;
import javafx.scene.shape.TriangleMesh;
public class Fx3DPlotMesh extends MeshView {
private static final int SIZE = 500;
private static float AMPLIFI = 130;
private int rtResolution;
private int mzResolution;
private static final Logger LOG = Logger
.getLogger(Fx3DPlotMesh.class.getName());
public Fx3DPlotMesh(Dataset dataset) {
rtResolution = dataset.getRtResolution();
mzResolution = dataset.getMzResolution();
TriangleMesh mesh = new TriangleMesh();
int[][] peakListIndices = new int[rtResolution][mzResolution];
float factorX = (float) SIZE / rtResolution;
float factorZ = (float) SIZE / mzResolution;
float[][] intensityValues = dataset.getIntensityValues();
for (int x = 0; x < rtResolution; x++) {
for (int z = 0; z < mzResolution; z++) {
mesh.getPoints().addAll((float) x * factorX,-intensityValues[x][z] * AMPLIFI ,(float) z * factorZ);
}
}
int rtLength = rtResolution;
int mzLength = mzResolution;
float rtTotal = rtLength;
float mzTotal = mzResolution;
for (float x = 0; x < rtLength - 1; x++) {
for (float y = 0; y < mzLength - 1; y++) {
float x0 = x / rtTotal;
float y0 = y / mzTotal;
float x1 = (x + 1) / rtTotal;
float y1 = (y + 1) / mzTotal;
mesh.getTexCoords().addAll( //
x0, y0, // 0, top-left
x0, y1, // 1, bottom-left
x1, y0, // 2, top-right
x1, y1 // 3, bottom-right
);
}
}
// faces
for (int x = 0; x < rtLength - 1; x++) {
for (int z = 0; z < mzLength - 1; z++) {
int tl = x * mzLength + z; // top-left
int bl = x * mzLength + z + 1; // bottom-left
int tr = (x + 1) * mzLength + z; // top-right
int br = (x + 1) * mzLength + z + 1; // bottom-right
int offset = (x * (mzLength - 1) + z) * 8 / 2; // div 2 because
// we have u AND
// v in the list
// working
mesh.getFaces().addAll(bl, offset + 1, tl, offset + 0, tr,
offset + 2);
mesh.getFaces().addAll(tr, offset + 2, br, offset + 3, bl,
offset + 1);
}
}
LOG.info("Plot mesh is ready.");
setMesh(mesh);
setCullFace(CullFace.NONE);
setDrawMode(DrawMode.FILL);
setDepthTest(DepthTest.ENABLE);
}
}
This code produces the mesh shown in the above image. I just wanted to add some more lighting to this mesh. I tried adding some light using the code below but it didn't worked. Please help!
Light.Spot light = new Light.Spot();
light.setX(250);
light.setY(500);
light.setZ(250);
light.setPointsAtX(250);
light.setPointsAtY(0);
light.setPointsAtZ(250);
light.setSpecularExponent(2);
Lighting lighting = new Lighting();
lighting.setLight(light);
lighting.setSurfaceScale(5.0);
meshView.setEffect(lighting);
I have sample code but it completely leaves out what my (void*)should_be!
I setup a cl_image_desc, cl_image_format, buffer, origin, and region:
cl_image_desc desc;
desc.image_type = CL_MEM_OBJECT_IMAGE2D;
desc.image_width = width;
desc.image_height = height;
desc.image_depth = 0;
desc.image_array_size = 0;
desc.image_row_pitch = 0;
desc.image_slice_pitch = 0;
desc.num_mip_levels = 0;
desc.num_samples = 0;
desc.buffer = NULL;
cl_image_format format;
format.image_channel_order = CL_R;
format.image_channel_data_type = CL_FLOAT;
cl_mem bufferSourceImage = clCreateImage(context, CL_MEM_READ_ONLY, &format, &desc, NULL, NULL);
size_t origin[3] = {0, 0, 0};
size_t region[3] = {width, height,1};
In this next snippet sourceImage is a void pointer to my image. But what is my image? For every pixel there are r, g, b, a, x, and y values.
clEnqueueWriteImage(queue, bufferSourceImage, CL_TRUE, origin, region, 0, 0, sourceImage, 0, NULL, NULL);
How do I turn my image (a bunch of (r,g,b,a,x,y)'s) into a suitable array?
This is the kernel they provide:
__kernel void convolution(__read_only image2d_t sourceImage, __write_only image2d_t outputImage, int rows, int cols, __constant float* filter, int filterWidth, sampler_t sampler)
{
int column = get_global_id(0);
int row = get_global_id(1);
int halfWidth = (int)(filterWidth/2);
float4 sum = {0.0f, 0.0f, 0.0f, 0.0f};
int filterIdx = 0;
int2 coords;
for(int i = -halfWidth; i <= halfWidth; i++)
{
coords.y = row + i;
for(int i2 = -halfWidth; i2 <= halfWidth; i2++)
{
coords.x = column + i2;
float4 pixel;
pixel = read_imagef(sourceImage, sampler, coords);
sum.x += pixel.x * filter[filterIdx++];
}
}
if(myRow < rows && myCol < cols)
{
coords.x = column;
coords.y = row;
write_imagef(outputImage, coords, sum);
}
}
Set up the cl_image_format as you like and then you just have to follow that format what you selected. Currently your channel (R, G, B, A) data should be represented as "single precision floating-point value" - image_channel_data_type = CL_FLOAT, and you can take only one channel of those and feed it into the expected R channel (image_channel_order = CL_R).
Your kernel expect float:
float4 pixel;
pixel = read_imagef(sourceImage, sampler, coords);
Ive been through every resource and cant fix my problem.
My host code calls the rgb2hsl kernel, then calls the hsl2rgb kernel. I should end up with the same image that I started with, but I do not. My new image hue is off in certain areas.
The red areas should not be there.
Here is the screen shot of what happens:
Here is the original picture
Here is the code:
#define E .0000001f
bool fEqual(float x, float y)
{
return (x+E > y && x-E < y);
}
__kernel void rgb2hsl(__global float *values, int numValues)
{
// thread index and total
int idx = get_global_id(0);
int idxVec3 = idx*3;
float3 gMem;
if (idx < numValues)
{
gMem.x = values[idxVec3];
gMem.y = values[idxVec3+1];
gMem.z = values[idxVec3+2];
}
barrier(CLK_LOCAL_MEM_FENCE);
gMem /= 255.0f; //convert from 256 color to float
//calculate chroma
float M = max(gMem.x, gMem.y);
M = max(M, gMem.z);
float m = min(gMem.x, gMem.y);
m = min(m, gMem.z);
float chroma = M-m; //calculate chroma
float lightness = (M+m)/2.0f;
float saturation = chroma/(1.0f-fabs(2.0f*lightness-1.0f));
float hue = 0;
if (fEqual(gMem.x, M))
hue = (int)((gMem.y - gMem.z)/chroma) % 6;
if (fEqual(gMem.y, M))
hue = (((gMem.z - gMem.x))/chroma) + 2;
if (fEqual(gMem.z, M))
hue = (((gMem.x - gMem.y))/chroma) + 4;
hue *= 60.0f;
barrier(CLK_LOCAL_MEM_FENCE);
if (idx < numValues)
{
values[idxVec3] = hue;
values[idxVec3+1] = saturation;
values[idxVec3+2] = lightness;
}
}
__kernel void hsl2rgb(__global float *values, int numValues)
{
// thread index and total
int idx = get_global_id(0);
int idxVec3 = idx*3;
float3 gMem;
if (idx < numValues)
{
gMem.x = values[idxVec3];
gMem.y = values[idxVec3+1];
gMem.z = values[idxVec3+2];
}
barrier(CLK_LOCAL_MEM_FENCE);
float3 rgb = (float3)(0,0,0);
//calculate chroma
float chroma = (1.0f - fabs( (float)(2.0f*gMem.z - 1.0f) )) * gMem.y;
float H = gMem.x/60.0f;
float x = chroma * (1.0f - fabs( fmod(H, 2.0f) - 1.0f ));
switch((int)H)
{
case 0:
rgb = (float3)(chroma, x, 0);
break;
case 1:
rgb = (float3)(x, chroma, 0);
break;
case 2:
rgb = (float3)(0, chroma, x);
break;
case 3:
rgb = (float3)(0, x, chroma);
break;
case 4:
rgb = (float3)(x, 0, chroma);
break;
case 5:
rgb = (float3)(chroma, 0, x);
break;
default:
rgb = (float3)(0, 0, 0);
}
barrier(CLK_LOCAL_MEM_FENCE);
rgb += gMem.z - .5f*chroma;
rgb *= 255;
if (idx < numValues)
{
values[idxVec3] = rgb.x;
values[idxVec3+1] = rgb.y;
values[idxVec3+2] = rgb.z;
}
}
The problem was this line:
hue = (int)((gMem.y - gMem.z)/chroma) % 6;
It should be
hue = fmod((gMem.y - gMem.z)/chroma, 6.0f);
I did some more changes to remove artifacts:
#define E .0000001f
bool fEqual(float x, float y)
{
return (x+E > y && x-E < y);
}
__kernel void rgb2hsl(__global float *values, int numValues)
{
// thread index and total
int idx = get_global_id(0);
int idxVec3 = idx*3;
float3 gMem;
if (idx < numValues)
{
gMem.x = values[idxVec3];
gMem.y = values[idxVec3+1];
gMem.z = values[idxVec3+2];
}
barrier(CLK_LOCAL_MEM_FENCE);
gMem /= 255.0f; //convert from 256 color to float
//calculate chroma
float M = max(gMem.x, gMem.y);
M = max(M, gMem.z);
float m = min(gMem.x, gMem.y);
m = min(m, gMem.z);
float chroma = M-m; //calculate chroma
float lightness = (M+m)/2.0f;
float saturation = chroma/(1.0f-fabs(2.0f*lightness-1.0f));
float hue = 0;
if (fEqual(gMem.x, M))
hue = fmod((gMem.y - gMem.z)/chroma, 6.0f);
if (fEqual(gMem.y, M))
hue = (((gMem.z - gMem.x))/chroma) + 2;
if (fEqual(gMem.z, M))
hue = (((gMem.x - gMem.y))/chroma) + 4;
hue *= 60.0f;
barrier(CLK_LOCAL_MEM_FENCE);
if (M == m)
hue = saturation = 0;
barrier(CLK_GLOBAL_MEM_FENCE);
if (idx < numValues)
{
//NOTE: ARTIFACTS SHOW UP if we do not cast to integer!
values[idxVec3] = (int)hue;
values[idxVec3+1] = saturation;
values[idxVec3+2] = lightness;
}
}
I'm trying to embed an existing implementation of ArcBall in JOGL into my own project. It compiles and runs but I doesn't work! I can't play around with the view.
I took the implementation (two classes) from here:
http://www.mdimension.com/page/Software?appNum=1
And followed the instructions of embeding the thing into my own project. Here's the class I'm using ArcBall in:
public class GLRenderer implements GLEventListener {
private static final int MAP_SIZE = 1024;
private static final int STEP_SIZE = 16;
private static final float HEIGHT_RATIO = 1.5f;
private float[][] temperatureMap = new float[MAP_SIZE][MAP_SIZE];
private float scaleValue = 0.15f;
private GLU glu = new GLU();
private ArcBall arcBall = new ArcBall();
public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
gl.glShadeModel(GL.GL_SMOOTH);
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
gl.glClearDepth(1.0f);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);
gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
loadValuesToMap();
arcBall.registerDrawable(drawable);
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
GL gl = drawable.getGL();
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL.GL_PROJECTION); // Select The Projection Matrix
gl.glLoadIdentity();
glu.gluPerspective(30,(float)width/(float)height,1.0f,650.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
arcBall.reshape(width, height);
}
public void display(GLAutoDrawable drawable) {
arcBall.displayUpdateRotations();
GL gl = drawable.getGL();
gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glClear(GL.GL_DEPTH_BUFFER_BIT); //added
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
setLight(gl);
positionCamera(glu, gl);
drawXYZ(gl);
arcBall.displayTransform(gl);
drawMap(glu, gl);
gl.glFlush();
}
public void setVertexColor(GL gl, int x, int y) {
float fColor = -0.15f + (temperatureMap[x][y] / 256.0f);
gl.glColor3f(0.0f, 0.0f, fColor);
}
public void drawMap(GLU glu, GL gl) {
int x, z;
float y;
gl.glBegin(GL.GL_QUADS);
for(int X = 0; X <(MAP_SIZE - STEP_SIZE); X += STEP_SIZE) {
for(int Y = 0; Y < (MAP_SIZE -STEP_SIZE); Y += STEP_SIZE) {
// Get The (X, Y, Z) Value For The Bottom Left Vertex
x = X;
y = temperatureMap[X][Y];
z = Y;
// Set The Color Value Of The Current Vertex
setVertexColor(gl, x, z);
gl.glVertex3f(x, y, z);
// Get The (X, Y, Z) Value For The Top Left Vertex
x = X;
y = temperatureMap[X][Y + STEP_SIZE];
z = Y + STEP_SIZE ;
// Set The Color Value Of The Current Vertex
setVertexColor(gl, x, z);
gl.glVertex3f(x, y, z); // Send This Vertex To OpenGL To Be Rendered
// Get The (X, Y, Z) Value For The Top Right Vertex
x = X + STEP_SIZE;
y = temperatureMap[X + STEP_SIZE][Y + STEP_SIZE];
z = Y + STEP_SIZE ;
// Set The Color Value Of The Current Vertex
setVertexColor(gl, x, z);
gl.glVertex3f(x, y, z); // Send This Vertex To OpenGL To Be Rendered
// Get The (X, Y, Z) Value For The Bottom Right Vertex
x = X + STEP_SIZE;
y = temperatureMap[X + STEP_SIZE][Y];
z = Y;
// Set The Color Value Of The Current Vertex
setVertexColor(gl, x, z);
gl.glVertex3f(x, y, z); // Send This Vertex To OpenGL To Be Rendered
}
}
gl.glEnd();
gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
gl.glTranslated(0.1, 0.1, -0.5);
gl.glColor3f(0.0f, 0.0f, 1.0f);
glu.gluSphere(glu.gluNewQuadric(), 0.05f, 32, 32);
gl.glTranslated(0.1, 0.1, -0.1);
gl.glColor3f(0.0f, 1.0f, 0.0f);
glu.gluSphere(glu.gluNewQuadric(), 0.05f, 32, 32);
gl.glTranslated(0.1, -0.1, 0.1);
gl.glColor3f(1.0f, 0.0f, 0.0f);
glu.gluSphere(glu.gluNewQuadric(), 0.05f, 32, 32);
}
public void positionCamera(GLU glu, GL gl) {
glu.gluPerspective(75.0f,1.09,0.1f,500.0f);
glu.gluLookAt(194, 80, 194,
131, 55, 131,
0, 1, 0);
gl.glScalef(scaleValue, scaleValue * HEIGHT_RATIO, scaleValue);
}
public void setLight(GL gl) {
// Prepare light parameters.
float SHINE_ALL_DIRECTIONS = 1;
float[] lightPos = {0, -30, 0, SHINE_ALL_DIRECTIONS};
float[] lightColorAmbient = {0.5f, 0.5f, 0.5f, 0.5f};
float[] diffuseLight = { 0.8f, 0.8f, 0.8f, 1.0f };
float[] lightColorSpecular = {0.5f, 0.5f, 0.5f, 0.5f};
// Set light parameters.
gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, lightPos, 1);
gl.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, lightColorAmbient, 0);
gl.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, diffuseLight, 0);
gl.glLightfv(GL.GL_LIGHT1, GL.GL_SPECULAR, lightColorSpecular, 0);
// Enable lighting in GL.
gl.glEnable(GL.GL_LIGHT1);
gl.glEnable(GL.GL_LIGHTING);
// Set material properties.
gl.glEnable(GL.GL_COLOR_MATERIAL);
}
public void drawXYZ(GL gl) {
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glBegin(GL.GL_LINES);
gl.glColor3d(1.0, 0.0, 0.0); //red (x)
gl.glVertex3d(-0.1, 0.0, 0.0);
gl.glVertex3d(1500.0, 0.0, 0.0);
gl.glColor3d(0.0, 1.0, 0.0); //green (y)
gl.glVertex3d(0.0, -0.1, 0.0);
gl.glVertex3d(0.0, 1500.0, 0.0);
gl.glColor3d(0.0, 0.0, 1.0); //blue (z)
gl.glVertex3d(0.0, 0.0, 0.1);
gl.glVertex3d(0.0, 0.0, 1500.0);
gl.glEnd();
}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
init(drawable);
}
private void loadValuesToMap() {
for(int i = 0; i < MAP_SIZE; i++) {
for(int j = 0; j< MAP_SIZE; j++) {
if(i > 300 && i < 700 && j > 300 && j < 700)
temperatureMap[i][j] = 150;
else
temperatureMap[i][j] = 100;
}
}
}
}
I'm new to openGL soke it might be a stupid mistake. I'd appreciate any help though.
Thanks
The source code is not complete. Where is your frame (AWT Frame or Swing JFrame)? Please look at the example of JOGL on Wikipedia.