Java Code Examples for org.lwjgl.opengl.GL11#glVertex2f()

The following examples show how to use org.lwjgl.opengl.GL11#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: RenderUtils.java    From Hyperium with GNU Lesser General Public License v3.0 7 votes vote down vote up
public static void drawLine(float x, float y, float x1, float y1, float width, int colour) {
    float red = (float) (colour >> 16 & 0xFF) / 255F;
    float green = (float) (colour >> 8 & 0xFF) / 255F;
    float blue = (float) (colour & 0xFF) / 255F;
    float alpha = (float) (colour >> 24 & 0xFF) / 255F;

    GlStateManager.enableBlend();
    GlStateManager.disableTexture2D();
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_LINE_SMOOTH);

    GlStateManager.pushMatrix();
    GlStateManager.color(red, green, blue, alpha);
    GL11.glLineWidth(width);
    GL11.glBegin(GL11.GL_LINE_STRIP);
    GL11.glVertex2f(x, y);
    GL11.glVertex2f(x1, y1);
    GL11.glEnd();
    GlStateManager.popMatrix();

    GlStateManager.enableTexture2D();
    GlStateManager.disableBlend();
    GL11.glDisable(GL11.GL_LINE_SMOOTH);
}
 
Example 2
Source File: TestUtils.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Game loop render
 */
public void render() {
	Color.white.bind();
	texture.bind(); // or GL11.glBind(texture.getTextureID());
	
	GL11.glBegin(GL11.GL_QUADS);
		GL11.glTexCoord2f(0,0);
		GL11.glVertex2f(100,100);
		GL11.glTexCoord2f(1,0);
		GL11.glVertex2f(100+texture.getTextureWidth(),100);
		GL11.glTexCoord2f(1,1);
		GL11.glVertex2f(100+texture.getTextureWidth(),100+texture.getTextureHeight());
		GL11.glTexCoord2f(0,1);
		GL11.glVertex2f(100,100+texture.getTextureHeight());
	GL11.glEnd();
	
	font.drawString(150, 300, "HELLO LWJGL WORLD", Color.yellow);
}
 
Example 3
Source File: RenderUtils.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void drawCircle(int xx, int yy, int radius, int col) {
    float f = (col >> 24 & 0xFF) / 255.0F;
    float f2 = (col >> 16 & 0xFF) / 255.0F;
    float f3 = (col >> 8 & 0xFF) / 255.0F;
    float f4 = (col & 0xFF) / 255.0F;
    GL11.glPushMatrix();
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_LINE_SMOOTH);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glBegin(2);

    for (int i = 0; i < 70; i++) {
        float x = radius * MathHelper.cos((float) (i * 0.08975979010256552D));
        float y = radius * MathHelper.sin((float) (i * 0.08975979010256552D));
        GlStateManager.color(f2, f3, f4, f);
        GL11.glVertex2f(xx + x, yy + y);
    }

    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    GL11.glEnd();
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glDisable(GL11.GL_LINE_SMOOTH);
    GL11.glPopMatrix();
}
 
Example 4
Source File: RenderUtils.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void drawArc(float cx, float cy, float r, float startAngle, float angle, int segments, int color) {
    float red = (float) (color >> 16 & 0xFF) / 255F;
    float green = (float) (color >> 8 & 0xFF) / 255F;
    float blue = (float) (color & 0xFF) / 255F;
    float alpha = (float) (color >> 24 & 0xFF) / 255F;

    float theta = angle / (float) (segments - 1);

    double tf = Math.tan(theta);
    float rf = MathHelper.cos(theta);

    float x = r * MathHelper.cos(startAngle);
    float y = r * MathHelper.sin(startAngle);

    GlStateManager.pushMatrix();
    GlStateManager.color(red, green, blue, alpha);
    GL11.glBegin(GL_LINE_STRIP);
    for (int ii = 0; ii < segments; ii++) {
        GL11.glVertex2f(x + cx, y + cy);

        float tx = -y;
        float ty = x;

        x += tx * tf;
        y += ty * tf;

        x *= rf;
        y *= rf;
    }
    GL11.glEnd();
    GlStateManager.popMatrix();
}
 
