@Override public void draw(GL2 gl, Object obj) { if (!(Force.class.isAssignableFrom(obj.getClass()))) return; Force force = (Force) obj; gl.glLineWidth(2.5f); gl.glColor3f(1.0f, 0f, 0f); gl.glBegin(GL.GL_LINES); gl.glVertex3d( force.getPointApplication().getX(), force.getPointApplication().getY(), force.getPointApplication().getZ()); Vector3D finalPoint = force.getPointApplication().add(force.getForce()); gl.glVertex3d(finalPoint.getX(), finalPoint.getY(), finalPoint.getZ()); gl.glEnd(); gl.glTranslated( force.getPointApplication().getX(), force.getPointApplication().getY(), force.getPointApplication().getZ()); gl.glColor3f(1.0f, 0.0f, 0.0f); GLU glu = new GLU(); GLUquadric q = glu.gluNewQuadric(); glu.gluQuadricDrawStyle(q, GLU.GLU_FILL); glu.gluSphere(q, Force.originRadius, 5, 5); glu.gluDeleteQuadric(q); }
/** ***************************************************** */ public void draw(GL2 gl, GLU glu, Camera cam) { if (transform != null) transform.execute(gl); gl.glTranslatef(x, y, z); applyMaterial(gl); gl.glLineWidth(wfwidth); // Draw GLUquadric qobj = glu.gluNewQuadric(); if (facestatus) { if (wfstatus) { gl.glEnable(GL2.GL_POLYGON_OFFSET_FILL); gl.glPolygonOffset(1.0f, 1.0f); } gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_FILL); gl.glNormal3f(norm.x, norm.y, norm.z); gl.glColor4f(color.r, color.g, color.b, color.a); glu.gluDisk(qobj, radiusInner, radiusOuter, slices, loops); if (wfstatus) gl.glDisable(GL2.GL_POLYGON_OFFSET_FILL); } if (wfstatus) { gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE); gl.glNormal3f(norm.x, norm.y, norm.z); gl.glColor4f(wfcolor.r, wfcolor.g, wfcolor.b, wfcolor.a); glu.gluDisk(qobj, radiusInner, radiusOuter, slices, loops); } }
// in pixels. @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { System.out.println(x + " " + y + " " + width + " " + height); GL2 gl = drawable.getGL().getGL2(); // calculate the aspect ratio of window double aspect = 1.0 * width / height; // in OpenGL terms, we are changing the 'projection' // this will be explained later gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); // Use the GLU library to compute the new projection GLU glu = new GLU(); // We are wider than high! if (aspect >= 1) { System.out.println("Showing world " + (-aspect) + " to " + (aspect) + " -1 to 1"); glu.gluOrtho2D(-aspect, aspect, -1.0, 1.0); // left, right, top, bottom } else { System.out.println("Showing world from -1 to 1 " + (-1.0 / aspect) + " to " + (1.0 / aspect)); glu.gluOrtho2D(-1, 1, -1.0 / aspect, 1.0 / aspect); // left, right, top, bottom } }
// private void pickSquares(GL gl, int button, int state, int x, int y) private void pickSquares(GL2 gl) { int selectBuf[] = new int[BUFSIZE]; IntBuffer selectBuffer = IntBuffer.wrap(selectBuf); int hits; int viewport[] = new int[4]; // if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN) return; gl.glGetIntegerv(GL2.GL_VIEWPORT, viewport, 0); gl.glSelectBuffer(BUFSIZE, selectBuffer); gl.glRenderMode(GL2.GL_SELECT); gl.glInitNames(); gl.glPushName(0); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); /* create 5x5 pixel picking region near cursor location */ glu.gluPickMatrix( (double) pickPoint.x, (double) (viewport[3] - pickPoint.y), 5.0, 5.0, viewport, 0); glu.gluOrtho2D(0.0, 3.0, 0.0, 3.0); drawSquares(gl, GL2.GL_SELECT); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glPopMatrix(); gl.glFlush(); hits = gl.glRenderMode(GL2.GL_RENDER); selectBuffer.get(selectBuf); processHits(hits, selectBuf); }
private void renderBlast(GL2 gl) { GLU glu = new GLU(); Shader shader = Shader.get("dissolve"); if (shader != null) { shader.enable(gl); shader.setSampler(gl, "cloudSampler", 0); shader.setUniform(gl, "dissolveFactor", 1.0f - ((float) blastDuration / 60.0f)); } gl.glEnable(GL2.GL_TEXTURE_2D); GLUquadric sphere = glu.gluNewQuadric(); glu.gluQuadricDrawStyle(sphere, GLU.GLU_FILL); glu.gluQuadricTexture(sphere, true); gl.glPushMatrix(); { noiseSampler.bind(gl); noiseSampler.setTexParameterf(gl, GL2.GL_TEXTURE_MAX_ANISOTROPY_EXT, 16); gl.glTranslatef(bound.c.x, bound.c.y, bound.c.z); glu.gluSphere(sphere, blastRadius, 24, 24); } gl.glPopMatrix(); }
private void renderPin(GL gl, Coordinates position, float[] color, float size) { float height = heightmap.getHeight(projection.getGeoCoordinates(position)); gl.glPushMatrix(); double[] model = new double[16]; gl.glGetDoublev(GL_MODELVIEW_MATRIX, model, 0); double zoomH = 0.1 / Math.sqrt((model[0] * model[0]) + (model[1] * model[1]) + (model[2] * model[2])); double zoomZ = 0.1 / Math.sqrt((model[8] * model[8]) + (model[9] * model[9]) + (model[10] * model[10])); gl.glTranslatef(position.getLongitude(), position.getLatitude(), height); gl.glScaled(zoomH * size, zoomH * size, zoomZ * size); gl.glDisable(GL_TEXTURE_2D); gl.glRotatef(20, 0.3f, 1, 0); GLU glu = new GLU(); GLUquadric quadric = glu.gluNewQuadric(); // glu.gluQuadricNormals(quadric, GLU.GLU_FLAT); gl.glColor3f(0.5f, 0.5f, 0.5f); gl.glEnable(GL_LIGHTING); glu.gluCylinder(quadric, 0.03, 0.03, 0.6f, 5, 1); gl.glTranslatef(0, 0, 0.6f); gl.glColor3f(color[0], color[1], color[2]); gl.glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glu.gluSphere(quadric, 0.12, 8, 8); // glu.gluCylinder(quadric, 0.2, 0.1, 0.5, 8, 1); gl.glDisable(GL_LIGHTING); glu.gluDeleteQuadric(quadric); gl.glPopMatrix(); }
public void displayInit(Point pickPoint) { gl.glShadeModel(GL.GL_SMOOTH); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); if (pickPoint != null) { int[] vp = new int[4]; gl.glGetIntegerv(GL.GL_VIEWPORT, vp, 0); GLU glu = new GLU(); int px = (int) pickPoint.getX(); int py = (int) (vp[3] - pickPoint.getY()); glu.gluPickMatrix(px, py, 1e-2, 1e-2, vp, 0); } gl.glOrtho(0, bounds.getWidth(), 0, bounds.getHeight(), .1, depth); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); glu.gluLookAt(0, 0, depth - 0.1, 0, 0, 0, 0, 1, 0); gl.glInitNames(); gl.glPushName(-1); }
{ final GLUtessellatorCallback callback = new GLUtessellatorCallbackAdapter() { private volatile Handler handler; @Override public void begin(int type) { switch (type) { case GL.GL_TRIANGLES: handler = triangleHandler; break; case GL.GL_TRIANGLE_STRIP: handler = triangleStripHandler; break; case GL.GL_TRIANGLE_FAN: handler = triangleFanHandler; break; } } @Override public void vertex(Object index) { handler.index((short) index); } }; GLU.gluTessCallback(tessellator, GLU.GLU_TESS_BEGIN, callback); GLU.gluTessCallback(tessellator, GLU.GLU_TESS_VERTEX, callback); }
/** * Get the current mouse position in world coordinates. * * @return */ public double[] getPosition() { double[] p = new double[3]; if (myMouse != null) { int x = myMouse.getX(); int y = myMouse.getY(); GLU glu = new GLU(); /* note viewport[3] is height of window in pixels */ y = myViewport[3] - y - 1; glu.gluUnProject( (double) x, (double) y, 0.0, // myMVMatrix, 0, myProjMatrix, 0, myViewport, 0, p, 0); } return p; }
@Override public void drawCD(double internalRadius, double externalRadius, int slices, int rings) { GLUquadric quadratic = glu.gluNewQuadric(); glu.gluDisk( quadratic, Math.max(internalRadius * scaleX, 1), externalRadius * scaleX, slices, rings); glu.gluDeleteQuadric(quadratic); }
public void render(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glPushMatrix(); gl.glTranslated( body.getPosition().get0(), body.getPosition().get1(), body.getPosition().get2()); GLUquadric bulletGeom = glu.gluNewQuadric(); glu.gluQuadricDrawStyle(bulletGeom, GLU.GLU_FILL); glu.gluQuadricNormals(bulletGeom, GLU.GLU_SMOOTH); glu.gluDisk(bulletGeom, 0.3, 0.4, 5, 5); gl.glPopMatrix(); }
public static void setup(GL2ES1 gl, int width, int height) { gl.glMatrixMode(GL2ES1.GL_PROJECTION); gl.glLoadIdentity(); // coordinate system origin at lower left with width and height same as the window GLU glu = new GLUgl2es1(); glu.gluOrtho2D(0.0f, width, 0.0f, height); gl.glMatrixMode(GL2ES1.GL_MODELVIEW); gl.glLoadIdentity(); gl.glViewport(0, 0, width, height); }
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { GL gl = drawable.getGL(); GLU glu = new GLU(); if (height <= 0) { height = 1; } final float h = (float) width / (float) height; gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(45.0f, h, 1.0, 20.0); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); }
public void eertLookAt(GL gl) { GLU glu = new GLU(); this.loc = this.engine.camMove.pos; glu.gluLookAt( this.engine.camMove.pos.x, this.engine.camMove.pos.y, this.engine.camMove.pos.z, this.engine.camMove.lookAt.x, this.engine.camMove.lookAt.y, this.engine.camMove.lookAt.z, 0f, 1f, 0f); }
public Tessellation(float[] vertices, short[] indices, Callback callback) { this.callback = callback; GLU.gluBeginPolygon(tessellator); for (short index : indices) { double w = vertices[index * 4 + 3]; GLU.gluTessVertex( tessellator, new double[] { vertices[index * 4] / w, vertices[index * 4 + 1] / w, vertices[index * 4 + 2] / w }, 0, index); } GLU.gluEndPolygon(tessellator); }
@Override public void reshape(GLAutoDrawable drawable, int arg1, int arg2, int width, int height) { GL2 gl = drawable.getGL().getGL2(); // Computing the aspect ratio float aspect = (float) width / height; // Setting the viewport, the area that is displayed, to cover the whole window gl.glViewport(0, 0, width, height); // Setting the perspective projection with an aspect that matches that of the viewport // Choose Projection Matrix gl.glMatrixMode(GL_PROJECTION); // Resets the Projection Matrix gl.glLoadIdentity(); // gluPerspective(fovy, aspect, zNear, zFar); // Instructions taken from http://www.opengl.org/sdk/docs/man2/xhtml/glTranslate.xml // fovy : Specifies the field of view angle, in degrees, in the y direction. // aspect : Specifies the aspect ratio that determines the field of view in the x direction. The // aspect ratio is the ratio of x (width) to y (height). // zNear : Specifies the distance from the viewer to the near clipping plane (always positive). // zFar : Specifies the distance from the viewer to the far clipping plane (always positive). glu.gluPerspective(45.0, aspect, 0.1, 100.0); gl.glMatrixMode(GL_MODELVIEW); gl.glLoadIdentity(); }
public void updateSelectedOctant(GL gl, GLU glu, float[] mousePosition, float[] pickRectangle) { // Start Picking mode int capacity = 1 * 4 * visibleLeaves.size(); // Each object take in maximium : 4 * name stack depth IntBuffer hitsBuffer = BufferUtil.newIntBuffer(capacity); gl.glSelectBuffer(hitsBuffer.capacity(), hitsBuffer); gl.glRenderMode(GL.GL_SELECT); gl.glDisable(GL.GL_CULL_FACE); // Disable flags gl.glInitNames(); gl.glPushName(0); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); glu.gluPickMatrix( mousePosition[0], mousePosition[1], pickRectangle[0], pickRectangle[1], drawable.getViewport()); gl.glMultMatrixd(drawable.getProjectionMatrix()); gl.glMatrixMode(GL.GL_MODELVIEW); // Draw the nodes' cube int the select buffer int hitName = 1; for (int i = 0; i < visibleLeaves.size(); i++) { Octant node = visibleLeaves.get(i); gl.glLoadName(hitName); node.displayOctant(gl); hitName++; } // Restoring the original projection matrix gl.glMatrixMode(GL.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glFlush(); // Returning to normal rendering mode int nbRecords = gl.glRenderMode(GL.GL_RENDER); if (vizController.getVizModel().isCulling()) { gl.glEnable(GL.GL_CULL_FACE); gl.glCullFace(GL.GL_BACK); } // Clean previous selection selectedLeaves.clear(); // Get the hits and put the node under selection in the selectionArray for (int i = 0; i < nbRecords; i++) { int hit = hitsBuffer.get(i * 4 + 3) - 1; // -1 Because of the glPushName(0) Octant nodeHit = visibleLeaves.get(hit); selectedLeaves.add(nodeHit); } }
public void error(int errnum) { String estring; estring = glu.gluErrorString(errnum); System.err.println("Tessellation Error: " + estring); System.exit(0); }
public void draw(GL2 gl, GLU glu) { gl.glColor3f(1f, 0f, .25f); // Lamp Stem, cylindrical, a little smaller at the top. gl.glPushMatrix(); gl.glRotatef(-90f, 1f, 0f, 0f); // stand upright (Y) glu.gluCylinder(quadric, 1., 1, 3., 10, 1); gl.glPopMatrix(); // Table Top gl.glPushMatrix(); gl.glTranslated(0, 3, 0); gl.glRotatef(-90f, 100f, 0f, 0f); // stand upright (Y) glu.gluDisk(quadric, 0, 4., 15, 5); // also to be flipped gl.glPopMatrix(); }
private static void updateShaderUniform(final ShaderVariableMatrix4 shaderUniform) { final GL gl = GLU.getCurrentGL(); shaderUniform.matrixBuffer.rewind(); gl.glUniformMatrix4fv( shaderUniform.variableID, 1, shaderUniform.rowMajor, shaderUniform.matrixBuffer); }
private void checkGLErrors(GL gl) { int err = gl.glGetError(); if (err != 0) { String errString = glu.gluErrorString(err); System.out.println(errString); } }
/** OpenGL reshape function Perspective and view calls go here */ @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { final GL gl = drawable.getGL(); final GLU glu = new GLU(); gl.setSwapInterval(1); gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(45.0f, (double) width / (double) height, 0.1f, 1000.0f); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); }
/* (non-Javadoc) * @see javax.media.opengl.GLEventListener#reshape(javax.media.opengl.GLAutoDrawable, int, int, int, int) */ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { this.width = width; this.height = height; // GL gl = drawable.getGL(); gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); double ratio = (double) width / (double) height; double w = 2; double h = 2; if (width < height) { h = h / ratio; } else { w = w * ratio; } int mode = Options.getProjectionMode(); if (mode == Options.PERSPECTIVE) { // For Perspective projection glu.gluPerspective(45, (double) (width) / (double) (height), 0.001, 1000); } else if (mode == Options.ORTHOGRAPHIC) { // For Orthogonal projection gl.glOrtho(-1 * w, w, -1 * h, h, -10000, 10000); } gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); for (Iterator<GLBrush> it = displayList.iterator(); it.hasNext(); ) { GLBrush brush = it.next(); brush.setScreenSize(width, height); } }
/* * sets up selection mode, name stack, and projection matrix for picking. * Then the objects are drawn. */ private void pickRects(GL2 gl) { int[] selectBuf = new int[BUFSIZE]; IntBuffer selectBuffer = GLBuffers.newDirectIntBuffer(BUFSIZE); int hits; int viewport[] = new int[4]; // int x, y; gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0); gl.glSelectBuffer(BUFSIZE, selectBuffer); gl.glRenderMode(GL2.GL_SELECT); gl.glInitNames(); gl.glPushName(-1); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); /* create 5x5 pixel picking region near cursor location */ glu.gluPickMatrix( (double) pickPoint.x, (double) (viewport[3] - pickPoint.y), // 5.0, 5.0, viewport, 0); gl.glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5); drawRects(gl, GL2.GL_SELECT); gl.glPopMatrix(); gl.glFlush(); hits = gl.glRenderMode(GL2.GL_RENDER); selectBuffer.get(selectBuf); processHits(hits, selectBuf); }
/** Draws a canonical circular particle. */ private static void drawParticle(GL gl, Point3d p, double r) { double radius = r; double vectorY1 = p.y; double vectorX1 = p.x; double vectorZ1 = p.z; GLU glu = new GLU(); GLUquadric quadratic = glu.gluNewQuadric(); glu.gluQuadricNormals(quadratic, GLU.GLU_SMOOTH); glu.gluQuadricTexture(quadratic, true); gl.glPushMatrix(); gl.glTranslated(p.x, p.y, p.z); glu.gluSphere(quadratic, radius, 12, 12); gl.glPopMatrix(); }
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { GL2 gl = drawable.getGL().getGL2(); gl.glMatrixMode(GL2ES1.GL_PROJECTION); gl.glLoadIdentity(); glu.gluOrtho2D(0, 1, 0, 1); gl.glMatrixMode(GL2ES1.GL_MODELVIEW); gl.glLoadIdentity(); }
@Override public void display(GLAutoDrawable dr) { GL2 gl = dr.getGL().getGL2(); // Очиска экрана gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Загрузка единичной матрицы gl.glLoadIdentity(); // Определение точки и направления взгляда glu.gluLookAt(0f, 0f, 10f, 0f, 0f, -100f, 0f, 1f, 0f); // Загрузка текстуры в графическую память this.texture.bind(gl); GLUquadric ground = glu.gluNewQuadric(); // enabling texturing on the quadric glu.gluQuadricTexture(ground, true); glu.gluSphere(ground, 1, 64, 64); glu.gluDeleteQuadric(ground); }
/** Removes the vertex shader */ private static void removeVertShader(final GLSLShaderObjectsState state) { final GL gl = GLU.getCurrentGL(); if (state._vertexShaderID != -1) { gl.glDetachObjectARB(state._programID, state._vertexShaderID); gl.glDeleteObjectARB(state._vertexShaderID); } }
public void prepare(GL2 gl, GLU glu, GLUT glut) { if (DEBUG) { System.out.println("Eye: " + eyeX + ", " + eyeY + ", " + eyeZ); System.out.println("Center: " + centerX + ", " + centerY + ", " + centerZ); System.out.println("ViewUp: " + viewUpX + ", " + viewUpY + ", " + viewUpZ); } glu.gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, viewUpX, viewUpY, viewUpZ); }
@Override public void reshape(GLAutoDrawable dr, int x, int y, int width, int height) { GL2 gl = dr.getGL().getGL2(); gl.glViewport(x, y, width, height); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(45.0f, (float) width / (float) height, 1.0, 100.0); gl.glMatrixMode(GL2.GL_MODELVIEW); }