Java Code Examples for javax.media.opengl.GL2#glEnd()

The following examples show how to use javax.media.opengl.GL2#glEnd() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JoglDebugDraw.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void drawCircle(Vec2 center, float radius, Color3f color) {
  GL2 gl = panel.getGL().getGL2();
  gl.glPushMatrix();
  transformViewport(gl, zero);
  float theta = 2 * MathUtils.PI / NUM_CIRCLE_POINTS;
  float c = MathUtils.cos(theta);
  float s = MathUtils.sin(theta);
  float x = radius;
  float y = 0;
  float cx = center.x;
  float cy = center.y;
  gl.glBegin(GL2.GL_LINE_LOOP);
  gl.glColor4f(color.x, color.y, color.z, 1);
  for (int i = 0; i < NUM_CIRCLE_POINTS; i++) {
    gl.glVertex3f(x + cx, y + cy, 0);
    // apply the rotation matrix
    float temp = x;
    x = c * x - s * y;
    y = s * temp + c * y;
  }
  gl.glEnd();
  gl.glPopMatrix();
}
 
Example 2
Source File: JoglDebugDraw.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void drawTransform(Transform xf) {
  GL2 gl = panel.getGL().getGL2();
  getWorldToScreenToOut(xf.p, temp);
  temp2.setZero();
  float k_axisScale = 0.4f;

  gl.glBegin(GL2.GL_LINES);
  gl.glColor3f(1, 0, 0);

  temp2.x = xf.p.x + k_axisScale * xf.q.c;
  temp2.y = xf.p.y + k_axisScale * xf.q.s;
  getWorldToScreenToOut(temp2, temp2);
  gl.glVertex2f(temp.x, temp.y);
  gl.glVertex2f(temp2.x, temp2.y);

  gl.glColor3f(0, 1, 0);
  temp2.x = xf.p.x + -k_axisScale * xf.q.s;
  temp2.y = xf.p.y + k_axisScale * xf.q.c;
  getWorldToScreenToOut(temp2, temp2);
  gl.glVertex2f(temp.x, temp.y);
  gl.glVertex2f(temp2.x, temp2.y);
  gl.glEnd();
}
 
Example 3
Source File: CefRenderer.java    From pandomium with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("static-access")
protected void render(GL2 gl2) {
    if (use_draw_pixels_ || view_width_ == 0 || view_height_ == 0) {
        return;
    }

    assert (initialized_context_ != null);

    final float[] vertex_data = {
            //tu,   tv,     x,     y,    z
            0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f };
    FloatBuffer vertices = FloatBuffer.wrap(vertex_data);

    gl2.glClear(gl2.GL_COLOR_BUFFER_BIT | gl2.GL_DEPTH_BUFFER_BIT);

    gl2.glMatrixMode(gl2.GL_MODELVIEW);
    gl2.glLoadIdentity();

    // Match GL units to screen coordinates.
    gl2.glViewport(0, 0, view_width_, view_height_);
    gl2.glMatrixMode(gl2.GL_PROJECTION);
    gl2.glLoadIdentity();

    // Draw the background gradient.
    gl2.glPushAttrib(gl2.GL_ALL_ATTRIB_BITS);
    gl2.glBegin(gl2.GL_QUADS);
    gl2.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);  // red
    gl2.glVertex2f(-1.0f, -1.0f);
    gl2.glVertex2f(1.0f, -1.0f);
    gl2.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);  // blue
    gl2.glVertex2f(1.0f, 1.0f);
    gl2.glVertex2f(-1.0f, 1.0f);
    gl2.glEnd();
    gl2.glPopAttrib();

    // Rotate the view based on the mouse spin.
    if (spin_x_ != 0) {
        gl2.glRotatef(-spin_x_, 1.0f, 0.0f, 0.0f);
    }
    if (spin_y_ != 0) {
        gl2.glRotatef(-spin_y_, 0.0f, 1.0f, 0.0f);
    }

    if (transparent_) {
        // Alpha blending style. Texture values have premultiplied alpha.
        gl2.glBlendFunc(gl2.GL_ONE, gl2.GL_ONE_MINUS_SRC_ALPHA);

        // Enable alpha blending.
        gl2.glEnable(gl2.GL_BLEND);
    }

    // Enable 2D textures.
    gl2.glEnable(gl2.GL_TEXTURE_2D);

    // Draw the facets with the texture.
    assert (texture_id_[0] != 0);
    gl2.glBindTexture(gl2.GL_TEXTURE_2D, texture_id_[0]);
    gl2.glInterleavedArrays(gl2.GL_T2F_V3F, 0, vertices);
    gl2.glDrawArrays(gl2.GL_QUADS, 0, 4);

    // Disable 2D textures.
    gl2.glDisable(gl2.GL_TEXTURE_2D);

    if (transparent_) {
        // Disable alpha blending.
        gl2.glDisable(gl2.GL_BLEND);
    }
}
 
