在Android中使用OpenGL的按钮,单击绘图形状 [英] Drawing shape on button click using OpenGL in android
问题描述
随着新到Android的OpenGL section.I已经下载网站上给出的样本例子的与OpenGL ES的显示图形
As new to the android OpenGL section.I had downloaded the sample example given on site Displaying Graphics with OpenGL ES
所以运行下载的样本,它的运行有错误并显示输出预期。
我不画在GLSurfaceview的三角形,其工作罚款。
为三角形的截图得出: -
so run the downloaded sample and its running with an error and display the output as expected. I had do draw the triangle in the GLSurfaceview and its working fine. The screenshot for the triangle drawn:-
现在的需求变化,我必须在的onclick的ImageView的,但不画的三角形上启动应用程序。
这里是上面提到的要求截图
Now as the requirement change i have to draw the triangle onclick of the imageview but not on starting the application. Here is the screenshot for the above mention requirement
黑色三角形是ImageView的,右侧是GLSurfaceView区域,我需要绘制triangle.Currently当我点击它不绘制图像的ImageView,但给出了一些例外,这里是logcat的消息:
the black triangle is the imageview and right side is the GLSurfaceView area where i need to draw the triangle.Currently when i click the imageview its doesn't draw image but gives some exception, here is the logcat message:
by Log Tag libEGL
by Log Message called unimplemented OpenGL ES API
我不能够明白的地方我为做这部分的东西wrong.Stuck。
i not able to understand where i m doing something wrong.Stuck of this part.
那么,这种要求可以用OpenGL Android中完成。
So, this kind of requirement can be completed with OpenGL in Android.
推荐答案
这听起来像你正试图使OpenGL的从你的UI线程调用。 GLSurfaceView
创建渲染线程,那就是目前的这种渲染线程的OpenGL上下文。于1981年启动了所有渲染 GLSurfaceView
然后在这种渲染线程中执行。
It sounds like you are trying to make OpenGL calls from your UI thread. GLSurfaceView
creates a rendering thread, and an OpenGL context that is current to this rendering thread. All the rendering initiated by the GLSurfaceView
is then executed in this rendering thread.
您不能让OpenGL的,而无需当前上下文调用,并在UI线程没有这样的,除非你专门创建一个。这样做可能会很麻烦,我不会推荐它用于这种情况。如果你有兴趣反正读了它,我回答了相关的问题,有一天,我试图解释如何创建和使用多个上下文:的如何在Android opengles和质感。
You can't make OpenGL calls without having a current context, and the UI thread does not have one unless you specifically create one. Doing that can get hairy, and I wouldn't recommend it for this case. If you're interested to read up on it anyway, I answered a related question the other day where I try to explain how to create and use multiple contexts: about opengles and texture on android.
做你所需要的最彻底的方法是存储的需要绘制什么再presentation(如3三角形顶点在你的情况下,坐标)作为成员变量 GLSurfaceView.Renderer
的实施。流程然后
The cleanest way to do what you need is to store a representation of what needs to be drawn (e.g. the coordinates of the 3 triangle vertices in your case) as member variables in the GLSurfaceView.Renderer
implementation. The flow is then:
- 在响应UI输入,可以调用上的
渲染
实现,设置在类的成员变量三角坐标的方法。您可能需要使用同步
方法,因为这些坐标将被UI线程和渲染线程可以访问两个。 - 您拨打的
requestRender()
方法触发GLSurfaceView
的重绘。 - 在
渲染
实施将响应被调用的onDrawFrame()
方法。它抓住从成员变量的新坐标,并绘制三角形。
- In response to the UI input, you invoke methods on the
Renderer
implementation that set the triangle coordinates in member variables of the class. You may want to usesynchronized
methods because these coordinates will be accessed both by the UI thread and the rendering thread. - You trigger a redraw of the
GLSurfaceView
by calling itsrequestRender()
method. - The
onDrawFrame()
method of theRenderer
implementation will be invoked in response. It grabs the new coordinates from the member variables, and draws the triangle.
这篇关于在Android中使用OpenGL的按钮,单击绘图形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!