OpenGL copy/paste out part of a texture into another texture [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 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().

Related

Efficient way of gathering 4 point subimage, matrix transformation problems + antialiasing [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
QUICK RECAP OF THE PROJECT:
I'm making a car that would drive itself in between the obstacles of which picture will be taken by your phone. The picture should then be cropped to the size of the "area of movement" or the area where car can move. That should have been done automatically. In my case I’d do it like this:
Before you would take picture of the "obstacle map", you would have to put a paper sheet on the ground, so the program would recognize the size of the area/the way image should be transformed to be "perpendicular" to the ground.
In program you would mark the area where car can move and it would crop it. Then it would automatically transform the selected area to be as "perpendicular" as possible, so the obstacle map would be good enough for the car to move in it as it would be an obstacle map.
Then I have 2 options: either to automate obstacle recognition or to make it manual. If I would automate it, I would have to use some sort of OpenCV obstacle recognition. Else id just make a simple program for marking obstacles. After that you would mark a point, where the car should move to and it would calculate the most optimal path with A algorithm. This algorithm only gives the points where the car should move, so I connected with some professors in my school and they are now doing some help with steering of car and calculating the right angle the car should steer to come to certain location.*
I have 2 questions, both connected with BufferedImage.
Two questions back in the past, I asked how to get a sub image that is defined by 4 random points. I got no answers for doing that so I did it myself, but I know that this method is VERY INEFFICIENT and I'd like to know how can it be done better?
My second question is about matrix transformation. I have already been discussing about that and got this code which is basically a modded version of this one. The code is limiting me to the size of the input bufferedimage and i'd like to know how can I "remove" this limit, because in some cases the image needs to be upscaled, but the code keeps cropping it. Also I’d like to have some sort of AA (Anti Aliasing) on it, because the transformed image just looks weird/pixelated.
EDIT: In first question's code, there is a method line(Point p1, Point p2) in class Place_2D which basically creates an arraylist of points connecting 2 points in place, creating a line.
Antialiasing will be achieved by a better sampling scheme than nearest-neighbor. You will get a nice improvement by switching to bilinear interpolation.
Every back-projected point falls between four pixels. The fractional part of the coordinates allow you to compute mixing weights to be assign to the color values of these four pixels.
If the scaling factor is small (transformed image being less than a quarter of the original), you can blur the image beforehand to avoid other artifacts.

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!

Basic Graphics. Need help in drawing [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'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
}

RGB retrieval of a coloured image [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am trying to do some image processing on a coloured image and for me to do so I need to separate the RGB values and modify them separately. I am just implementing a increase in brightness filter. I am doing this in java. Can someone help me out please
You have a few options.
First, you need to be able to load an image that supports the BufferedImage class. For this, you're best using the ImageIO API. Take a look at Reading/Loading an Image.
Once you have this, you can obtain the pixel information in a verity of ways.
One of the simplest is to use BufferedImage#getRGB, which returns a packed integer of the pixel.
Depending on the type of image, you can obtain the individual color values Color(int, boolean), which will unpack the integer accordingly (you can also do this manually, but I never remember the maths and this is simpler).
Alternativly, you can access the Raster directly, via BufferedImage#getData, which provides you access to more methods for manipulating the underlying pixel information (such as grabbing regions of pixels for example)
Now, if all that sounds like more fun then you can handle, you can easily perform image brightening using a BufferedImageOp...
See, Adjust brightness and contrast of BufferedImage in Java and How to change the contrast and brightness of an image stored as pixel values and Change brightness of image using RescaleOp for examples (these where just the top few that popped up on Google)

Complementary colours - Image Analysis [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am just processing an image, looking at things such as colour and contrast. How ever my issue is analysing the complementary colours in the image and trying to do this efficiently.
Firstly I have got the pixel rgb. I have then converted to HSV and increase the hue and return to rgb, hence obtaining the complementary colour. I am then looking at its closet neighbours to see if any of these are complementary colours. How ever given these are pixels, it is rare one would find the central pixel to be a complementary - hence I do not feel this is very efficient.
Or another idea... to segment the image in accordance to colour regions and work out the distance from one region to another if there is a region with the complementary colours.
Any ideas and any ideas on how to efficiently code this?
Thanks
So I eventually worked out roughly how to do this, either by a very slow way or a slightly faster way:
segment image into colour regions
calculate complementary of colour region by adding 0.5 to the hue of the colour
look at closest neighbours to complementary aswell, as we may not have exact complementary colour present
calculate euclidean distance from the segment to the complementary segment (if this exits) and calculate 1/ED - this will be 1 if close and nearer to zero if far away, so acts like a weight.
calculate proportions in segment to weight pairing of complementary colours accordingly.
Otherwise
As opposed to segments do this for each pixel to every other pixel

Categories

Resources