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

The following examples show how to use javax.media.opengl.GL2#glColor4f() . 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: 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 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 4
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 5
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 6
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();
}