List of usage examples for org.lwjgl.opengl GL11 glVertex2f
public static native void glVertex2f(@NativeType("GLfloat") float x, @NativeType("GLfloat") float y);
From source file:net.bryanbergen.lwjgl.test.Main.java
public static void main(String... args) { Dimension d = new Dimension(0, 0, 960, 600); Window.Builder builder = new Window.Builder(d); builder.setTitle("Test Window"); builder.setFullscreen(false);/* www .j a v a2s . c o m*/ builder.setResizable(true); builder.setVisible(true); builder.setVsync(true); builder.setBackground(Color.BLUE); Window window = builder.build(); window.addKeyListener(new KeyAdapter() { @Override public void KeyPressed(KeyEvent event) { if (event.getKeycode() == KeyCode.KEY_ESCAPE) { window.close(); } } }); window.addKeyListener(new ColorSwapper()); window.addMouseListener(new ColorClicker(window)); while (!window.shouldClose()) { window.clear(); // immediate mode for testing only GL11.glColor3f((float) color.getRed(), (float) color.getGreen(), (float) color.getBlue()); GL11.glBegin(GL_QUADS); GL11.glVertex2f(-.5f, -.5f); GL11.glVertex2f(-.5f, .5f); GL11.glVertex2f(.5f, .5f); GL11.glVertex2f(.5f, -.5f); GL11.glEnd(); window.update(); } window.dispose(); }
From source file:net.kubin.world.World.java
License:Apache License
private void renderOverlay() { Configuration conf = Kubin.getConfiguration(); Game.getInstance().initOverlayRendering(); GL11.glColor3f(1, 1, 1);/*from ww w .j a va2 s . co m*/ if (Game.RENDER_INFORMATION_OVERLAY) { GLFont infoFont = FontStorage.getFont("Monospaced_20"); /* Down Left Info */ infoFont.print(4, 30, _player.coordinatesToString()); infoFont.print(4, 45, "Visible Chunks: " + _visibleChunks.size()); infoFont.print(4, 60, "Updading Blocks: " + _updatingBlocks); infoFont.print(4, 75, "Total Chunks in RAM: " + _chunkManager.getTotalChunkCount()); infoFont.print(4, 90, "Local Chunks: " + _localChunks.size()); infoFont.print(4, 105, "Total Local Blocks: " + _localBlockCount); infoFont.print(4, 120, "Time: " + _time); infoFont.print(4, 135, "Sunlight: " + _sunlight); } /** RENDER **/ if (_activatedInventory != null) { Game.getInstance().renderTransculentOverlayLayer(); _activatedInventory.renderInventory(); } else { int width = conf.getWidth(); int height = conf.getHeight(); // Center Cross GL11.glDisable(GL11.GL_TEXTURE_2D); if (CENTER_CROSS_CALL_LIST == 0) { CENTER_CROSS_CALL_LIST = GL11.glGenLists(1); GL11.glNewList(CENTER_CROSS_CALL_LIST, GL11.GL_COMPILE_AND_EXECUTE); int crossSize = 7; int crossHole = 4; GL11.glLineWidth(2.5f); GL11.glColor3f(255, 255, 255); GL11.glBegin(GL11.GL_LINES); GL11.glVertex3f(width / 2f - crossSize - crossHole, height / 2f, 0); GL11.glVertex3f(width / 2f - crossHole, height / 2f, 0); GL11.glVertex3f(width / 2f + crossSize + crossHole, height / 2f, 0); GL11.glVertex3f(width / 2f + crossHole, height / 2f, 0); GL11.glVertex3f(width / 2f, height / 2f - crossSize - crossHole, 0); GL11.glVertex3f(width / 2f, height / 2f - crossHole, 0); GL11.glVertex3f(width / 2f, height / 2f + crossSize + crossHole, 0); GL11.glVertex3f(width / 2f, height / 2f + crossHole, 0); GL11.glEnd(); GL11.glEndList(); } else { GL11.glCallList(CENTER_CROSS_CALL_LIST); } GL11.glEnable(GL11.GL_TEXTURE_2D); // Inventory bar GL11.glPushMatrix(); Texture texGui = TextureStorage.getTexture("gui.gui"); texGui.bind(); float tileSize = 20.0f / texGui.getImageWidth(); if (INVENTORY_BAR_CALL_LIST == 0) { INVENTORY_BAR_CALL_LIST = GL11.glGenLists(2); /* Bar */ GL11.glNewList(INVENTORY_BAR_CALL_LIST, GL11.GL_COMPILE_AND_EXECUTE); GL11.glTranslatef(width / 2.0f - 9 * 20, 0, 0); GL11.glColor3f(1.0f, 1.0f, 1.0f); GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(0, 0); GL11.glVertex2f(0, 40); GL11.glTexCoord2f(tileSize * 9, 0); GL11.glVertex2f(9 * 40, 40); GL11.glTexCoord2f(tileSize * 9, tileSize); GL11.glVertex2f(9 * 40, 0); GL11.glTexCoord2f(0, tileSize); GL11.glVertex2f(0, 0); GL11.glEnd(); GL11.glEndList(); /* Little frame around selected item */ float frameTileSize = 24.0f / texGui.getImageWidth(); float frameTileY = 22.0f / texGui.getImageHeight(); GL11.glNewList(INVENTORY_BAR_CALL_LIST + 1, GL11.GL_COMPILE); GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(0, frameTileY); GL11.glVertex2f(0, 48); GL11.glTexCoord2f(frameTileSize, frameTileY); GL11.glVertex2f(48, 48); GL11.glTexCoord2f(frameTileSize, frameTileY + frameTileSize); GL11.glVertex2f(48, 0); GL11.glTexCoord2f(0, frameTileY + frameTileSize); GL11.glVertex2f(0, 0); GL11.glEnd(); GL11.glEndList(); } else { GL11.glCallList(INVENTORY_BAR_CALL_LIST); } /* Content */ GL11.glPushMatrix(); GL11.glTranslatef(20, 20, 0); for (int i = 0; i < 9; ++i) { InventoryPlace place = getActivePlayer().getInventory().getInventoryPlace(i); if (place != null) { place.render(); } GL11.glTranslatef(40, 0, 0); } texGui.bind(); GL11.glPopMatrix(); GL11.glTranslatef(getActivePlayer().getSelectedInventoryItemIndex() * 40.0f - 4, -4, 0); GL11.glCallList(INVENTORY_BAR_CALL_LIST + 1); GL11.glPopMatrix(); } }
From source file:net.phatcode.rel.multimedia.Graphics.java
License:Open Source License
public void drawEllipse(int x, int y, int a, int b, int degrees, float red, float green, float blue, float alpha) { // these constants decide the quality of the ellipse final float pi = (float) Math.PI; final float twopi = 2 * pi; // two pi (radians in a circle) final int face_length = 8; // approx. face length in pixels final int max_faces = 256; // maximum number of faces in ellipse final int min_faces = 16; // minimum number of faces in ellipse // approx. ellipse circumference (hudson's method) float h = (a - b * a - b) / (float) (a + b * a + b); float circumference = 0.25f * pi * (a + b) * (3 * (1 + h * 0.25f) + 1 / (1 - h * 0.25f)); // number of faces in ellipse int num_faces = (int) (circumference / (float) face_length); // clamp number of faces if (num_faces > max_faces) num_faces = max_faces;//w w w . jav a2 s . co m if (num_faces < min_faces) num_faces = min_faces; // keep number of faces divisible by 4 num_faces -= (num_faces & 3); // precalc cosine theta float angle = degrees * pi / 180.0f; float s = (float) Math.sin(twopi / (float) num_faces); float c = (float) Math.cos(twopi / (float) num_faces); float xx = 1; float yy = 0; float xt; float ax = (float) Math.cos(angle); float ay = (float) Math.sin(angle); // draw ellipse GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glColor4f(red, green, blue, alpha); int i; GL11.glBegin(GL11.GL_LINE_LOOP); for (i = 0; i < num_faces; i++) { xt = xx; xx = c * xx - s * yy; yy = s * xt + c * yy; GL11.glVertex2f(x + a * xx * ax - b * yy * ay, y + a * xx * ay + b * yy * ax); } GL11.glVertex2f(x + a * ax, y + a * ay); GL11.glEnd(); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glColor4f(1, 1, 1, 1); }
From source file:net.phatcode.rel.multimedia.Graphics.java
License:Open Source License
public void drawEllipse(int x, int y, int a, int b, int degrees) { // these constants decide the quality of the ellipse final float pi = (float) Math.PI; final float twopi = 2 * pi; // two pi (radians in a circle) final int face_length = 8; // approx. face length in pixels final int max_faces = 256; // maximum number of faces in ellipse final int min_faces = 16; // minimum number of faces in ellipse // approx. ellipse circumference (hudson's method) float h = (a - b * a - b) / (float) (a + b * a + b); float circumference = 0.25f * pi * (a + b) * (3 * (1 + h * 0.25f) + 1 / (1 - h * 0.25f)); // number of faces in ellipse int num_faces = (int) (circumference / (float) face_length); // clamp number of faces if (num_faces > max_faces) num_faces = max_faces;/*from w w w .j a va2 s . c o m*/ if (num_faces < min_faces) num_faces = min_faces; // keep number of faces divisible by 4 num_faces -= (num_faces & 3); // precalc cosine theta float angle = degrees * pi / 180.0f; float s = (float) Math.sin(twopi / (float) num_faces); float c = (float) Math.cos(twopi / (float) num_faces); float xx = 1; float yy = 0; float xt; float ax = (float) Math.cos(angle); float ay = (float) Math.sin(angle); // draw ellipse GL11.glDisable(GL11.GL_TEXTURE_2D); int i; GL11.glBegin(GL11.GL_LINE_LOOP); for (i = 0; i < num_faces; i++) { xt = xx; xx = c * xx - s * yy; yy = s * xt + c * yy; GL11.glVertex2f(x + a * xx * ax - b * yy * ay, y + a * xx * ay + b * yy * ax); } GL11.glVertex2f(x + a * ax, y + a * ay); GL11.glEnd(); GL11.glEnable(GL11.GL_TEXTURE_2D); }
From source file:net.phatcode.rel.multimedia.Graphics.java
License:Open Source License
public void drawEllipseFilled(int x, int y, int a, int b, int degrees, float red, float green, float blue, float alpha) { // these constants decide the quality of the ellipse final float pi = (float) Math.PI; final float twopi = 2 * pi; // two pi (radians in a circle) final int face_length = 8; // approx. face length in pixels final int max_faces = 256; // maximum number of faces in ellipse final int min_faces = 16; // minimum number of faces in ellipse // approx. ellipse circumference (hudson's method) float h = (a - b * a - b) / (float) (a + b * a + b); float circumference = 0.25f * pi * (a + b) * (3 * (1 + h * 0.25f) + 1 / (1 - h * 0.25f)); // number of faces in ellipse int num_faces = (int) (circumference / (float) face_length); // clamp number of faces if (num_faces > max_faces) num_faces = max_faces;//from ww w . ja v a 2 s .c o m if (num_faces < min_faces) num_faces = min_faces; // keep number of faces divisible by 4 num_faces -= (num_faces & 3); // precalc cosine theta float angle = degrees * pi / 180.0f; float s = (float) Math.sin(twopi / (float) num_faces); float c = (float) Math.cos(twopi / (float) num_faces); float xx = 1; float yy = 0; float xt; float ax = (float) Math.cos(angle); float ay = (float) Math.sin(angle); // draw ellipse GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glColor4f(red, green, blue, alpha); int i; GL11.glBegin(GL11.GL_TRIANGLE_FAN); for (i = 0; i < num_faces; i++) { xt = xx; xx = c * xx - s * yy; yy = s * xt + c * yy; GL11.glVertex2f(x + a * xx * ax - b * yy * ay, y + a * xx * ay + b * yy * ax); } GL11.glVertex2f(x + a * ax, y + a * ay); GL11.glEnd(); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glColor4f(1, 1, 1, 1); }
From source file:net.phatcode.rel.multimedia.Graphics.java
License:Open Source License
public void drawEllipseFilled(int x, int y, int a, int b, int degrees) { // these constants decide the quality of the ellipse final float pi = (float) Math.PI; final float twopi = 2 * pi; // two pi (radians in a circle) final int face_length = 8; // approx. face length in pixels final int max_faces = 256; // maximum number of faces in ellipse final int min_faces = 16; // minimum number of faces in ellipse // approx. ellipse circumference (hudson's method) float h = (a - b * a - b) / (float) (a + b * a + b); float circumference = 0.25f * pi * (a + b) * (3 * (1 + h * 0.25f) + 1 / (1 - h * 0.25f)); // number of faces in ellipse int num_faces = (int) (circumference / (float) face_length); // clamp number of faces if (num_faces > max_faces) num_faces = max_faces;// w w w. ja v a2s .co m if (num_faces < min_faces) num_faces = min_faces; // keep number of faces divisible by 4 num_faces -= (num_faces & 3); // precalc cosine theta float angle = degrees * pi / 180.0f; float s = (float) Math.sin(twopi / (float) num_faces); float c = (float) Math.cos(twopi / (float) num_faces); float xx = 1; float yy = 0; float xt; float ax = (float) Math.cos(angle); float ay = (float) Math.sin(angle); // draw ellipse GL11.glDisable(GL11.GL_TEXTURE_2D); int i; GL11.glBegin(GL11.GL_TRIANGLE_FAN); for (i = 0; i < num_faces; i++) { xt = xx; xx = c * xx - s * yy; yy = s * xt + c * yy; GL11.glVertex2f(x + a * xx * ax - b * yy * ay, y + a * xx * ay + b * yy * ax); } GL11.glVertex2f(x + a * ax, y + a * ay); GL11.glEnd(); GL11.glEnable(GL11.GL_TEXTURE_2D); }
From source file:net.phatcode.rel.multimedia.Graphics.java
License:Open Source License
void drawSprite(float x, float y, int flipmode, SpriteGL sprite) { flipmode = getflipMode(flipmode);/*from ww w .j a va 2 s . c o m*/ float x2 = x + sprite.width; float y2 = y + sprite.height; float u1 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u1 : sprite.u2; float v1 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v1 : sprite.v2; float u2 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u2 : sprite.u1; float v2 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v2 : sprite.v1; if (sprite.textureID != currentTexture) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.textureID); currentTexture = sprite.textureID; } GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(u1, v1); GL11.glVertex2f(x, y); GL11.glTexCoord2f(u1, v2); GL11.glVertex2f(x, y2); GL11.glTexCoord2f(u2, v2); GL11.glVertex2f(x2, y2); GL11.glTexCoord2f(u2, v1); GL11.glVertex2f(x2, y); GL11.glEnd(); }
From source file:net.phatcode.rel.multimedia.Graphics.java
License:Open Source License
private void drawSprite(float x, float y, float r, float g, float b, float a, int flipmode, SpriteGL sprite) { flipmode = getflipMode(flipmode);//from w w w . j a v a2s.c o m float x2 = x + sprite.width; float y2 = y + sprite.height; float u1 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u1 : sprite.u2; float v1 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v1 : sprite.v2; float u2 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u2 : sprite.u1; float v2 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v2 : sprite.v1; if (sprite.textureID != currentTexture) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.textureID); currentTexture = sprite.textureID; } GL11.glColor4f(r, g, b, a); GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(u1, v1); GL11.glVertex2f(x, y); GL11.glTexCoord2f(u1, v2); GL11.glVertex2f(x, y2); GL11.glTexCoord2f(u2, v2); GL11.glVertex2f(x2, y2); GL11.glTexCoord2f(u2, v1); GL11.glVertex2f(x2, y); GL11.glEnd(); }
From source file:net.phatcode.rel.multimedia.Graphics.java
License:Open Source License
private void drawTransformedSprite(float x, float y, float angle, float scaleX, float scaleY, int flipmode, SpriteGL sprite) {/*from w w w .ja v a 2s .c o m*/ flipmode = getflipMode(flipmode); float s_half_x = sprite.width / 2.0f; float s_half_y = sprite.height / 2.0f; float x1 = -s_half_x; float y1 = -s_half_y; float u1 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u1 : sprite.u2; float v1 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v1 : sprite.v2; float u2 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u2 : sprite.u1; float v2 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v2 : sprite.v1; if (sprite.textureID != currentTexture) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.textureID); currentTexture = sprite.textureID; } GL11.glPushMatrix(); GL11.glTranslatef(x, y, 0.0f); GL11.glScalef(scaleX, scaleY, 1.0f); GL11.glRotatef(angle, 0.0f, 0.0f, 1.0f); GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(u1, v1); GL11.glVertex2f(x1, y1); GL11.glTexCoord2f(u1, v2); GL11.glVertex2f(x1, s_half_y); GL11.glTexCoord2f(u2, v2); GL11.glVertex2f(s_half_x, s_half_y); GL11.glTexCoord2f(u2, v1); GL11.glVertex2f(s_half_x, y1); GL11.glEnd(); GL11.glPopMatrix(); }
From source file:net.phatcode.rel.multimedia.Graphics.java
License:Open Source License
private void drawTransformedSprite(float x, float y, float angle, float scaleX, float scaleY, float r, float g, float b, float a, int flipmode, SpriteGL sprite) { flipmode = getflipMode(flipmode);//from ww w . j a v a 2s. c o m float s_half_x = sprite.width / 2.0f; float s_half_y = sprite.height / 2.0f; float x1 = -s_half_x; float y1 = -s_half_y; float u1 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u1 : sprite.u2; float v1 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v1 : sprite.v2; float u2 = ((flipmode & SpriteGL.FLIP_H) == 0) ? sprite.u2 : sprite.u1; float v2 = ((flipmode & SpriteGL.FLIP_V) == 0) ? sprite.v2 : sprite.v1; if (sprite.textureID != currentTexture) { GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.textureID); currentTexture = sprite.textureID; } GL11.glColor4f(r, g, b, a); GL11.glPushMatrix(); GL11.glTranslatef(x, y, 0.0f); GL11.glScalef(scaleX, scaleY, 1.0f); GL11.glRotatef(angle, 0.0f, 0.0f, 1.0f); GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(u1, v1); GL11.glVertex2f(x1, y1); GL11.glTexCoord2f(u1, v2); GL11.glVertex2f(x1, s_half_y); GL11.glTexCoord2f(u2, v2); GL11.glVertex2f(s_half_x, s_half_y); GL11.glTexCoord2f(u2, v1); GL11.glVertex2f(s_half_x, y1); GL11.glEnd(); GL11.glPopMatrix(); }