Example 5
Source File: GLUtils.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
public static void drawCheck(int x, int y) {

        GL11.glEnable(3042);
        GL11.glDisable(3553);
        GL11.glColor4f(0.0f, 0.0f, 0.75f, 0.5f);
        GL11.glBlendFunc(770, 771);
        GL11.glLineWidth(2.0f);
        GL11.glBegin(3);
        GL11.glVertex2f((x + 1), (y + 4));
        GL11.glVertex2f((x + 3), (y + 6.5f));
        GL11.glVertex2f((x + 7), (y + 2));
        GL11.glEnd();
        GL11.glDisable(3042);
        GL11.glEnable(3553);
    }
 
Example 6
Source File: SolidBox.java    From OpenPeripheral-Addons with MIT License 5 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
protected void drawContents(RenderState renderState, float partialTicks) {
	renderState.setupSolidRender();
	renderState.setColor(color, opacity);

	GL11.glBegin(GL11.GL_QUADS);
	GL11.glVertex2f(0, 0);
	GL11.glVertex2f(0, height);
	GL11.glVertex2f(width, height);
	GL11.glVertex2f(width, 0);
	GL11.glEnd();
}
 
Example 7
Source File: GradientBox.java    From OpenPeripheral-Addons with MIT License 5 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
protected void drawContents(RenderState renderState, float partialTicks) {
	renderState.setupSolidRender();

	{
		renderState.setColor(color1, opacity1);
		GL11.glBegin(GL11.GL_QUADS);
		if (gradient == 1) {
			GL11.glVertex2f(0, height);
			GL11.glVertex2f(width, height);
		} else {
			GL11.glVertex2f(width, height);
			GL11.glVertex2f(width, 0);
		}
	}

	{
		renderState.setColor(color2, opacity2);
		if (gradient == 1) {
			GL11.glVertex2f(width, 0);
			GL11.glVertex2f(0, 0);
		} else {
			GL11.glVertex2f(0, 0);
			GL11.glVertex2f(0, height);
		}
	}

	GL11.glEnd();
}
 
Example 8
Source File: Gui.java    From Slyther with MIT License 5 votes vote down vote up
public void drawTexture(float x, float y, float width, float height) {
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glShadeModel(GL11.GL_FLAT);
    GL11.glTexCoord2f(0, 0);
    GL11.glVertex2f(x, y);
    GL11.glTexCoord2f(1, 0);
    GL11.glVertex2f(x + width, y);
    GL11.glTexCoord2f(1, 1);
    GL11.glVertex2f(x + width, y + height);
    GL11.glTexCoord2f(0, 1);
    GL11.glVertex2f(x, y + height);
    GL11.glEnd();
}
 
Example 9
Source File: Gui.java    From Slyther with MIT License 5 votes vote down vote up
public void drawLine(float x1, float y1, float x2, float y2, float width, int color) {
    GL11.glPushMatrix();
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glColor4f((color >> 16 & 0xFF) / 255.0F, (color >> 8 & 0xFF) / 255.0F, (color & 0xFF) / 255.0F, 1.0F);
    GL11.glLineWidth(width * renderResolution.getScale());
    GL11.glBegin(GL11.GL_LINES);
    GL11.glVertex2f(x1, y1);
    GL11.glVertex2f(x2, y2);
    GL11.glEnd();
    GL11.glPopMatrix();
}
 
Example 10
Source File: ImmediateModeOGLRenderer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @see org.newdawn.slick.opengl.renderer.SGL#glVertex2f(float, float)
 */
public void glVertex2f(float x, float y) {
	GL11.glVertex2f(x, y);
}
 
Example 11
Source File: ColorPointListBuilder.java    From OpenPeripheral-Addons with MIT License 4 votes vote down vote up
@Override
protected void drawPoint(RenderState renderState, ColorPoint2d p) {
	renderState.setColor(p.rgb, p.opacity);
	GL11.glVertex2f(p.x, p.y);
}
 
Example 12
Source File: Gui.java    From Slyther with MIT License 4 votes vote down vote up
public void drawVertex(float x, float y, float u, float v, float uMultiplier, float vMultiplier) {
    GL11.glTexCoord2f(u * uMultiplier, v * vMultiplier);
    GL11.glVertex2f(x, y);
}
 
Example 13
Source File: Gui.java    From Slyther with MIT License 4 votes vote down vote up
public void drawConnectedLine(float x1, float y1, float x2, float y2) {
    GL11.glVertex2f(x1, y1);
    GL11.glVertex2f(x2, y2);
}
 
Example 14
Source File: Graphics.java    From AnyaBasic with MIT License 4 votes vote down vote up
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;
    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 );

}
 
