void drawCuboid(Part p) { gl.glBegin(GL2.GL_LINES); gl.glColor3d(1, 1, 1); for (double vx : new double[] {-p.w / 2, p.w / 2}) { for (double vz : new double[] {-p.w / 2, p.w / 2}) { // vertical lines gl.glVertex3d(vx, 0, vz); gl.glVertex3d(vx, p.h, vz); } for (double vy : new double[] {0, p.h}) { // hoizontal lines parallel to z axis gl.glVertex3d(vx, vy, -p.w / 2); gl.glVertex3d(vx, vy, p.w / 2); // hoizontal lines parallel to x axis gl.glVertex3d(-p.w / 2, vy, vx); gl.glVertex3d(p.w / 2, vy, vx); } } gl.glEnd(); }
public static void drawCoordinateSystem(GL2 gl) { gl.glBegin(GL_LINES); gl.glColor3d(1, 0, 0); gl.glVertex3i(0, 0, 0); gl.glVertex3i(1, 0, 0); gl.glColor3d(1, 1, 0); gl.glVertex3i(0, 0, 0); gl.glVertex3i(0, 1, 0); gl.glColor3d(0, 1, 0); gl.glVertex3i(0, 0, 0); gl.glVertex3i(0, 0, 1); gl.glEnd(); }
/** * Draws a centered grid with given dimensions * * @param gl OpenGL context * @param h grid height * @param v grid width */ public static void drawGrid(GL2 gl, int h, int v) { gl.glBegin(GL_LINES); gl.glColor3d(.3, .3, .3); for (int x = -h / 2; x <= h / 2; x++) { gl.glVertex3i(x, 0, -v / 2); gl.glVertex3i(x, 0, v / 2); } for (int z = -v / 2; z <= v / 2; z++) { gl.glVertex3i(-h / 2, 0, z); gl.glVertex3i(h / 2, 0, z); } gl.glEnd(); }
public void draw() { // Clear GL state gl.glDisable(GL_LIGHTING); gl.glDisable(GL_DEPTH); gl.glMatrixMode(GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glMatrixMode(GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glClearColor(0.8f, 0.2f, 0.2f, 1.0f); gl.glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); gl.glPointSize(1.0f); // Set the viewport glu.gluOrtho2D(xMin, xMax, yMin, yMax); gl.glBegin(GL_POINTS); for (int x = (int) (xMin); x < xMax; x++) for (int y = (int) (yMin); y < yMax; y++) { gl.glColor3d(viewPort[x][y].r, viewPort[x][y].g, viewPort[x][y].b); gl.glVertex2d(x + 0.5, y + 0.5); } gl.glEnd(); // Restore state gl.glMatrixMode(GL_MODELVIEW); gl.glPopMatrix(); gl.glMatrixMode(GL_PROJECTION); gl.glPopMatrix(); gl.glEnable(GL_LIGHTING); gl.glEnable(GL_DEPTH); }
@Override public void display(GLAutoDrawable a) { GL2 gl2 = a.getGL().getGL2(); this.basicClear(gl2); width = a.getWidth(); height = a.getHeight(); if (!pause) { juliaImaginary += juliaInc; if (juliaImaginary >= 0.95f) juliaInc = -juliaInc; else if (juliaImaginary <= 0.3f) juliaInc = -juliaInc; } // juliaReal += juliaInc2; // if (juliaReal >= 0.38f) // juliaInc2 = -juliaInc2; // else if (juliaImaginary <= 0.35f) // juliaInc2 = -juliaInc2; gl2.glMatrixMode(GL2.GL_PROJECTION); gl2.glLoadIdentity(); gl2.glOrtho(0, 1, 0, 1, -1, 1); gl2.glMatrixMode(GL2.GL_MODELVIEW); gl2.glLoadIdentity(); gl2.glColor3d(0.5, 0.5, 0); shader.bind(gl2); // Set shader uniform variables if (use64 == true) { shader.setUniform1i(gl2, "width", width); shader.setUniform1i(gl2, "height", height); shader.setUniform1i(gl2, "iter", iteration); shader.setUniformf(gl2, "cminX1", (float) dcminx); shader.setUniformf(gl2, "cminX2", (float) (dcminx - (double) ((float) dcminx))); shader.setUniformf(gl2, "cminY1", (float) dcminy); shader.setUniformf(gl2, "cminY2", (float) (dcminy - (double) ((float) dcminy))); shader.setUniformf(gl2, "cmaxX1", (float) dcmaxx); shader.setUniformf(gl2, "cmaxX2", (float) (dcmaxx - (double) ((float) dcmaxx))); shader.setUniformf(gl2, "cmaxY1", (float) dcmaxy); shader.setUniformf(gl2, "cmaxY2", (float) (dcmaxy - (double) ((float) dcmaxy))); shader.setUniformf(gl2, "juliaImaginary", juliaImaginary); shader.setUniformf(gl2, "juliaReal", juliaReal); } else { shader.setUniform1i(gl2, "width", width); shader.setUniform1i(gl2, "height", height); shader.setUniform1i(gl2, "iter", iteration); shader.setUniformf(gl2, "cminX", cminx); shader.setUniformf(gl2, "cminY", cminy); shader.setUniformf(gl2, "cmaxX", cmaxx); shader.setUniformf(gl2, "cmaxY", cmaxy); shader.setUniform1i(gl2, "flag", flag); shader.setUniformf(gl2, "juliaImaginary", juliaImaginary); shader.setUniformf(gl2, "juliaReal", juliaReal); } // Draw an empty quad so the fragments can propagate to the fragment shader gl2.glBegin(GL2.GL_QUADS); gl2.glVertex3d(0, 0, 0); gl2.glVertex3d(1, 0, 0); gl2.glVertex3d(1, 1, 0); gl2.glVertex3d(0, 1, 0); gl2.glEnd(); shader.unbind(gl2); // iteration ++; // if (iteration >= 64) iteration = 1; // canvas.swapBuffers(); }