Basic Graphics. Need help in drawing [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I'm just beginning to learn basic graphics, particularly drawing, and I would like to ask for suggestions on how I draw animals such as this fox.
http://www.wikihow.com/images/2/2f/Draw-a-Fox-Step-9.jpg
Do I use polygons and hard code the whole drawing? Or is there a program that allows me to input the image in it and it outputs the x and y coordinates of all the vertices that I'd need in order to draw it? Basically, what I have to do is I'd draw that fox in Java but I have to draw it on my own using shapes. I'd have to start from scratch and work my way up until I recreate the fox using Java's shapes. Any suggestions how I do this?

When people want graphics like that in their games/applications, they usually create the files in other applications and then import the image files. There are many different application to create images in, but two of the popular ones are Photoshop and Illustrator. For a free application to create images, look into GIMP.
There are a variety of different files types you can use in almost all languages and platforms. For example, .png files are particularly useful because they can have transparency. For resolution independent images people often use .svn file format.
It is rare for anyone to have the program generate the images with polygons, unless you have some type of severe constraint, there is no reason to.
Look up how to load and display image files in the language and platform of your choice.

This block'll paint the fox:
#Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
ImageIcon fox = new ImageIcon(new URL('http://i.stack.imgur.com/vJOsv.jpg'));
fox.paintIcon(this, g, x, y) // Replace x and y with the x/y coordinates
}

Related

2d collisions engine for irregular shapes formed with straight equations [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Contex: I'm trying to make a 2d physic engine, i'm starting to think about how to draw shapes that i could rotate. So i thought i could draw irregular shapes by drawing lines from several equations of straight. Now i have some doubts:
There is a easy way of draw a straight by giving an equation?
There is a library that can help me to handle equations?
The reason to use equations instead of using functions to draw lines from x1,y1 to x2,y2 is that i want the equations to calculate collisions between shapes.
Do you know a book or an article that could help me pull this off?
I'm gonna work in java, for now this is just an idea.
Not an expert in this field but quick search on java 2d engine collision engine returns dyn4j library on the first page. You can explore their examples and consequently the implementation code.
https://github.com/wnbittle/dyn4j

How can I make 3D graphic in Java? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
First, I'm new in Java.
Second, sorry for my English but I'm still learning it.
I need to create object in 3D space, which I would can manipulate from my mouse next.
I can make e.g. square like this:
public void paint(Graphics g){
super.paint(g);
((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g.fillRect(50, 50, 40, 40);
}
But what I can do with that? In my opinion its only contour. Have Java special class for that?
I can use only awt;* and derivative from that. Is Canvas3D count to that?
Please, help me:)
I have used jogl in my projects
One possible option is to use JavaFX.
It involves complex math and requires Java8 and for you to understand the threading mechanism of Swing and JavaFX, but it seems the optimal option for 3D graphics implemented in Java.
It also integrates with Swing if you require or stands-alone.
Check Getting Started with JavaFX 3D Graphics
Check JavaFX Transformation overview.
I found this book helpful, it shows you how to create 3D graphics in Java from the ground up:
http://www.amazon.com/Computer-Graphics-Java-Programmers-Ammeraal/dp/0470031603

OpenGL copy/paste out part of a texture into another texture [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need to take a bunch of images from different sprite sheets and put them in a particular way into one texture for my game (although I"m not very familiar with openGL). So, what is the best way to make a texture from a smaller portion of a texture in OpenGL, and what is the best way to combine two or more textures into one texture in OpenGL?
The most direct way to do this using glBlitFramebuffer(). You will need two FBOs (framebuffer objects): one for the source, and one for the destination. Then you attach the source and destination textures to the FBOs, and call glBlitFramebuffer().
The code could look like this, with srcTexId the texture name of your source texture, and dstTexId the destination:
GLuint fboIds[2];
glGenFramebuffers(2, fboIds);
glBindFramebuffer(GL_READ_FRAMEBUFFER, fboIds[0]);
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, srcTexId, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboIds[1]);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, dstTexId, 0);
glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1,
dstX0, dstY0, dstX1, dstY1,
GL_COLOR_BUFFER_BIT, GL_NEAREST);
The first 8 arguments to glBlitFramebuffer() specify the rectangles in the source and destination textures.
There are many different ways this can be achieved in OpenGL. Assuming a reasobably modern GL version, I would recommend using FBOs. Bind the destination texture as the color attachment for one FBO. Then, you can simply render textured quads (using the source texture regions) to it. You could even skip the render step completely, and also use a FBO for the source textures, and directly blit the parts using glBlitFramebuffer().

Create wind rose android [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I would like to create a wind rose similar to this :
The goal is to be able to update the green area based on information from a database.
The green area should take in two degrees and then create the green area between them.
Where could i start looking for a soulution ?
I have done such a compass for ios.
Besides custom views, you should be familiar with polar coordinates:
A point then is defined by (r, phi) instead of (x,y).
You need that all the time, you loop around the rose iterating with phi from 0 to 360, in steps. When you have the drawing coordinates in polar, you have to transform to x,y and draw it.
Further you will need AffineTransformations to scale the rose from a given pixel width, and height to a neutral -1, 1 range. Then drawing is easier.
Look at how to create a custom view : http://developer.android.com/training/custom-views/index.html
And keep in mind that you will have to optimize your drawing code : no object creation and rely as much as possible on java graphics primitives.
Happy coding, that's a very fun android development ahead, but a bit complex for novices.
Oh, and by the way, here you might be interested in using PorterDuff mode for translucency.
As has been mentioned, you'll likely want to implement a custom view.
In particular though, you'll want to divide the rendering into two. The background static image and the foreground dynamic image.
The foreground image could be generated using the Canvas class. It's quite easy to use once you get your head around it. The idea is that you'll be generating a bitmap using the canvas on whcih you draw. See the docs for more details:
http://developer.android.com/guide/topics/graphics/2d-graphics.html
For the actual rendering, you can use the drawArc method in the Canvas class:
public void drawArc (RectF oval, float startAngle, float sweepAngle, boolean useCenter, Paint paint)
http://developer.android.com/reference/android/graphics/Canvas.html#drawArc(android.graphics.RectF, float, float, boolean, android.graphics.Paint)
All the best!

How to get the best graphical performance out of Java2D [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
This question does not apply to libraries such as LWJGL, JavaFX, etc. The goal here is to determine how to get the best performance out of Java2D. More particularly, how to get the best performance out of Java2D to create visually appealing yet efficient 2D games. I have come across quite a lot of practices: drawing directly onto a JFrame, overriding JPanel or JComponent, overriding Canvas to provide some nice double buffering strategies, using a library (ehm), etc.
In the past, I have simply overriden a JPanel and its paintComponent method, and, in the end, it ran at a steady 35 FPS! Not really the pinnacle of performance for a simple top-down 2D Java game (or maybe it is?).
So, what is the best strategy to get every drop of performance out of Java2D?
If you want to use Java's Graphics2D class to draw objects with nice performance, I recommend using VolatileImage. It is available since Java 1.4 and uses hardware accelerated processing (if possible) to render its stuff. It extends java.awt.Image so there are not so much changes for you, if you used BufferedImage or so before. But there are some tricky things using this class. For example before you render its content you need to check whether it is still valid, but usually it is not so hard to manage this stuff· But therefor you get pretty nice performance boost to your app, without the need to change a lot of code. :)
This link should give you good advice using this class.

Categories

Resources