我正在为Android编写信息可视化API,并试图将两个自定义单元GLSurfaceView放入布局中遇到问题.此时的Custom GLSurfaceView只是一个扩展,GLSurfaceView以消除自定义方法可能导致的故障.
当我在布局中添加了两个组件并启动它运行的应用程序时.但没有任何东西被绘制,似乎它进入了一个无限循环.因为Renderers中的调试消息被打印到LogCat中.但是,如果我只使用其中一个自定义GLSurfaceView组件,它的工作完全正常.
我读到GLSurfaceView在多个活动中使用时出现问题,我想在同时使用其中两个组件时也适用.我已经尝试过这里发布的解决方法,但似乎无法让它工作.
我将不胜感激任何帮助.我选择使用openGL以获得更好的性能,但如果我不能同时使用多个组件,我想我将不得不使用Canvas.
清单如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:text="@string/hello" android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.syntronic.vtadlib.VisualizationView android:id="@+id/glview"
android:layout_width="fill_parent" android:layout_height="300px" />
<TextView android:text="@string/hello" android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.syntronic.vtadlib.VisualizationView android:id="@+id/glview2"
android:layout_width="fill_parent" android:layout_height="fill_parent" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
从Activity中,代码如下:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mSurfaceView = (VisualizationView) findViewById(R.id.glview);
mSurfaceView2 = (VisualizationView) findViewById(R.id.glview2);
//Enables debug flags for Errors
//mSurfaceView.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR);
//mSurfaceView2.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR);
mSurfaceView.setRenderer(new …Run Code Online (Sandbox Code Playgroud) 我正试图在OpenGL中将一个视频文件的内容(现在只说没有音频)显示在UV映射的3D对象上.我在OpenGL中做了很多,但不知道在视频文件处理方面从哪里开始,大多数示例似乎都是从摄像机获取视频帧,这不是我想要的.
目前我觉得如果我可以将CGImageRef的单个帧视频设置好,那么我想知道如何做到这一点?也许甚至有更好的方法来做到这一点?我应该从哪里开始,iOS上视频播放最直接的文件格式是什么?.mov格式?
在高层次上,我创建了一个应用程序,让用户可以指向他或她的iPhone相机并查看已经过视觉效果处理过的视频帧.此外,用户可以点击按钮将当前预览的定格作为保存在其iPhone库中的高分辨率照片.
为此,该应用程序遵循以下过程:
1)创建AVCaptureSession
captureSession = [[AVCaptureSession alloc] init];
[captureSession setSessionPreset:AVCaptureSessionPreset640x480];
Run Code Online (Sandbox Code Playgroud)
2)使用后置摄像头连接AVCaptureDeviceInput.
videoInput = [[[AVCaptureDeviceInput alloc] initWithDevice:backFacingCamera error:&error] autorelease];
[captureSession addInput:videoInput];
Run Code Online (Sandbox Code Playgroud)
3)将AVCaptureStillImageOutput连接到会话,以便能够以Photo分辨率捕获静止帧.
stillOutput = [[AVCaptureStillImageOutput alloc] init];
[stillOutput setOutputSettings:[NSDictionary
dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA]
forKey:(id)kCVPixelBufferPixelFormatTypeKey]];
[captureSession addOutput:stillOutput];
Run Code Online (Sandbox Code Playgroud)
4)将AVCaptureVideoDataOutput连接到会话,以便能够以较低分辨率捕获单个视频帧(CVImageBuffers)
videoOutput = [[AVCaptureVideoDataOutput alloc] init];
[videoOutput setVideoSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey]];
[videoOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
[captureSession addOutput:videoOutput];
Run Code Online (Sandbox Code Playgroud)
5)在捕获视频帧时,将每个新帧作为CVImageBuffer调用委托的方法:
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
[self.delegate processNewCameraFrame:pixelBuffer];
}
Run Code Online (Sandbox Code Playgroud)
6)然后委托处理/绘制它们:
- (void)processNewCameraFrame:(CVImageBufferRef)cameraFrame {
CVPixelBufferLockBaseAddress(cameraFrame, 0);
int bufferHeight = CVPixelBufferGetHeight(cameraFrame);
int bufferWidth = CVPixelBufferGetWidth(cameraFrame);
glClear(GL_COLOR_BUFFER_BIT);
glGenTextures(1, …Run Code Online (Sandbox Code Playgroud) 我在Google Play商店中有一个OpenGL应用程序,我面临着每日例外:
java.lang.RuntimeException: eglSwapBuffers failed: EGL_SUCCESS
at android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:1085)
at android.opengl.GLSurfaceView$EglHelper.swap(GLSurfaceView.java:1043)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1369)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1123)
Run Code Online (Sandbox Code Playgroud)
问题是,在我的所有智能手机上,我都无法重现此错误.我已经与谷歌联系了任何设备信息,但他们没有(所以他们说).例外中的平台信息设置为"OTHER".
我在网上发现了一些提示,这个错误可能来自三星Galaxy Y设备,我发现了一些建议,包括:
android:configChanges="orientation|screenSize"
Run Code Online (Sandbox Code Playgroud)
在Android清单文件中,但这不起作用!
当然,我已经为我的GL表面实现了onPause和onResume处理,如果没有,会产生其他eglSwapBuffer问题.
有没有人解决这个问题?
谢谢!
我找到了一种理解为什么glActiveTexture需要的方法.我有以下代码:
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
Run Code Online (Sandbox Code Playgroud)
如果我想象这GL_TEXTURE_2D是挂在墙上的图片框架并且textureId是真实的图片,那么glBindTexture它是唯一一个将真实图片分配给框架的命令,那么,什么是GL_TEXTURE0和glActiveTexture?
我的代码可以正常工作吗?
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
glActiveTexture(GL_TEXTURE1);
glTexImage2D(GL_TEXTURE_2D, .....)
glTexParameteri(GL_TEXTURE_2D, ...)
Run Code Online (Sandbox Code Playgroud)
我目前正在使用OpenGL2.1.
我是Open Gl世界的新手,我已经google了很多,但我无法找到一种方法来实现对正在播放的视频的效果.经过一番研究,我终于找到了一个类可以用来在GLSurfaceView播放视频.我从Google文档中了解到,我们可以对视频应用效果.
通过这篇文章,我能够成功地对位图应用效果.现在我想为我的视频做到这一点,所以任何帮助或指针都表示赞赏.
这是我用于渲染正在播放的视频的VideoSurfaceView
package me.crossle.demo.surfacetexture;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.SurfaceTexture;
import android.media.MediaPlayer;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.opengl.Matrix;
import android.util.Log;
import android.view.Surface;
@SuppressLint("ViewConstructor")
class VideoSurfaceView extends GLSurfaceView {
VideoRender mRenderer;
private MediaPlayer mMediaPlayer = null;
public VideoSurfaceView(Context context, MediaPlayer mp) {
super(context);
setEGLContextClientVersion(2);
mMediaPlayer = mp;
mRenderer = new VideoRender(context);
setRenderer(mRenderer);
}
@Override
public void onResume() { …Run Code Online (Sandbox Code Playgroud) 我有一个我正在研究的iPad应用程序,我们正在考虑的一个可能的功能是允许用户触摸图像并使其变形.
基本上,图像就像一幅画,当用户将手指拖过图像时,图像会变形,触摸的像素将沿着图像"拖动".很抱歉,如果这很难理解,但最重要的是我们想要在用户与之交互时动态编辑纹理的内容.
对于这样的事情,有没有一种有效的技术?我试图弄清楚需要做什么以及操作会有多重.
现在我唯一能想到的就是根据触摸的位置搜索纹理内容并复制像素数据,并在手指移动时对现有像素数据进行某种混合.然后定期用glTexImage2D重新加载纹理以获得此效果.
我有一个动画透明的OpenGL ES子视图(Apple的模板EAGLView类的修改),它绘制一个旋转的球体.就像Apple的例子一样,CADisplayLink用在可用的设备上.
在同一屏幕上,有一个UIScrollView包含可以选择的UIButtons.当用户滚动UIScrollView时,我的EAGLView的动画会冻结.此行为在iPhone 2G设备上的iOS模拟器4.2和iPhone OS 3.1.3上重现.
除了编写自己的滚动视图之外,还有任何关于如何防止EAGLView暂停的想法?
如果我在opengl-es中准备了自定义渲染器:
public void onDrawFrame(GL10 gl)
{
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
// here i want to draw line from [0, 0, 0] to [1, 0, 0]
}
Run Code Online (Sandbox Code Playgroud)
绘制线条最简单,最简单的方法是什么?
在普通的OpenGL中它是:
glBegin(GL_LINES);
glVertex3f(0, 0, 0);
glVertex3f(1, 0, 0);
glEnd();
Run Code Online (Sandbox Code Playgroud)
但是我怎么能用OpenGL ES获得同样的效果呢?
我正在尝试使用以下MediaExtractor示例:
http://bigflake.com/mediacodec/ - ExtractMpegFramesTest.java(需要4.1,API 16)
我遇到的问题是outputSurface.awaitNewImage(); 似乎总是抛出RuntimeException("frame wait timed out"),每当mFrameSyncObject.wait(TIMEOUT_MS)调用超时时抛出它.无论我设置什么TIMEOUT_MS,onFrameAvailable()总是在超时发生后立即调用.我尝试了50毫秒和30000毫秒,它是相同的.
似乎onFrameAvailable()在线程繁忙时无法进行调用,并且一旦超时发生并结束线程代码执行,它就可以解析onFrameAvailable()调用.
有没有人设法让这个例子工作,或者知道MediaExtractor应该如何使用GL纹理?
编辑:在使用API 4.4和4.1.1的设备上尝试了这一点,两者都发生了同样的情况.
编辑2:
得益于fadden 4.4.问题是ExtractMpegFramesWrapper.runTest()调用的方法th.join();阻塞了主线程并阻止了onFrameAvailable()调用的处理.一旦我评论th.join();它就适用于4.4.我想也许ExtractMpegFramesWrapper.runTest()本身应该在另一个线程上运行,所以主线程没有被阻止.
4.1.2调用时还有一个小问题codec.configure(),它给出了错误:
A/ACodec(2566): frameworks/av/media/libstagefright/ACodec.cpp:1041 CHECK(def.nBufferSize >= size) failed.
A/libc(2566): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 2625 (CodecLooper)
Run Code Online (Sandbox Code Playgroud)
通过在通话前添加以下内容我解决了这个问题:
format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 0);
Run Code Online (Sandbox Code Playgroud)
然而,我现在在4.1.1(Galaxy S2 GT-I9100)和4.1.2(三星Galaxy Tab GT-P3110)上的问题是它们都始终将info.size设置为0以用于所有帧.这是日志输出:
loop
input buffer not available
no output from decoder available
loop
input …Run Code Online (Sandbox Code Playgroud)