I am creating a 2D game with lwjgl and slick-util. For a special feature in my game I wanted to be able to give textures a certain opacity. I have managed to figure this out but the next step is giving a Texture as a paramter which will give me the ability to give certain textures certain opacities in certain spots.
Note: I have gotten it sort of working before, but the mask also seemed to remove my background image, which I do not want.
I cannot post images because I dont have enough reputation or something but anyway what I want to basically do is:
first render a background image.
then render another images on top with a mask on it, I do not want this mask to apply onto the background.
How would I go about doing this?
I think you use wrong blending mode. If you did not change default blending mode, then you need:
glEnable (GL_BLEND); // Enable blending.
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Setup blending function.
I think in you case, texture does not blend with background, it simple replaces background.
Related
I'm using SVG files in my Game and i want to add transparency and brightness effects to them. So what i want is that a sprite becomes more and more transparent until it's invisible. This looks much smoother than a just disappearing sprite. This allows also smooth transitions between the levels where a white screen gets less transparent and then again more. I hope you understand what i mean. Besides this a brightness effect would be nice, too. A sprite can get brighter or darker during the game. Nevertheless i could create a workaround for this using the transparency effect, but yeah, i have none :/
I use this library:
https://androidsvg.googlecode.com/hg/doc/reference/packages.html
I render my svgs on this way:
svg.renderToCanvas(pCanvas);
However i can also convert it to pictures:
Picture pic = svg.renderToPicture();
Maybe this information will help you.
Does there exist something what could help me? And if not, have you an idea how can i solve the problem?
EDIT:So iwant my SVGs behave like these ones:
http://scratch.mit.edu/projects/24634091/
You could use an ImageView and setAlpha(), as Frank says. Or it may just be easier to render the sprites to the canvas in your draw() method.
If you are writing a game, then you may find that rendering SVGs in your game loop may not be fast enough. So you might have to pre-render all your SVG sprites to Bitmaps (ie on startup) and draw them to your Canvas.
Paint p = new Paint();
p.setAlpha(alpha);
canvas.drawBitmap(sprite, x,y, p);
Can you modify the darkness you get on screen when using a ray handler in libgdx with box2d world? Also when I put lights over sprites they look different because the light is on top of them. Can you render lights so that the color of the sprite is the same, even though it is lighted up by a source?
Yes. You can modify the darkness by setting ambient light. For instance:
rayHandler.setAmbientLight(0.5f);
makes everything 50% brighter.
Also, if you find that the lights over your sprites cause too much of a difference in colour, you might want to set the light's colour to white and set the alpha lower (just tweak around with it until you think it looks good).
I need to capture more pixels than the width of the screen contains to save a higher res image. I figure the only two options are to pack more pixels into the screen with some Matrix command, or to make the actual view larger than the screen (which I don't think is possible.) I should probably make it known that I'm using OpenGL ES 2. Any help?
The technique you're looking for is called Render to Texture. Essentially you create an offscreen framebuffer, and redirect your draw calls to this framebuffer instead of the default.
You can make your framebuffer as big as you want (within hardware limitations).
This looks like a reasonable example:
http://blog.shayanjaved.com/2011/05/13/android-opengl-es-2-0-render-to-texture/
I want to have a global gradient that goes all the way across the window but it only appears in certain objects with OpenGL. It's a bit like using a 'Clipping Mask' in Photoshop, here is an example on what I am trying to achieve.
(by the way I am doing this with LWJGL in Java, but that shouldn't affect to much.)
Have the texture coordinates aligned with the screen coordinates of your objects. That will cause the texture to be mapped as you want to.
I'm trying to draw a 2D contour plot of some data on Android and I'm wondering what the best approach would be to draw those. The whole datasets can be relatively large (2k * 2k points) and zooming and moving inside the plot should be very fast. Most of the time only a small part of the data will be drawn as the user has zoomed in on the data.
My idea now would be to draw the whole plot onto a large canvas, but clip it to the portion visible on the screen, so that only that part would be really drawn in the end. I find the 2D drawing API of Android somewhat confusing and I'm not sure if this is really a feasible approach and how I would then go about executing it.
So my questions are:
Is it a good idea to draw onto a canvas much larger than the screen and use clipping to display only the relevant part?
How would I create a larger canvas and how would I select which parts should be drawn?
You should start the other way around. Instead of creating a huge canvas you should detect what part of your plot you need to draw and draw only that.
So basically you need some navigation/scrolling and you need to keep the offset from the starting point in memory to calculate where you are. Using the offset you can easily zoom in and out because you just need to scale the plot to the screen.
Is it a good idea to draw onto a
canvas much larger than the screen and
use clipping to display only the
relevant part?
A better question might be, do you have any other options. Some might argue that this is a bad idea since your going to keep memory in use when it isn't relevant to whats happening on the UI. However, from my experiences with the Canvas, I think you'll find this should work out just fine. Now, if you are trying to keep "5 square miles" of canvas in memory your definitely going to have to find a better way to manage it.
How would I create a larger canvas and
how would I select which parts should
be drawn?
I would expect that you will be creating your own "scrolling" method when the user touches the screen via overriding the onTouchEvent method. Basically your going to need to keep track of a starting point X and Y and just track that value as you move the Canvas on screen. In order to move the Canvas there are a number of built in's like translate and scale that you can use to both move the Canvas in X and Y as well as scale it when the user zooms in or out.
I don't think that is a good idea to draw your 2D contour plot on a big bitmap because you need a vector type graphics to zoom in and out in order to keep it sharp. Only pictures are good to scale down but graphs will lose thin lines or come out deformed when scaled down in bitmaps.
The proper way is to do it all mathematically and to calculate which part of the graph should be drawn for required position and zoom. Using anti_alias paint for lines and text, the graph would always come out sharp and good...
When the user zooms out, some items should not be drawn as they could not fit into the screen or would clutter it. So the graph would be always optimised for the zoom level...