Example 15
Source File: BlurPane.java    From LWJGUI with MIT License 4 votes vote down vote up
@Override
public void render(Context context, int x, int y, int w, int h) {
	if ( !isVisible() )
		return;
	
	if ( this.quad == null || quadDirty ) {
		if ( this.quad != null ) {
			this.quad.cleanup();
		}
		quad = new TexturedQuad(0, 0, w, h, source.getTexId());
	}
	
	GL11.glViewport(x, y, w, h);
	this.quadDirty = false;
	quadShader.bind();
	quadShader.projectOrtho(0, h, w, -h);
	
	// bind stuff
	GL13.glActiveTexture(GL13.GL_TEXTURE0);
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, source.getTexId());
	
	if ( internalBackground instanceof BackgroundSolid ) {
		BackgroundSolid bg = (BackgroundSolid)internalBackground;
		GL20.glUniform4f(GL20.glGetUniformLocation(quadShader.getProgram(), "uColor"),
				bg.getColor().getRed()/255f-0.5f,
				bg.getColor().getGreen()/255f-0.5f,
				bg.getColor().getBlue()/255f-0.5f,
				bg.getColor().getAlpha()/255f);
	}
	GL20.glUniform1f(GL20.glGetUniformLocation(quadShader.getProgram(), "uBlurSize"), blurRadius);
	GL20.glUniform2f(GL20.glGetUniformLocation(quadShader.getProgram(), "uTexelSize"), 1.0f/(float)w, 1.0f/(float)h);
	GL20.glUniform4f(GL20.glGetUniformLocation(quadShader.getProgram(), "uCornerRadii"), (float)Math.max(BlurPane.this.getBorderRadii()[0], 0.1), (float)Math.max(BlurPane.this.getBorderRadii()[1], 0.1), (float)Math.max(BlurPane.this.getBorderRadii()[2], 0.1), (float)Math.max(BlurPane.this.getBorderRadii()[3], 0.1));
	
	
	// Draw quad
	if ( context.isCoreOpenGL() ) {
		if ( quad != null ) {
			quad.render();
		}
	} else {

		GL13.glActiveTexture(GL13.GL_TEXTURE0);
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, source.getTexId());
		
		GL11.glBegin(GL11.GL_QUADS);
			GL11.glColor3f(1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(0, 0);
			GL11.glVertex2f(0, 0);
	
			GL11.glColor3f(1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(1, 0);
			GL11.glVertex2f(w, 0);
	
			GL11.glColor3f(1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(1, 1);
			GL11.glVertex2f(w, h);
	
			GL11.glColor3f(1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(0, 1);
			GL11.glVertex2f(0, h);
		GL11.glEnd();
	}
}
 
Example 16
Source File: Graphics.java    From AnyaBasic with MIT License 4 votes vote down vote up
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;
    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 );

}
 
Example 17
Source File: DrawOnDemandTest.java    From lwjgl3-awt with MIT License 4 votes vote down vote up
public static void main(String[] args) {
	
	AWTGLCanvas canvas = new AWTGLCanvas() {
		private static final long serialVersionUID = 1L;

		@Override
		public void initGL() {
			GL.createCapabilities();
			glClearColor(0.3f, 0.4f, 0.5f, 1);
		}
		
		@Override
		public void paintGL() {
			int w = getWidth();
			int h = getHeight();
			if (w == 0 || h == 0) {
				return;
			}
			float aspect = (float) w / h;
			GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
			GL11.glViewport(0, 0, w, h);
			GL11.glBegin(GL11.GL_QUADS);
			GL11.glColor3f(quadColor.getRed()/255f, quadColor.getGreen()/255f, quadColor.getBlue()/255f);
			GL11.glVertex2f(-0.75f / aspect, 0.0f);
			GL11.glVertex2f(0, -0.75f);
			GL11.glVertex2f(+0.75f / aspect, 0);
			GL11.glVertex2f(0, +0.75f);
			GL11.glEnd();
			swapBuffers();
		}

		@Override
		public void repaint() {
			if (SwingUtilities.isEventDispatchThread()) {
				render();
			} else {
				SwingUtilities.invokeLater(() -> render());
			}
		}

	};

	JFrame frame = new JFrame();
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.getContentPane().setLayout(new BorderLayout());
	frame.getContentPane().add(canvas, BorderLayout.CENTER);
	canvas.setPreferredSize(new Dimension(200, 200));
	canvas.addComponentListener(new ComponentAdapter() {
		public void componentResized(java.awt.event.ComponentEvent e) {
			canvas.repaint();
		};
	});
	JColorChooser colorChooser = new JColorChooser(quadColor);
	frame.getContentPane().add(colorChooser, BorderLayout.SOUTH);
	colorChooser.getSelectionModel().addChangeListener((e)->{
		quadColor = colorChooser.getColor();
		canvas.repaint();
	});
	

	SwingUtilities.invokeLater(() -> {
		frame.pack();
		frame.setVisible(true);
	});
}
 
