can I draw polygons on texture with GLSL? - android

I'm completely new to OpenGL so my question might sound stupid but I'm trying to do one thing for more then week and I got completely stuck.
I'm trying to draw a globe that you can rotate and zoom and pick the country on Android. There are no problems with rotation but there are some with zooming (texture looks ugly if camera come closer) and I have no idea how to implement country picking. I have an arrays for each country with lat,log for each vertex of country border. But how can I draw it on the sphere ?
I've been trying to convert lat,long to zyx and draw lines but there is a triangulation issue to build polygons. Is it possible to draw texture on run-time with shaders? and is it possible to get a touch point on texture ? (I'd like to highlight selected country by filling it with another color)
I don't need a map, just a countries with one color, borders with another one and rest of the globe with third one.
I'm using Rajawali lib for this purpose. Although it is opensource but it has no comment and tiny doc is outdated so if you know better framework please suggest me.

Related

Mapbox : How to animate Polygon transformation

Its pretty simple to transform a Point feature from one to another like this :
But I am facing a usecase that needs to animate polygon feature from one state to another, sometimes the polygons (old and new) can have different number of vertices like shown below below where I want to smoothly animate the left polygon to right?
Are there any pre-built APIs or efficient way of doing these things?
sometimes the polygons (old and new) can have different number of vertices
As a solution for this particular problem, you can simply add intermediate nodes on the polygon that has less vertices. The image below shows how to get from polygon A (a rectangle) to polygon B (a "plus" shape). It is a screenshot taken from this video, which I suggest you checkout out.
Now, the difficult part is how to determine where to add those nodes ?
Do you have more info on these polygons ? Is there a relationship between them ?

Drawing a 2d convex hull shape on a 3d terrain

I have a 3d mesh, which is a terrain. This runs perfectly fine btw, but I want to have shapes moving accross this terrain. These shapes are flat on the landscape and are blob-like: They can change shape and should follow the contoures and the heightmap of the terrain. These shapes can be painted on the landscape or flow over it, that doesn't matter.
The shapes are meant to be blocks of armies moving across the map, and this should be happening Real-Time! Also: they are 2d convex hull shapes. Also they are just one color with an alpha value (like blue with alpha 0.25f).
The only problem is: I can't figure out how to do this and the question is: Can anyone tell me how to do it?
My first thoughts were just to copy the terrain vertex matrix, push it up a bit so it will be on top of the terrain, load this buffer into a VBO and update the index buffer according to the position and shape needed and then draw the shape. This is rather slow and inefficient, especially when the shape is moving and changing. Also, the resolution of the heightmap is 175x175, so the movement is not at all smooth but rather jaggy.
Then I thought, but rather new to this area, update the shape outlines to the fragment shader of the terrain and let the shader decide if a point lies in that area and change color accordingly. This also was a really slow option, but if anyone sees potential and a good way to do this, tell me!
The next option was to draw directly onto the texture, which is still in the failing stage. If someone has any good ideas on how to draw a scene to a flat area and then put that on a terrain mesh, that would be great!
So if anyone has a solution to draw a shape (or multiple) on a terrain? That would be awesome. Thanks in advance!

How can I create curves with openGL ES android

I'm currently working through a set of tutorials on Android OpenGL ES (1.1) and feel like I'm starting to get a grasp of how the vertices and textures work, along with some sprite animation. As I understand, the only primitives here are points, straight lines, and triangles.
I'm now trying to create a simple curve and really don't know where to start.
I want the curve to be drawn dynamically to represent something like a beam deflection like this where I could input a force and have the curve change.
Is it something I would create with a line loop or triangle fan with a ton of vertices? Or perhaps a texture that I then manipulate?
Any input or a point in the right direction is much appreciated, thanks.
I can recommend this blog post http://blog.uncle.se/2012/02/opengl-es-tutorial-for-android-part-ii-building-a-polygon/ sadly the original source returns a 404. Hopefully the link provides the same quality of information. Anyhow, a good read for openGL.
You have the general idea. Whatever you do must be made of lines, points or triangles. You can generate all the numbers for any pseudo-curve however you want, but you're always going to be passing the resulting vertices to OPENGL then connecting those with lines and triangles.

Drawing a 3d object inside a 3d object using java opengl1.0 for android

I have a 3D cube created using GL_TRIANGLE_STRIP.Is it possible to draw points(using GL_POINTS) or a triangle (using GL_TRIANGLE) on/inside my 3D Cube?How could that be achieved?
If you want to draw something directly of the face of another object (by using the exact same vertex coordinates), you will need to use glPolygonOffset to prevent stitching. There is a chapter in the Red Book that explains it.
If by inside you mean to draw something in the volume of the cube, than there is nothing stopping you. You just need to get the alpha values and blending right to actually see through the cube. Look for some generic tutorial on transparency in OpenGL.
But maybe I'm horribly mistaken and what you are looking for a textures.
If I understand you correctly you could just generate the appropriate texture with the points and apply it to the cube.

Android: how to have an animation on top of a background image

What I'm trying to do is have a background image, for sake of simplicity, lets say it's a picture of the front of a house. Then, I want to have a red ball move from window to window.
**I want to have a background picture, and a picture on top of it.
**I then want to be able to tell the top picture EXACTLY where to go.
How can I do this?
I'm just beginning to learn about animations in Android, and have not yet run across any way to do this.
There are two routes to animation in android: Canvas and OpenGL ES.
I would recommend OpenGL for anything requiring smoothness and speed, like a moving ball.
You should create a view using the helper class GLSurfaceView
http://android-developers.blogspot.com/2009/04/introducing-glsurfaceview.html, and implement a Renderer.
I assume you have the images saved in your res/drawable folders, in a format like png and the ball file contains an alpha channel.
You can see many tutorials online, but basically you need to load your background image and your ball resource at onSurfaceCreated and store it in a texture using GLUtils.texImage2D.
In the onDrawFrame method, you should set up a 2D projection such as glOrtho2D, then draw the background.
Then just before you draw the ball texture, you can use the glTranslate(x,y,0) function to move the ball over the house. Use an alpha blend for the ball:
glBlendFunc(GL_SRC_ALPHA, GL_SRC_ONE_MINUS_ALPHA);
glEnable(GL_BLEND);
Unfortunately writing in OpenGL isn't as straightforward as you might hope. Everything is done with 3D coordinates, despite the fact you want only a 2D image. But hopefully this gives you enough info to google for good exmaples, which are abundant!

Categories

Resources