Draw image as a polygon - java

I'm trying to draw an image as a polygon in Swing but I don't know how. Now I
only have code to draw filled polygon. This is not a cropped image, it is distorted.
What I need (Polygon with texture):
What I have - Filled polygon
gr.fillPolygon(x_points, y_points, points.length);

The easiest way to render 3D is using JOGL library which uses OpenGL to render in JPanel.

Related

How to draw Image pattern with javaFX Canvas

I want to draw a repeating image on a javafx canvas, is there any way to do it other than manually reapeatedly drawing the same image over and over?
This can be done by setting the Paint for filling some area. A subclass of Paint is
https://openjfx.io/javadoc/12/javafx.graphics/javafx/scene/paint/ImagePattern.html
which does exactly what you want.

Fill a ShapeRenderer rectangle with an image(.png)?

I am new to libgdx. I am trying to write a basic android game with the libgdx framework
Is it possible at all to fill a rectangle drawn with libgdx ShapeRenderer with a given image?
If yes, how, and if no, is there any kind of hack or workaround?
Images to be put on the screen in Libgdx (and OpenGL) are known as "textures". The ShapeRenderer library does not support textures.
That said, the Libgdx texture and SpriteBatch APIs are optimized for drawing image rectangles. Check out the overview and tutorial here:
https://github.com/libgdx/libgdx/wiki/Spritebatch%2C-textureregions%2C-and-sprite

Render circles and change color of the intersection

I'm working in a simple game for desktop and Android using LibGDX framework. The game spawn some balls that move from one side of the screen to the opposite one. I want to show white circles over a black background but I also want to draw some white texts. My problem with this is that I want to draw the intersection between balls and between balls and text in black. I want something like this:
Other of my problems is that I'm using ShapeRenderer to draw the circles and they are too pixelated.
What is the best way to render circles in libGDX (Ill have to render between 1 and 100). Is it possible to get the effect shown in the image?

With Java's graphics shape drawing operations, is there an easy way to give the shapes transparency gradients and blurry edges?

What I would like is to give circles a fill color with a gradient that starts from the middle and then as it moves out to the edges becomes progressively more transparent, giving a blur effect. What is the simplest way of doing this?
Try setting an appropiately defined java.awt.RadialGradientPaint (using Colors with alpha), then render your circles using that. You may need to translate the graphics coordinate system to get the gradient centered in the circle. (http://docs.oracle.com/javase/7/docs/api/java/awt/RadialGradientPaint.html)
Or just make an image in a graphics program and simply draw the image.

LWJGL Texture a cube

I'm currently rendering a cube with VBOs, and with color. I want to drop some texture on them, and I don't have any idea about it. Still learning OGL, but how can I render the cube with texture on them? I need another VBO for texture?
Thanks!
Yeah, you need another FloatBuffer, not to mention a texture.
When mapping a texture onto an object, you need to use texture coordinates (How do opengl texture coordinates work?). Use glTexCoordPointer() to map your texture onto the cube.
You can load textures with the slick library that comes with LWJGL.

Categories

Resources