添加在一个OpenGL屏幕按钮按钮、屏幕、OpenGL

2023-09-06 04:28:02 作者:伊人未归、旧城已空

我创建了一个旋转的立方体与OpenGL在机器人的帮助下,现在我想添加一个监听器来处理立方体,即转动,当我点击按钮,然后CUBE必须开始旋转,副versa..How我可以加在一个OpenGL屏幕按钮?

I have created a rotating CUBE with the help of OPENGL in Android now i want to add a listener to handle the rotation of the cube i.e. When i click button then CUBE must start rotating and vice versa..How can i add a button on an OPENGL Screen?

推荐答案

有两个选项:

创建一个布局,包括你的 GLSurfaceView 和任何你想要的按钮/设置。使用标准的 OnClickListener 的按钮,并有听众致电您的渲染方法做旋转。这是pretty的多少来得到这个工作,最简单的方法,但按钮的风格,将改变基于操作系统版本和供应商。如果你想有更多的控制按钮,你可以尝试其他的选项。 在画使用OpenGL的按钮。当您呈现立方体,切换投影矩阵,以正投影( glOrtho )具有相同尺寸的屏幕,并绘制纹理的矩形,您的按钮图像(你也可以像机器人确实通过使用9矩形保持角部和边缘锋利,只是比例通常是一个梯度或纯色)的图像的内部部分缩放您的按钮图像。你必须设置你的渲染器为接收触摸输入,并做了简单的围堵检查pressed点是按钮的范围内。如果是,那么你可以调用处理旋转的方法。 Create a layout that includes both your GLSurfaceView and whatever buttons/settings you want. Use the standard OnClickListener for the button and have the listener call a method in your renderer to do the rotations. This is pretty much the easiest way to get this working, but the style of the button will change based on OS version and vendor. If you want to have more control over the button, you can try the other option. Draw the button using OpenGL. After you render the cube, switch the projection matrix to an orthographic projection (glOrtho) with the same dimensions as your screen and draw a textured rectangle with your button image (You can also scale your button image like Android does by using 9 rectangles to keep the corners and edges sharp and just scale the inner part of the image which is usually a gradient or solid color). You'll have to set your renderer up to receive touch input and do a simple containment check that the pressed point is within the bounds of the button. If it is then you can call the method that handles rotation.

如果你想有一个全面的UI库,我敢肯定,支持OpenGL ES在Android上存在,其中大部分可能会成为更大的游戏引擎的一部分,这将处理大部分工作,有几个在那里为你。如果你只是想在一个按钮,虽然,我会因为这是最简单的建议第一个选项。

If you want a full-blown UI library, I'm sure there are several out there that exist for OpenGL ES on Android, and most of them would probably be part of larger game engines, which would handle most of the work for you. If you just want the single button though, I would recommend the first option as it's the simplest.