Java Code Examples for org.lwjgl.opengl.GL11#glVertex3f()
The following examples show how to use
org.lwjgl.opengl.GL11#glVertex3f() .
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: Snippet195.java From ldparteditor with MIT License | 6 votes |
static void drawTorus(float r, float R, int nsides, int rings) { float ringDelta = 2.0f * (float) Math.PI / rings; float sideDelta = 2.0f * (float) Math.PI / nsides; float theta = 0.0f, cosTheta = 1.0f, sinTheta = 0.0f; for (int i = rings - 1; i >= 0; i--) { float theta1 = theta + ringDelta; float cosTheta1 = (float) Math.cos(theta1); float sinTheta1 = (float) Math.sin(theta1); GL11.glBegin(GL11.GL_QUAD_STRIP); float phi = 0.0f; for (int j = nsides; j >= 0; j--) { phi += sideDelta; float cosPhi = (float) Math.cos(phi); float sinPhi = (float) Math.sin(phi); float dist = R + r * cosPhi; GL11.glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi); GL11.glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi); GL11.glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi); GL11.glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi); } GL11.glEnd(); theta = theta1; cosTheta = cosTheta1; sinTheta = sinTheta1; } }
Example 2
Source File: DebugRender.java From tribaltrouble with GNU General Public License v2.0 | 6 votes |
public final static void drawSphere(float origin_x, float origin_y, float origin_z, float radius, float r, float g, float b) { float x, y, z; GL11.glDisable(GL11.GL_TEXTURE_2D); // GL11.glDisable(GL11.GL_LIGHTING); GL11.glColor3f(r, g, b); for (float phi = 0; phi < (float)java.lang.StrictMath.PI; phi += CIRCLE_DELTA) { GL11.glBegin(GL11.GL_LINE_LOOP); for (float rho = 0f; rho < (float)java.lang.StrictMath.PI*2; rho += ANGLE_DELTA) { x = radius*(float)java.lang.StrictMath.cos(rho); z = radius*(float)java.lang.StrictMath.sin(rho); y = x*(float)java.lang.StrictMath.sin(phi); x *= (float)java.lang.StrictMath.cos(phi); GL11.glVertex3f(x + origin_x, y + origin_y, z + origin_z); } GL11.glEnd(); } drawCircle(radius, origin_x, origin_y, origin_z); // GL11.glEnable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_TEXTURE_2D); }
Example 3
Source File: SelectionDelegate.java From tribaltrouble with GNU General Public License v2.0 | 6 votes |
public final void render2D() { if (selection) { GL11.glColor3f(.3f, 1f, 0f); GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_LINE); GL11.glPolygonMode(GL11.GL_BACK, GL11.GL_LINE); GL11.glDisable(GL11.GL_CULL_FACE); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glBegin(GL11.GL_QUADS); GL11.glVertex3f(selection_x1, selection_y1, 0f); GL11.glVertex3f(selection_x2, selection_y1, 0f); GL11.glVertex3f(selection_x2, selection_y2, 0f); GL11.glVertex3f(selection_x1, selection_y2, 0f); GL11.glEnd(); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glEnable(GL11.GL_CULL_FACE); GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL); GL11.glPolygonMode(GL11.GL_BACK, GL11.GL_FILL); } }
Example 4
Source File: EmitterRenderer.java From tribaltrouble with GNU General Public License v2.0 | 6 votes |
private static void render2DParticle(Particle particle, Emitter emitter) { float x = particle.getPosX(); float y = particle.getPosY(); float z = particle.getPosZ(); float radius_x = particle.getRadiusX()*emitter.getScaleX(); float radius_y = particle.getRadiusY()*emitter.getScaleY(); float radius_z = particle.getRadiusZ()*emitter.getScaleZ(); GL11.glColor4f(particle.getColorR(), particle.getColorG(), particle.getColorB(), particle.getColorA()); GL11.glTexCoord2f(particle.getU1(), particle.getV1()); GL11.glVertex3f(x - right_plus_up.getX()*radius_x, y - right_plus_up.getY()*radius_y, z - right_plus_up.getZ()*radius_z); GL11.glTexCoord2f(particle.getU2(), particle.getV2()); GL11.glVertex3f(x + right_minus_up.getX()*radius_x, y + right_minus_up.getY()*radius_y, z + right_minus_up.getZ()*radius_z); GL11.glTexCoord2f(particle.getU3(), particle.getV3()); GL11.glVertex3f(x + right_plus_up.getX()*radius_x, y + right_plus_up.getY()*radius_y, z + right_plus_up.getZ()*radius_z); GL11.glTexCoord2f(particle.getU4(), particle.getV4()); GL11.glVertex3f(x - right_minus_up.getX()*radius_x, y - right_minus_up.getY()*radius_y, z - right_minus_up.getZ()*radius_z); }
Example 5
Source File: GLUtils.java From ehacks-pro with GNU General Public License v3.0 | 5 votes |
public static void renderBlock(int x, int y, int z, XRayBlock block) { GL11.glColor4ub(((byte) block.r), ((byte) block.g), ((byte) block.b), ((byte) block.a)); GL11.glVertex3f(x, y, z); GL11.glVertex3f((x + 1), y, z); GL11.glVertex3f((x + 1), y, z); GL11.glVertex3f((x + 1), y, (z + 1)); GL11.glVertex3f(x, y, z); GL11.glVertex3f(x, y, (z + 1)); GL11.glVertex3f(x, y, (z + 1)); GL11.glVertex3f((x + 1), y, (z + 1)); GL11.glVertex3f(x, (y + 1), z); GL11.glVertex3f((x + 1), (y + 1), z); GL11.glVertex3f((x + 1), (y + 1), z); GL11.glVertex3f((x + 1), (y + 1), (z + 1)); GL11.glVertex3f(x, (y + 1), z); GL11.glVertex3f(x, (y + 1), (z + 1)); GL11.glVertex3f(x, (y + 1), (z + 1)); GL11.glVertex3f((x + 1), (y + 1), (z + 1)); GL11.glVertex3f(x, y, z); GL11.glVertex3f(x, (y + 1), z); GL11.glVertex3f(x, y, (z + 1)); GL11.glVertex3f(x, (y + 1), (z + 1)); GL11.glVertex3f((x + 1), y, z); GL11.glVertex3f((x + 1), (y + 1), z); GL11.glVertex3f((x + 1), y, (z + 1)); GL11.glVertex3f((x + 1), (y + 1), (z + 1)); }
Example 6
Source File: GData4.java From ldparteditor with MIT License | 5 votes |
@Override public void drawGL20_BFCuncertified(Composite3D c3d) { if (!visible) return; if (a < 1f && c3d.isDrawingSolidMaterials() || !c3d.isDrawingSolidMaterials() && a == 1f) return; GL11.glBegin(GL11.GL_QUADS); if (GData.globalNegativeDeterminant) { GL11.glColor4f(View.BFC_uncertified_Colour_r[0], View.BFC_uncertified_Colour_g[0], View.BFC_uncertified_Colour_b[0], a); GL11.glNormal3f(xn, yn, zn); GL11.glVertex3f(x1, y1, z1); GL11.glVertex3f(x4, y4, z4); GL11.glVertex3f(x3, y3, z3); GL11.glVertex3f(x2, y2, z2); GL11.glNormal3f(-xn, -yn, -zn); GL11.glVertex3f(x1, y1, z1); GL11.glVertex3f(x2, y2, z2); GL11.glVertex3f(x3, y3, z3); GL11.glVertex3f(x4, y4, z4); } else { GL11.glColor4f(View.BFC_uncertified_Colour_r[0], View.BFC_uncertified_Colour_g[0], View.BFC_uncertified_Colour_b[0], a); GL11.glNormal3f(-xn, -yn, -zn); GL11.glVertex3f(x1, y1, z1); GL11.glVertex3f(x4, y4, z4); GL11.glVertex3f(x3, y3, z3); GL11.glVertex3f(x2, y2, z2); GL11.glNormal3f(xn, yn, zn); GL11.glVertex3f(x1, y1, z1); GL11.glVertex3f(x2, y2, z2); GL11.glVertex3f(x3, y3, z3); GL11.glVertex3f(x4, y4, z4); } GL11.glEnd(); }
Example 7
Source File: UnitGrid.java From tribaltrouble with GNU General Public License v2.0 | 5 votes |
private final void debugRenderQuad(int x, int y) { final float OFFSET = 2f; final float RADIUS = .5f; int s = HeightMap.METERS_PER_UNIT_GRID; float xf = (x + .5f)*s; float yf = (y + .5f)*s; float z = heightmap.getNearestHeight(xf, yf) + OFFSET; GL11.glVertex3f(xf - RADIUS, yf - RADIUS, z); GL11.glVertex3f(xf + RADIUS, yf + RADIUS, z); GL11.glVertex3f(xf + RADIUS, yf - RADIUS, z); GL11.glVertex3f(xf - RADIUS, yf + RADIUS, z); }
Example 8
Source File: GData4.java From ldparteditor with MIT License | 5 votes |
@Override public void drawGL20_RandomColours(Composite3D c3d) { if (!visible) return; if (a < 1f && c3d.isDrawingSolidMaterials() || !c3d.isDrawingSolidMaterials() && a == 1f) return; final float r = MathHelper.randomFloat(ID, 0); final float g = MathHelper.randomFloat(ID, 1); final float b = MathHelper.randomFloat(ID, 2); GL11.glBegin(GL11.GL_QUADS); if (GData.globalNegativeDeterminant) { GL11.glColor4f(r, g, b, a); GL11.glNormal3f(xn, yn, zn); GL11.glVertex3f(x1, y1, z1); GL11.glVertex3f(x4, y4, z4); GL11.glVertex3f(x3, y3, z3); GL11.glVertex3f(x2, y2, z2); GL11.glNormal3f(-xn, -yn, -zn); GL11.glVertex3f(x1, y1, z1); GL11.glVertex3f(x2, y2, z2); GL11.glVertex3f(x3, y3, z3); GL11.glVertex3f(x4, y4, z4); } else { GL11.glColor4f(r, g, b, a); GL11.glNormal3f(-xn, -yn, -zn); GL11.glVertex3f(x1, y1, z1); GL11.glVertex3f(x4, y4, z4); GL11.glVertex3f(x3, y3, z3); GL11.glVertex3f(x2, y2, z2); GL11.glNormal3f(xn, yn, zn); GL11.glVertex3f(x1, y1, z1); GL11.glVertex3f(x2, y2, z2); GL11.glVertex3f(x3, y3, z3); GL11.glVertex3f(x4, y4, z4); } GL11.glEnd(); }
Example 9
Source File: SpriteRenderer.java From tribaltrouble with GNU General Public License v2.0 | 5 votes |
public final void renderNoDetail(ModelState model) { float[] color = model.getTeamColor(); GL11.glColor3f(color[0], color[1], color[2]); GL11.glBegin(GL11.GL_QUADS); float x = model.getModel().getPositionX(); float y = model.getModel().getPositionY(); float z = model.getModel().getPositionZ(); float r = model.getModel().getNoDetailSize(); GL11.glVertex3f(x - r, y - r, z); GL11.glVertex3f(x + r, y - r, z); GL11.glVertex3f(x + r, y + r, z); GL11.glVertex3f(x - r, y + r, z); GL11.glEnd(); }
Example 10
Source File: GData3.java From ldparteditor with MIT License | 5 votes |
@Override public void drawGL20_BFCuncertified(Composite3D c3d) { if (!visible) return; if (a < 1f && c3d.isDrawingSolidMaterials() || !c3d.isDrawingSolidMaterials() && a == 1f) return; GL11.glBegin(GL11.GL_TRIANGLES); if (GData.globalNegativeDeterminant) { GL11.glColor4f(View.BFC_uncertified_Colour_r[0], View.BFC_uncertified_Colour_g[0], View.BFC_uncertified_Colour_b[0], a); GL11.glNormal3f(xn, yn, zn); GL11.glVertex3f(x1, y1, z1); GL11.glVertex3f(x3, y3, z3); GL11.glVertex3f(x2, y2, z2); GL11.glNormal3f(-xn, -yn, -zn); GL11.glVertex3f(x1, y1, z1); GL11.glVertex3f(x2, y2, z2); GL11.glVertex3f(x3, y3, z3); } else { GL11.glColor4f(View.BFC_uncertified_Colour_r[0], View.BFC_uncertified_Colour_g[0], View.BFC_uncertified_Colour_b[0], a); GL11.glNormal3f(xn, yn, zn); GL11.glVertex3f(x1, y1, z1); GL11.glVertex3f(x2, y2, z2); GL11.glVertex3f(x3, y3, z3); GL11.glNormal3f(-xn, -yn, -zn); GL11.glVertex3f(x1, y1, z1); GL11.glVertex3f(x3, y3, z3); GL11.glVertex3f(x2, y2, z2); } GL11.glEnd(); }
Example 11
Source File: PGData5.java From ldparteditor with MIT License | 5 votes |
@Override public void drawBFCprimitive_GL20(int drawOnlyMode) { if (drawOnlyMode == 1) return; // GL11.glLineWidth(View.lineWidthGL[0]); GL11.glLineWidth(1f); GL11.glColor4f(View.primitive_condline_Colour_r[0], View.primitive_condline_Colour_g[0], View.primitive_condline_Colour_b[0], 1f); GL11.glBegin(GL11.GL_LINES); GL11.glVertex3f(x1, y1, z1); GL11.glVertex3f(x2, y2, z2); GL11.glEnd(); }
Example 12
Source File: PGData2.java From ldparteditor with MIT License | 5 votes |
@Override public void drawBFCprimitive_GL20(int drawOnlyMode) { if (drawOnlyMode == 1) return; // GL11.glLineWidth(View.lineWidthGL[0]); GL11.glLineWidth(1f); GL11.glColor4f(View.primitive_edge_Colour_r[0], View.primitive_edge_Colour_g[0], View.primitive_edge_Colour_b[0], 1f); GL11.glBegin(GL11.GL_LINES); GL11.glVertex3f(x1, y1, z1); GL11.glVertex3f(x2, y2, z2); GL11.glEnd(); }
Example 13
Source File: Frustum.java From tectonicus with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void lineBetween(int start, int end) { GL11.glVertex3f(points[start].x, points[start].y, points[start].z); GL11.glVertex3f(points[end].x, points[end].y, points[end].z); }
Example 14
Source File: LwjglRasteriser.java From tectonicus with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void vertex(final float x, final float y, final float z) { GL11.glVertex3f(x, y, z); }
Example 15
Source File: GData3.java From ldparteditor with MIT License | 4 votes |
public void drawProtractor_GL20(boolean selected, Composite3D c3d, BigDecimal x1c, BigDecimal y1c, BigDecimal z1c, BigDecimal x2c, BigDecimal y2c, BigDecimal z2c, BigDecimal x3c, BigDecimal y3c, BigDecimal z3c) { final java.text.DecimalFormat NUMBER_FORMAT2F = new java.text.DecimalFormat(View.NUMBER_FORMAT2F, new DecimalFormatSymbols(MyLanguage.LOCALE)); final OpenGLRenderer20 renderer = (OpenGLRenderer20) c3d.getRenderer(); final float zoom = 1f / c3d.getZoom(); GL11.glDisable(GL11.GL_LIGHTING); GL11.glLineWidth(View.lineWidthGL[0]); if (selected) { GL11.glColor4f(View.vertex_selected_Colour_r[0], View.vertex_selected_Colour_g[0], View.vertex_selected_Colour_b[0], 1f); GL11.glBegin(GL11.GL_LINES); GL11.glVertex3f(x1, y1, z1); GL11.glVertex3f(x2, y2, z2); GL11.glEnd(); } else { final float s = ((r + g + b) / 3 + .5f) % 1f; GL11.glColor4f(s, s, s, 1f); GL11.glBegin(GL11.GL_LINES); GL11.glVertex3f(x1, y1, z1); GL11.glVertex3f(x2, y2, z2); GL11.glEnd(); } GL11.glColor4f(r, g, b, 1f); GL11.glBegin(GL11.GL_LINES); GL11.glVertex3f(x1, y1, z1); GL11.glVertex3f(x3, y3, z3); GL11.glEnd(); final Vector4f textOrigin = new Vector4f(x1, y1, z1, 1f); Matrix4f.transform(c3d.getRotation(), textOrigin, textOrigin); Vector3d va = new Vector3d(x1c, y1c, z1c); Vector3d vb = new Vector3d(x2c, y2c, z2c); Vector3d vc = new Vector3d(x3c, y3c, z3c); vb = Vector3d.sub(va, vb); vc = Vector3d.sub(va, vc); double angle = Vector3d.angle(vb, vc); BigDecimal ang = new BigDecimal(angle); String angle_s = NUMBER_FORMAT2F.format(ang) + "°"; //$NON-NLS-1$ float sx1 = x1 + (x2 - x1) * .2f; float sy1 = y1 + (y2 - y1) * .2f; float sz1 = z1 + (z2 - z1) * .2f; float sx2 = x1 + (x3 - x1) * .2f; float sy2 = y1 + (y3 - y1) * .2f; float sz2 = z1 + (z3 - z1) * .2f; float sx1t = x1 + (x2 - x1) * .25f; float sy1t = y1 + (y2 - y1) * .25f; float sz1t = z1 + (z2 - z1) * .25f; float sx2t = x1 + (x3 - x1) * .25f; float sy2t = y1 + (y3 - y1) * .25f; float sz2t = z1 + (z3 - z1) * .25f; float sx1tt = x1 + (x2 - x1) * .24f; float sy1tt = y1 + (y2 - y1) * .24f; float sz1tt = z1 + (z2 - z1) * .24f; float sx2tt = x1 + (x3 - x1) * .24f; float sy2tt = y1 + (y3 - y1) * .24f; float sz2tt = z1 + (z3 - z1) * .24f; float sx3 = sx1t * .5f + sx2t * .5f; float sy3 = sy1t * .5f + sy2t * .5f; float sz3 = sz1t * .5f + sz2t * .5f; float sx3r = sx1tt * .7f + sx2tt * .3f; float sy3r = sy1tt * .7f + sy2tt * .3f; float sz3r = sz1tt * .7f + sz2tt * .3f; float sx3l = sx1tt * .3f + sx2tt * .7f; float sy3l = sy1tt * .3f + sy2tt * .7f; float sz3l = sz1tt * .3f + sz2tt * .7f; GL11.glBegin(GL11.GL_LINES); GL11.glVertex3f(sx1, sy1, sz1); GL11.glVertex3f(sx3r, sy3r, sz3r); GL11.glVertex3f(sx3r, sy3r, sz3r); GL11.glVertex3f(sx3, sy3, sz3); GL11.glVertex3f(sx3, sy3, sz3); GL11.glVertex3f(sx3l, sy3l, sz3l); GL11.glVertex3f(sx3l, sy3l, sz3l); GL11.glVertex3f(sx2, sy2, sz2); GL11.glEnd(); GL11.glPushMatrix(); GL11.glMultMatrixf(renderer.getRotationInverse()); GL11.glDisable(GL11.GL_CULL_FACE); GL11.glDisable(GL11.GL_DEPTH_TEST); PGData3.beginDrawText(); GL11.glColor4f(r, g, b, 1f); drawNumber(angle_s, textOrigin.x, textOrigin.y, textOrigin.z, zoom); PGData3.endDrawText(); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glEnable(GL11.GL_CULL_FACE); GL11.glPopMatrix(); GL11.glEnable(GL11.GL_LIGHTING); }
Example 16
Source File: Test.java From tribaltrouble with GNU General Public License v2.0 | 4 votes |
public final static void main(String[] args) { try { Display.setDisplayMode(new DisplayMode(DISPLAY_WIDTH, DISPLAY_HEIGHT)); Display.create(); initGL(); // Load font InputStream font_is = Utils.makeURL("/fonts/tahoma.ttf").openStream(); java.awt.Font src_font = java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT, font_is); java.awt.Font font = src_font.deriveFont(14f); // Load text InputStreamReader text_is = new InputStreamReader(Utils.makeURL("/test_text.txt").openStream()); StringBuffer str_buffer = new StringBuffer(); int c = text_is.read(); do { str_buffer.append((char)c); c = text_is.read(); } while (c != -1); String str = str_buffer.toString(); // Build texture int[] pixels = new int[WIDTH*HEIGHT]; // ByteBuffer pixel_data = ByteBuffer.wrap(pixels); // NEW // pixelDataFromString(WIDTH, HEIGHT, str, font, pixels); // NEW IntBuffer pixel_data = BufferUtils.createIntBuffer(WIDTH*HEIGHT); // OLD pixel_data.put(pixels); // OLD pixel_data.rewind(); int texture_handle = createTexture(WIDTH, HEIGHT, pixel_data); FontRenderContext frc = g2d.getFontRenderContext(); AttributedString att_str = new AttributedString(str); att_str.addAttribute(TextAttribute.FONT, font); AttributedCharacterIterator iterator = att_str.getIterator(); LineBreakMeasurer measurer = new LineBreakMeasurer(iterator, frc); while (!Display.isCloseRequested()) { long start_time = System.currentTimeMillis(); for (int i = 0; i < 10; i++) { pixelDataFromString(WIDTH, HEIGHT, str, font, pixels, measurer); pixel_data.put(pixels); // OLD pixel_data.rewind(); //texture_handle = createTexture(WIDTH, HEIGHT, pixel_data); updateTexture(WIDTH, HEIGHT, pixel_data); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glLoadIdentity(); // Background /* GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glColor4f(.1f, .1f, .1f, 1f); GL11.glBegin(GL11.GL_QUADS); GL11.glVertex3f(0f, DISPLAY_HEIGHT-RENDER_SIZE, 1f); GL11.glVertex3f(RENDER_SIZE, DISPLAY_HEIGHT-RENDER_SIZE, 1f); GL11.glVertex3f(RENDER_SIZE, DISPLAY_HEIGHT, 1f); GL11.glVertex3f(0f, DISPLAY_HEIGHT, 1f); GL11.glEnd(); */ // Text GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glColor4f(1f, 1f, 1f, 1f); GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(0f, 1f); GL11.glVertex3f(0f, DISPLAY_HEIGHT-RENDER_SIZE, 1f); GL11.glTexCoord2f(1f, 1f); GL11.glVertex3f(RENDER_SIZE, DISPLAY_HEIGHT-RENDER_SIZE, 1f); GL11.glTexCoord2f(1f, 0f); GL11.glVertex3f(RENDER_SIZE, DISPLAY_HEIGHT, 1f); GL11.glTexCoord2f(0f, 0f); GL11.glVertex3f(0f, DISPLAY_HEIGHT, 1f); GL11.glEnd(); Display.update(); } long total_time = System.currentTimeMillis() - start_time; System.out.println("total_time = " + total_time); } Display.destroy(); } catch (Exception t) { t.printStackTrace(); } }
Example 17
Source File: ArrowBlunt.java From ldparteditor with MIT License | 4 votes |
public void draw(float x, float y, float z, float zoom) { final float zoom_inv = 1f / zoom; GL11.glPushMatrix(); GL11.glTranslatef(x, y, z); GL11.glMultMatrixf(matrix); GL11.glScalef(zoom_inv, zoom_inv, zoom_inv); GL11.glLineWidth(line_width); GL11.glColor3f(r, g, b); GL11.glBegin(GL11.GL_LINES); GL11.glVertex3f(0f, 0f, 0f); GL11.glVertex3f(0f, line_end, 0f); GL11.glEnd(); GL11.glBegin(GL11.GL_QUADS); GL11.glVertex3f(cube_x[3], cube_y[3], cube_z[3]); GL11.glVertex3f(cube_x[2], cube_y[2], cube_z[2]); GL11.glVertex3f(cube_x[1], cube_y[1], cube_z[1]); GL11.glVertex3f(cube_x[0], cube_y[0], cube_z[0]); GL11.glVertex3f(cube_x[4], cube_y[4], cube_z[4]); GL11.glVertex3f(cube_x[5], cube_y[5], cube_z[5]); GL11.glVertex3f(cube_x[6], cube_y[6], cube_z[6]); GL11.glVertex3f(cube_x[7], cube_y[7], cube_z[7]); GL11.glEnd(); GL11.glBegin(GL11.GL_QUAD_STRIP); GL11.glVertex3f(cube_x[0], cube_y[0], cube_z[0]); GL11.glVertex3f(cube_x[4], cube_y[4], cube_z[4]); GL11.glVertex3f(cube_x[3], cube_y[3], cube_z[3]); GL11.glVertex3f(cube_x[7], cube_y[7], cube_z[7]); GL11.glVertex3f(cube_x[2], cube_y[2], cube_z[2]); GL11.glVertex3f(cube_x[6], cube_y[6], cube_z[6]); GL11.glVertex3f(cube_x[1], cube_y[1], cube_z[1]); GL11.glVertex3f(cube_x[5], cube_y[5], cube_z[5]); GL11.glVertex3f(cube_x[0], cube_y[0], cube_z[0]); GL11.glVertex3f(cube_x[4], cube_y[4], cube_z[4]); GL11.glEnd(); GL11.glPopMatrix(); }
Example 18
Source File: Model.java From pycode-minecraft with MIT License | 4 votes |
public void genList() { this.glList = GL11.glGenLists(1); GL11.glNewList(this.glList, GL11.GL_COMPILE); // if use_texture: glEnable(GL_TEXTURE_2D) GL11.glFrontFace(GL11.GL_CCW); GL11.glEnable(GL11.GL_CULL_FACE); GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL); GL11.glDepthFunc(GL11.GL_LESS); GL11.glCullFace(GL11.GL_BACK); String currentMaterial = ""; Material mtl; for (Face face : this.faces) { if (!face.material.equals(currentMaterial)) { currentMaterial = face.material; mtl = this.materials.get(face.material); if (mtl == null) { GL11.glColor3f(1, 1, 1); } else { // if 'texture_Kd' in mtl: // # use diffuse texmap // glBindTexture(GL_TEXTURE_2D, mtl['texture_Kd']) GL11.glColor3f(mtl.diffuse.x, mtl.diffuse.y, mtl.diffuse.z); } } GL11.glBegin(GL11.GL_POLYGON); for (int i = 0; i < face.vertexes.size(); i++) { if (face.normals.get(i) != 0) { Vector3f n = this.normals.get(face.normals.get(i)); GL11.glNormal3f(n.x, n.y, n.z); } // if texture_coords[i]: // glTexCoord2fv(self.texcoords[texture_coords[i] - 1]) Vector3f v = this.vertices.get(face.vertexes.get(i)); GL11.glVertex3f(v.x, v.y, v.z); } GL11.glEnd(); } GL11.glCullFace(GL11.GL_BACK); GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL); GL11.glDisable(GL11.GL_CULL_FACE); // if use_texture: glDisable(GL11.GL_TEXTURE_2D); GL11.glEndList(); }
Example 19
Source File: Graphics.java From AnyaBasic with MIT License | 4 votes |
public void drawSpriteOnLine( int x1, int y1, int x2, int y2, int width, int type, float r, float g, float b, float a ) { SpriteGL sprite = glowImages.getSprite(type % glowImages.getNumImages()); // Only change active texture when there is a need // Speeds up the rendering by batching textures if ( sprite.textureID != currentTexture ) { GL11.glBindTexture( GL11.GL_TEXTURE_2D, sprite.textureID ); currentTexture = sprite.textureID; } GL11.glColor4f( r, g, b, a ) ; float u1 = sprite.u1; float v1 = sprite.v1; float u2 = sprite.u2; float v2 = sprite.v2; float uh = (u1 + u2)/2.0f; float nx,ny; nx = -( y2-y1 ); ny = ( x2-x1 ); float leng; leng = (float)Math.sqrt( nx * nx + ny * ny ); nx = nx / leng; ny = ny / leng; nx *= width / 2.0; ny *= width / 2.0; float lx1, ly1, lx2, ly2, lx3, ly3, lx4, ly4; lx1 = x2 + nx; ly1 = y2 + ny; lx2 = x2 - nx; ly2 = y2 - ny; lx3 = x1 - nx; ly3 = y1 - ny; lx4 = x1 + nx; ly4 = y1 + ny; // MAIN GL11.glBegin( GL11.GL_QUADS ); GL11.glTexCoord2f( uh, v1 ); GL11.glVertex3f( lx1, ly1, 0.0f ); GL11.glTexCoord2f( uh, v2 ); GL11.glVertex3f( lx2, ly2, 0.0f ); GL11.glTexCoord2f( uh, v2 ); GL11.glVertex3f( lx3, ly3, 0.0f ); GL11.glTexCoord2f( uh, v1 ); GL11.glVertex3f( lx4, ly4, 0.0f ); GL11.glEnd(); //RIGHT float lx5, ly5, lx6, ly6, vx, vy; vx = ( x2-x1 ); vy = ( y2-y1 ); leng = (float)Math.sqrt( vx * vx + vy * vy ); vx = vx / leng; vy = vy / leng; vx *= width / 2.0; vy *= width / 2.0; lx5 = lx1 + vx; ly5 = ly1 + vy; lx6 = lx2 + vx; ly6 = ly2 + vy; GL11.glBegin( GL11.GL_QUADS ); GL11.glTexCoord2f( uh, v1 ); GL11.glVertex3f( lx1, ly1,0.0f ); GL11.glTexCoord2f( u2, v1 ); GL11.glVertex3f( lx5, ly5,0.0f ); GL11.glTexCoord2f( u2, v2 ); GL11.glVertex3f( lx6, ly6,0.0f ); GL11.glTexCoord2f( uh, v2 ); GL11.glVertex3f( lx2, ly2,0.0f ); GL11.glEnd(); // LEFT lx5 = lx4 - vx; ly5 = ly4 - vy; lx6 = lx3 - vx; ly6 = ly3 - vy; GL11.glBegin( GL11.GL_QUADS ); GL11.glTexCoord2f( uh, v1 ); GL11.glVertex3f( lx4, ly4, 0.0f ); GL11.glTexCoord2f( uh, v2 ); GL11.glVertex3f( lx3, ly3 ,0.0f ); GL11.glTexCoord2f( u2, v2 ); GL11.glVertex3f( lx6, ly6, 0.0f ); GL11.glTexCoord2f( u2, v1 ); GL11.glVertex3f( lx5, ly5, 0.0f ); GL11.glEnd(); }
Example 20
Source File: Graphics.java From AnyaBasic with MIT License | 4 votes |
public void drawSpriteOnLine( int x1, int y1, int x2, int y2, int width, int type ) { SpriteGL sprite = glowImages.getSprite(type % glowImages.getNumImages()); // Only change active texture when there is a need // Speeds up the rendering by batching textures if ( sprite.textureID != currentTexture ) { GL11.glBindTexture( GL11.GL_TEXTURE_2D, sprite.textureID ); currentTexture = sprite.textureID; } float u1 = sprite.u1; float v1 = sprite.v1; float u2 = sprite.u2; float v2 = sprite.v2; float uh = (u1 + u2)/2.0f; float nx,ny; nx = -( y2-y1 ); ny = ( x2-x1 ); float leng; leng = (float)Math.sqrt( nx * nx + ny * ny ); nx = nx / leng; ny = ny / leng; nx *= width / 2.0; ny *= width / 2.0; float lx1, ly1, lx2, ly2, lx3, ly3, lx4, ly4; lx1 = x2 + nx; ly1 = y2 + ny; lx2 = x2 - nx; ly2 = y2 - ny; lx3 = x1 - nx; ly3 = y1 - ny; lx4 = x1 + nx; ly4 = y1 + ny; // MAIN GL11.glBegin( GL11.GL_QUADS ); GL11.glTexCoord2f( uh, v1 ); GL11.glVertex3f( lx1, ly1, 0.0f ); GL11.glTexCoord2f( uh, v2 ); GL11.glVertex3f( lx2, ly2, 0.0f ); GL11.glTexCoord2f( uh, v2 ); GL11.glVertex3f( lx3, ly3, 0.0f ); GL11.glTexCoord2f( uh, v1 ); GL11.glVertex3f( lx4, ly4, 0.0f ); GL11.glEnd(); //RIGHT float lx5, ly5, lx6, ly6, vx, vy; vx = ( x2-x1 ); vy = ( y2-y1 ); leng = (float)Math.sqrt( vx * vx + vy * vy ); vx = vx / leng; vy = vy / leng; vx *= width / 2.0; vy *= width / 2.0; lx5 = lx1 + vx; ly5 = ly1 + vy; lx6 = lx2 + vx; ly6 = ly2 + vy; GL11.glBegin( GL11.GL_QUADS ); GL11.glTexCoord2f( uh, v1 ); GL11.glVertex3f( lx1, ly1,0.0f ); GL11.glTexCoord2f( u2, v1 ); GL11.glVertex3f( lx5, ly5,0.0f ); GL11.glTexCoord2f( u2, v2 ); GL11.glVertex3f( lx6, ly6,0.0f ); GL11.glTexCoord2f( uh, v2 ); GL11.glVertex3f( lx2, ly2,0.0f ); GL11.glEnd(); // LEFT lx5 = lx4 - vx; ly5 = ly4 - vy; lx6 = lx3 - vx; ly6 = ly3 - vy; GL11.glBegin( GL11.GL_QUADS ); GL11.glTexCoord2f( uh, v1 ); GL11.glVertex3f( lx4, ly4, 0.0f ); GL11.glTexCoord2f( uh, v2 ); GL11.glVertex3f( lx3, ly3 ,0.0f ); GL11.glTexCoord2f( u2, v2 ); GL11.glVertex3f( lx6, ly6, 0.0f ); GL11.glTexCoord2f( u2, v1 ); GL11.glVertex3f( lx5, ly5, 0.0f ); GL11.glEnd(); }