OpenGL and 9patch drawables

I am making a brickwork game on an android with opengl, and I decided that I want to use 9patch hoods, so that, for example, the brick can scale to be wider or taller. Is it possible?

In addition, I made my images and then used draw9patch.exe in the Android tools folder to create the images. It was quite some kind of work, and now it turned out that she added a few pixels to each side, so that the images no longer have the power of the two that they should be.

So, how do I use nine patch panels with openGL?

+4
source share
3 answers

It seems that NinePatchDrawable objects do not allow you to access the basic bitmaps, but I suppose you could draw them on the canvas and then read the resulting bitmap from this. This will probably also solve your problem with two strengths.

You can then read the fill area using getPadding () and convert these positions to a range of 0..1 to use as texture coordinates.

Then, in OpenGL, you will draw a textured brick using a nine-quad grid, such as the "#" symbol. Your texture coordinates for the vertices will be fixed and match your addition with nine patches. The coordinates of your position will depend on the scaling of your block. You would keep your corner squares the same size and scale the square square as desired. (The rest of the squares will be scaled in one dimension, as required so that everything is connected).

Personally, I would be inclined to forget about nine Android patches and instead adopt a brickwork convention where (say) the average 50% of the width and height are stretched, and 25% are not around the perimeter. Depends on how much work you throw away nonetheless.

+1
source

So, how do I use nine patch panels with openGL?

No. 9-patches and drawings are intended for use with the usual classes of Android View, and not with OpenGL. If you want to have this behavior, you will have to implement your own OpenGL visualization, including parsing the 9-patch PNG.

+2
source

so that the images are not more than two, and they should be.

If you are using OpenGL-ES 2, this restriction has been removed. Textures can be of any size.

0
source

Source: https://habr.com/ru/post/1392124/


All Articles