Enlarging Textures in Android OpenGL ES? - android

I have a small issue.
I need to enlarge(Zoom) Textures when I hold&drag at the corners.
I am using glOrtho() to setup ModelView.
gl.glOrthof(0.0f, screen_width, -screen_height, 0, -1.0f, 1.0f); //Map exact pixel to World Co-od
I am able to do hit-test and detect corners of the images(Textures) on the screen.
Now I need to enlarge(zoom) the image(texture). I have offset values, means how far I moved on the screen in X,Y directions.
If I need to use glScalef(), it will accept values in percentage(I think). How can I map the offset values to this percentage value.
or is there any other way to zoom(ie by enlarging the background polygon vertices, so that the mapped texture will automatically get zoomed) ? In this method, I am fixing the polygon sides at time of Surface Creation.
Please help me in this.
Thanks in advance. Your help is really appreciated.

ok... I am answering my own question..
I did this by changing(increasing / decreasing) the vertices values according to stylus move on the screen.
Now, I am able to zoom the image in specified direction.
But, I am not getting exact behavior, like the center of the image(x,y) is not perfect (I am calculating Image boundaries by using image center values). So, the hit-test is not properly functioning.
I am doubting, it may not be the correct way to zoom an image by changing the vertices values.
Still, need to explore. If anybody got any idea, please feel free to share.
Thanks in advance.

Related

OpenGL android 2D projection matrix

I am using OpenGLES20 with android and I would like to know how to do the following:
I think it's easier to explain with a picture...
How can I rectify this stretching. Note: I am working in 2D.
I've heard this problem is solved using something called a projection matrix. I have also read a StackOverflow question saying that the android documentation for setting up a projection matrix is not good. I have tried it personally and couldn't get it to work.
This question is extremely poorly put. On the left image you have rectangular view with coordinate system [0,1]x[0,1] and a correctly drawn triangle while on the right you have the same view with view coordinate system and stretched triangle... Taking this 2 things into consideration your triangle coordinates are already stretched to begin with (or there is an extra model view matrix). If they weren't stretched the triangle would be drawn correctly on the right image.
It is a very common issue your scene is stretched when dealing with different view ratios. In general to solve this you are looking for something like glOrtho which can define your coordinate system. The input parameters for this method are left, right, top and bottom and it is easiest to simply use screen coordinates (like presented on the right image). Another approach is to normalise this input to either [0,1]x[0,height/width] or [0,width/height]x[0,1]. These two methods represent "fit" and "fill" and which is which depends on width of view being smaller or larger then height (portrait, landscape).
When using a correct orthographical matrix your square will always be a square without using any additional matrices or multiplying the vertex arrays... In your case it seems you already multiplied your vertices so I suggest you remove that, all of it. If you can not and those vertices will continue to be scaled incorrectly I suggest you use model view matrix to rescale them.

Android - size of the screen that is currently displayed

I am a developer in Korea.
I avail weak point very English.
Try to draw the ocean map using OpenGL ES.
Therefore, it is us with a direct manipulation of movement when you touch the screen, zoom in / zoom out function.
To get the movement value to know the difference between the width height of the screen according to the zoom state of each is likely to be.
Is there a way to check the internal coordinates of the lower right and the most coordinate of the top left of the screen to be projected in the current Android?
We can not speak English, you can complement the description of the picture.
Please help me.
Are unable to work.
I Hope this will help you:
getWindow().getWindowManager().getDefaultDisplay().getWidth();
getWindow().getWindowManager().getDefaultDisplay().getHeight();

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!

Opengl es rotation causing stretching of rectangle

I am working on a project that uses scale/translate/rotate. I know that I need to rotate first (bottom of list of transformations) I am currently pushing before every objects draw and popping matrix afterwards. This is done in the draw() method I created. I have tested removing drawing of objects systematically and not using transformations other than rotate on the object in question.
This is my problem. When I rotate the object at 0/360 degrees it is a perfect square, as it rotates it stretches longer along the x-axis (still maintaining properties of a rectangle if you follow me) at 270 degrees (straight down x-axis) the stretch reaches its highest point... It will stretch directly coordinating to the angle in which it is facing. I am setting point of origin to 0,0 before I re-rotate.
I am wondering if this problem is a case of a common newbie mistake, working as intended and I need to compensate, or my code has a flaw that I couldn't find in a few hours of research and digging. I will post code if requested but I think that because of the nature and the checking I have already done it may take quite a bit of space.
Any input would be greatly appreciated.
Thanks in advance!
I changed the image so that I could see more of what was happening. It doesn't appear to be rotating the way I intended so that might be the cause of all this.
After fixing the angle I have noticed that the slope is where it's being drawn from/to is off. I am assuming that I have a problem with my points.

Emulating constant size of point sprites using OpenGL ES

I am trying to emulate point sprites in Android using OpenGL, specifically the characteristic of the size staying the same if the view is zoomed.
I do not want to use point sprites themselves as they pop out of the frustum when the "point" reaches the edge, regardless of size. I do not want to go down the route of Orthographic projection either.
Say I have a billboard square with a size of 1, when the use zooms in, I would need to decrease the size of the square so it looks the same size, if the user zooms out, I increase it. I have the projection and model matrices to hand if these are required as well as the FOV. My head just goes blank every time I sit down and think about it! Any ideas on the necessary algorithm?
Ok, By changing field of view to zoom into the environment I divide the quad size by (max_fov / current_fov). It works for me.

Categories

Resources