Example 18
Source File: PointListBuilder.java    From OpenPeripheral-Addons with MIT License 4 votes vote down vote up
@Override
protected void drawPoint(RenderState renderState, Point2d p) {
	GL11.glVertex2f(p.x, p.y);
}
 
Example 19
Source File: GLUtils.java    From ehacks-pro with GNU General Public License v3.0 4 votes vote down vote up
public static void drawStrip(int x, int y, float width, double angle, float points, float radius, int color) {

        int i;
        float yc;
        float a2;
        float xc;
        GL11.glPushMatrix();
        float f1 = (color >> 24 & 255) / 255.0f;
        float f2 = (color >> 16 & 255) / 255.0f;
        float f3 = (color >> 8 & 255) / 255.0f;
        float f4 = (color & 255) / 255.0f;
        GL11.glTranslatef(x, y, 0.0f);
        GL11.glColor4f(f2, f3, f4, f1);
        GL11.glLineWidth(width);
        GL11.glEnable(3042);
        GL11.glDisable(2929);
        GL11.glEnable(2848);
        GL11.glDisable(3553);
        GL11.glDisable(3008);
        GL11.glBlendFunc(770, 771);
        GL11.glHint(3154, 4354);
        GL11.glEnable(32925);
        if (angle > 0.0) {
            GL11.glBegin(3);
            i = 0;
            while (i < angle) {
                a2 = (float) (i * (angle * 3.141592653589793 / points));
                xc = (float) (Math.cos(a2) * radius);
                yc = (float) (Math.sin(a2) * radius);
                GL11.glVertex2f(xc, yc);
                ++i;
            }
            GL11.glEnd();
        }
        if (angle < 0.0) {
            GL11.glBegin(3);
            i = 0;
            while (i > angle) {
                a2 = (float) (i * (angle * 3.141592653589793 / points));
                xc = (float) (Math.cos(a2) * (-radius));
                yc = (float) (Math.sin(a2) * (-radius));
                GL11.glVertex2f(xc, yc);
                --i;
            }
            GL11.glEnd();
        }
        GL11.glDisable(3042);
        GL11.glEnable(3553);
        GL11.glDisable(2848);
        GL11.glEnable(3008);
        GL11.glEnable(2929);
        GL11.glDisable(32925);
        GL11.glDisable(3479);
        GL11.glPopMatrix();
    }
 
Example 20
Source File: OffscreenBuffer.java    From LWJGUI with MIT License 4 votes vote down vote up
public void render(Context context, int x, int y, int w, int h) {
	if (quadShader == null) {
		quadShader = new GenericShader();
	}
	float pixelRatio = LWJGUI.getThreadWindow().getPixelRatio();
	x *= pixelRatio;
	y *= pixelRatio;
	GL11.glViewport(x, y,(int) (w*pixelRatio),(int) (h*pixelRatio));
	quadShader.bind();
	quadShader.projectOrtho(0, 0, w, h);
	
	if (quadDirty) {
		quadDirty = false;
		if (quad != null) {
			quad.cleanup();
		}
		quad = new TexturedQuad(0, 0, w, h, texId);
	}
	if ( context.isCoreOpenGL() ) {
		if ( quad != null ) {
			quad.render();
		}
	} else {

		GL13.glActiveTexture(GL13.GL_TEXTURE0);
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);
		
		GL11.glBegin(GL11.GL_QUADS);
			GL11.glColor3f(1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(0, 0);
			GL11.glVertex2f(0, 0);

			GL11.glColor3f(1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(1, 0);
			GL11.glVertex2f(w, 0);

			GL11.glColor3f(1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(1, 1);
			GL11.glVertex2f(w, h);

			GL11.glColor3f(1.0f, 1.0f, 1.0f);
			GL11.glTexCoord2f(0, 1);
			GL11.glVertex2f(0, h);
		GL11.glEnd();
	}
}