Example 4
Source File: JoglDebugDraw.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void drawPoint(Vec2 argPoint, float argRadiusOnScreen, Color3f argColor) {
  Vec2 vec = getWorldToScreen(argPoint);
  GL2 gl = panel.getGL().getGL2();
  gl.glPointSize(argRadiusOnScreen);
  gl.glBegin(GL2.GL_POINTS);
  gl.glVertex2f(vec.x, vec.y);
  gl.glEnd();
}
 
Example 5
Source File: JoglDebugDraw.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void drawPolygon(Vec2[] vertices, int vertexCount, Color3f color) {
  GL2 gl = panel.getGL().getGL2();
  gl.glPushMatrix();
  transformViewport(gl, zero);
  gl.glBegin(GL2.GL_LINE_LOOP);
  gl.glColor4f(color.x, color.y, color.z, 1f);
  for (int i = 0; i < vertexCount; i++) {
    Vec2 v = vertices[i];
    gl.glVertex2f(v.x, v.y);
  }
  gl.glEnd();
  gl.glPopMatrix();
}
 
Example 6
Source File: JoglDebugDraw.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void drawCircle(Vec2 center, float radius, Vec2 axis, Color3f color) {
  GL2 gl = panel.getGL().getGL2();
  gl.glPushMatrix();
  transformViewport(gl, zero);
  float theta = 2 * MathUtils.PI / NUM_CIRCLE_POINTS;
  float c = MathUtils.cos(theta);
  float s = MathUtils.sin(theta);
  float x = radius;
  float y = 0;
  float cx = center.x;
  float cy = center.y;
  gl.glBegin(GL2.GL_LINE_LOOP);
  gl.glColor4f(color.x, color.y, color.z, 1);
  for (int i = 0; i < NUM_CIRCLE_POINTS; i++) {
    gl.glVertex3f(x + cx, y + cy, 0);
    // apply the rotation matrix
    float temp = x;
    x = c * x - s * y;
    y = s * temp + c * y;
  }
  gl.glEnd();
  gl.glBegin(GL2.GL_LINES);
  gl.glVertex3f(cx, cy, 0);
  gl.glVertex3f(cx + axis.x * radius, cy + axis.y * radius, 0);
  gl.glEnd();
  gl.glPopMatrix();
}
 
Example 7
Source File: JoglDebugDraw.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void drawSegment(Vec2 p1, Vec2 p2, Color3f color) {
  GL2 gl = panel.getGL().getGL2();
  gl.glPushMatrix();
  transformViewport(gl, zero);
  gl.glBegin(GL2.GL_LINES);
  gl.glColor3f(color.x, color.y, color.z);
  gl.glVertex3f(p1.x, p1.y, 0);
  gl.glVertex3f(p2.x, p2.y, 0);
  gl.glEnd();
  gl.glPopMatrix();
}
 
Example 8
Source File: JoglDebugDraw.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void drawParticles(Vec2[] centers, float radius, ParticleColor[] colors, int count) {
  GL2 gl = panel.getGL().getGL2();
  gl.glPushMatrix();
  transformViewport(gl, zero);

  float theta = 2 * MathUtils.PI / NUM_CIRCLE_POINTS;
  float c = MathUtils.cos(theta);
  float s = MathUtils.sin(theta);

  float x = radius;
  float y = 0;

  for (int i = 0; i < count; i++) {
    Vec2 center = centers[i];
    float cx = center.x;
    float cy = center.y;
    gl.glBegin(GL2.GL_TRIANGLE_FAN);
    if (colors == null) {
      gl.glColor4f(1, 1, 1, .4f);
    } else {
      ParticleColor color = colors[i];
      gl.glColor4b(color.r, color.g, color.b, color.a);
    }
    for (int j = 0; j < NUM_CIRCLE_POINTS; j++) {
      gl.glVertex3f(x + cx, y + cy, 0);
      float temp = x;
      x = c * x - s * y;
      y = s * temp + c * y;
    }
    gl.glEnd();
  }
  gl.glPopMatrix();
}
 
