@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(); }
@Override public void init(GLAutoDrawable arg0) { getGL().getGL2().glLineWidth(1f); getGL().getGL2().glEnable(GL2.GL_BLEND); getGL().getGL2().glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA); }
@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(); }
@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(); }
@Override public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) { GL2 gl2 = arg0.getGL().getGL2(); gl2.glMatrixMode(GL2.GL_PROJECTION); gl2.glLoadIdentity(); // coordinate system origin at lower left with width and height same as the window GLU glu = new GLU(); glu.gluOrtho2D(0.0f, getWidth(), 0.0f, getHeight()); gl2.glMatrixMode(GL2.GL_MODELVIEW); gl2.glLoadIdentity(); gl2.glViewport(0, 0, getWidth(), getHeight()); controller.updateExtents(arg3 / 2, arg4 / 2); } }
@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(); }
@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(); }
public JoglPanel(final TestbedModel model, final TestbedController controller) { super(new GLCapabilities(GLProfile.getDefault())); this.controller = controller; setSize(600, 600); setPreferredSize(new Dimension(600, 600)); setAutoSwapBufferMode(true); addGLEventListener(this); AWTPanelHelper.addHelpAndPanelListeners(this, model, controller, SCREEN_DRAG_BUTTON); }
/** * Start a new display list. All further renderer commands that can be stored in a display list are part of this new * list until {@link #endDisplayList()} is called. * * @return id of new display list */ public int startDisplayList() { final GL gl = GLContext.getCurrentGL(); final int id = gl.getGL2().glGenLists(1); gl.getGL2().glNewList(id, GL2.GL_COMPILE); return id; }
/* pp */ final void validateGL(final GL gl) throws GLException { if( imageBuffer != null && !gl.isGL2ES3()) { throw new GLException("Using image-buffer w/ inssufficient GL context: "+gl.getContext().getGLVersion()+", "+gl.getGLProfile()); } }
private static void updateShaderUniform(final ShaderVariableInt4 shaderUniform) { final GL gl = GLContext.getCurrentGL(); gl.getGL2ES2().glUniform4i(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2, shaderUniform.value3, shaderUniform.value4); }
private static void updateShaderUniform(final ShaderVariableInt3 shaderUniform) { final GL gl = GLContext.getCurrentGL(); gl.getGL2ES2().glUniform3i(shaderUniform.variableID, shaderUniform.value1, shaderUniform.value2, shaderUniform.value3); }
public void transformViewport(GL2 gl, Vec2 center) { Vec2 e = viewportTransform.getExtents(); Vec2 vc = viewportTransform.getCenter(); Mat22 vt = viewportTransform.getMat22Representation(); int f = viewportTransform.isYFlip() ? -1 : 1; mat[0] = vt.ex.x; mat[4] = vt.ey.x; // mat[8] = 0; mat[12] = e.x; mat[1] = f * vt.ex.y; mat[5] = f * vt.ey.y; // mat[9] = 0; mat[13] = e.y; // mat[2] = 0; // mat[6] = 0; // mat[10] = 1; // mat[14] = 0; // mat[3] = 0; // mat[7] = 0; // mat[11] = 0; // mat[15] = 1; gl.glMultMatrixf(mat, 0); gl.glTranslatef(center.x - vc.x, center.y - vc.y, 0); }
@Override public void loadMatrix(final FloatBuffer fb) { final GL2ES1 gl = GLContext.getCurrentGL().getGL2ES1(); gl.glLoadMatrixf(fb); }
@Override public void drawSolidCircle(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 cx = center.x; float cy = center.y; gl.glBegin(GL2.GL_TRIANGLE_FAN); gl.glColor4f(color.x, color.y, color.z, .4f); for (int i = 0; i < NUM_CIRCLE_POINTS; i++) { gl.glVertex3f(x + cx, y + cy, 0); y = s * temp + c * y; gl.glEnd(); 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); 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();
@Override public void drawSolidPolygon(Vec2[] vertices, int vertexCount, Color3f color) { GL2 gl = panel.getGL().getGL2(); gl.glPushMatrix(); transformViewport(gl, zero); gl.glBegin(GL2.GL_TRIANGLE_FAN); gl.glColor4f(color.x, color.y, color.z, .4f); for (int i = 0; i < vertexCount; i++) { Vec2 v = vertices[i]; gl.glVertex2f(v.x, v.y); } gl.glEnd(); 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(); }
@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(); }
@Override public void drawParticles(Vec2[] centers, float radius, ParticleColor[] colors, int count) { GL2 gl = panel.getGL().getGL2(); gl.glPushMatrix(); transformViewport(gl, zero); 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); gl.glVertex3f(x + cx, y + cy, 0); float temp = x; x = c * x - s * y; y = s * temp + c * y; gl.glEnd(); gl.glPopMatrix();
@Override public void drawParticlesWireframe(Vec2[] centers, float radius, ParticleColor[] colors, int count) { GL2 gl = panel.getGL().getGL2(); gl.glPushMatrix(); transformViewport(gl, zero); 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); gl.glVertex3f(x + cx, y + cy, 0); float temp = x; x = c * x - s * y; y = s * temp + c * y; gl.glEnd(); gl.glPopMatrix();