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

The following examples show how to use javax.media.opengl.GL2#glVertex2f() . 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 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 2
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 3
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 4
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();
}