Example 9
Source File: JoglDebugDraw.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void drawParticlesWireframe(Vec2[] centers, float radius, ParticleColor[] colors, int count) {
  GL2 gl = panel.getGL().getGL2();
  gl.glPushMatrix();
  transformViewport(gl, zero);

  float theta = 2 * MathUtils.PI / NUM_CIRCLE_POINTS;
  float c = MathUtils.cos(theta);
  float s = MathUtils.sin(theta);

  float x = radius;
  float y = 0;

  for (int i = 0; i < count; i++) {
    Vec2 center = centers[i];
    float cx = center.x;
    float cy = center.y;
    gl.glBegin(GL2.GL_LINE_LOOP);
    if (colors == null) {
      gl.glColor4f(1, 1, 1, 1);
    } else {
      ParticleColor color = colors[i];
      gl.glColor4b(color.r, color.g, color.b, (byte) 127);
    }
    for (int j = 0; j < NUM_CIRCLE_POINTS; j++) {
      gl.glVertex3f(x + cx, y + cy, 0);
      float temp = x;
      x = c * x - s * y;
      y = s * temp + c * y;
    }
    gl.glEnd();
  }
  gl.glPopMatrix();
}
 
Example 10
Source File: Rhombus.java    From MeteoInfo with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void display(GLAutoDrawable drawable) {

    final GL2 gl = drawable.getGL().getGL2();
    gl.glTranslatef(0f, 0f, -2.5f);

    //drawing edge1.....
    gl.glBegin(GL2.GL_LINES);
    gl.glVertex3f(-0.75f, 0f, 0);
    gl.glVertex3f(0f, -0.75f, 0);
    gl.glEnd();

    gl.glBegin(GL2.GL_LINES);
    gl.glVertex3f(-0.75f, 0f, 3f); // 3 units into the window
    gl.glVertex3f(0f, -0.75f, 3f);
    gl.glEnd();

    //top
    gl.glBegin(GL2.GL_LINES);
    gl.glVertex3f(-0.75f, 0f, 0);
    gl.glVertex3f(-0.75f, 0f, 3f);
    gl.glEnd();

    // bottom
    gl.glBegin(GL2.GL_LINES);
    gl.glVertex3f(0f, -0.75f, 0);
    gl.glVertex3f(0f, -0.75f, 3f);
    gl.glEnd();

    // edge 2....
    gl.glBegin(GL2.GL_LINES);
    gl.glVertex3f(0f, -0.75f, 0);
    gl.glVertex3f(0.75f, 0f, 0);
    gl.glEnd();

    gl.glBegin(GL2.GL_LINES);
    gl.glVertex3f(0f, -0.75f, 3f);
    gl.glVertex3f(0.75f, 0f, 3f);
    gl.glEnd();

    gl.glBegin(GL2.GL_LINES);
    gl.glVertex3f(0f, -0.75f, 0);
    gl.glVertex3f(0f, -0.75f, 3f);
    gl.glEnd();

    gl.glBegin(GL2.GL_LINES);
    gl.glVertex3f(0.75f, 0f, 0);
    gl.glVertex3f(0.75f, 0f, 3f);
    gl.glEnd();

    //Edge 3.............
    gl.glBegin(GL2.GL_LINES);
    gl.glVertex3f(0.0f, 0.75f, 0);
    gl.glVertex3f(-0.75f, 0f, 0);
    gl.glEnd();

    gl.glBegin(GL2.GL_LINES);
    gl.glVertex3f(0.0f, 0.75f, 3f);
    gl.glVertex3f(-0.75f, 0f, 3f);
    gl.glEnd();

    gl.glBegin(GL2.GL_LINES);
    gl.glVertex3f(0.0f, 0.75f, 0);
    gl.glVertex3f(0.0f, 0.75f, 3f);
    gl.glEnd();

    gl.glBegin(GL2.GL_LINES);
    gl.glVertex3f(-0.75f, 0f, 0);
    gl.glVertex3f(-0.75f, 0f, 3f);
    gl.glEnd();

    //final edge
    gl.glBegin(GL2.GL_LINES);
    gl.glVertex3f(0.75f, 0f, 0);
    gl.glVertex3f(0.0f, 0.75f, 0);
    gl.glEnd();

    gl.glBegin(GL2.GL_LINES);
    gl.glVertex3f(0.75f, 0f, 3f);
    gl.glVertex3f(0.0f, 0.75f, 3f);
    gl.glEnd();

    gl.glBegin(GL2.GL_LINES);
    gl.glVertex3f(0.75f, 0f, 0);
    gl.glVertex3f(0.75f, 0f, 3f);
    gl.glEnd();

    gl.glBegin(GL2.GL_LINES);
    gl.glVertex3f(0.0f, 0.75f, 0);
    gl.glVertex3f(0.0f, 0.75f, 3f);
    gl.glEnd();
}