- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我是 java 和 OpenGL 的新手。
我正在尝试让相机预览屏幕能够同时显示 3d 对象。已经在api 演示,我想将示例的代码组合在api演示就足够了。但不知何故它不起作用。强制我在启动时关闭并且错误被称为空指针异常(exception)。有人可以和我分享我哪里出了问题以及如何解决从那里开始。如图所示,我是如何组合代码的下面:
我的概览.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.opengl.GLSurfaceView
android:id="@+id/cubes"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<SurfaceView
android:id="@+id/camera"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</FrameLayout>
我的概览.java
import android.app.Activity;
import android.os.Bundle;
import android.view.SurfaceView;
import android.view.Window;
public class MyOverView extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Hide the window title.
requestWindowFeature(Window.FEATURE_NO_TITLE);
// camera view as the background
SurfaceView cameraView = (SurfaceView) findViewById(R.id.camera);
cameraView = new CameraView(this);
// visual of both cubes
GLSurfaceView cubesView = (GLSurfaceView) findViewById(R.id.cubes);
cubesView = new GLSurfaceView(this);
cubesView.setRenderer(new CubeRenderer(false));
// set view
setContentView(R.layout.myoverview);
}
}
GLSurfaceView.java
import android.content.Context;
class GLSurfaceView extends android.opengl.GLSurfaceView {
public GLSurfaceView(Context context) {
super(context);
}
}
注意:
我没有列出其余文件,因为它们只是api演示。 cameraView 引用 camerapreview.java 示例而 CubeRenderer 指的是 CubeRenderer.java 和 Cube.java例子。任何帮助,将不胜感激。
抱歉,没有意识到由于格式错误导致编码不正确。
最佳答案
使用 .xml 时出现空指针异常的原因是因为您实际上是在 Java 代码中创建新 View .. 而不是使用 .xml 文件中您可能已传入属性的 View (如果你确实传递了属性......)..新 View 显然会有一个空值..因此抛出一个空指针异常......例如 -
cubesView = new GLSurfaceView(this);
如果您已经在包含 FrameLayout 的 .xml 文件中创建了 View ,则代码中实际上不需要。
关于android - 表面 View + glsurfaceview + 框架布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2108600/
我有一个增强现实应用程序,它显示相机 View 和一个带有多边形的 GLSurfaceView,该多边形可以在触摸屏幕时旋转。我的应用程序的主要布局是 FrameLayout。 frameLayout
我对 EGL 感到困惑。 我的 GLSurfaceView 创建了一个 EGLContext。现在我创建一个共享上下文。现在我需要使用 EGLExtension。 我必须使用的方法被称为(>=API1
是否可以在 GLSurfaceView 上添加 LinearLayout?如何在 GLSurfaceView 上叠加 LinearLayout?也许 GLSurfaceView 是 Game play
请,有人可以提供使用带有 GLSurfaceView 的 CameraX 库的好例子,找不到任何信息。 最佳答案 不存在将 CameraX 与自定义表面/TextureView 一起使用的文档。在 C
我尝试在我的 GLSurfaceView 上使用 setRotation(),但 View 似乎没有围绕屏幕中心的枢轴旋转。代码如下: class MyGLSurfaceView extends GL
我正在尝试运行 android 示例 http://developer.android.com/training/graphics/opengl/index.html 我必须向 View 添加一些控件
我有 GLSurfaceView 和顶部带有按钮的小型 LinearLayout,代表菜单。此布局默认隐藏,并在用户点击某个按钮时从屏幕底部(通过 TranslateAnimation)显示。 (也尝
我在我的应用程序中使用开放式 GL。我还在我的 Activity 中创建了一个操作栏,将其 View 设置为表面 View 。但是我无法获得操作栏。它在我的表面后面吗?我不知道。我只是无法得到它。我当
实际上,我有一个项目正在使用 GLSurfaceView。此时此组件作为主控件放置在整个屏幕上。在此配置中,我能够正确处理绘图功能。 在下一步中,我想更改 GLSurfaceView 的大小和位置。我
根据标题,从暂停状态恢复后 GLSurfaceView 为空白。 Renderer的onSurfaceCreated、onSurfaceChanged和onDrawFrame在恢复后被调用,但是屏幕还
我有一个带有可绘制对象作为背景的 GLSurfaceView,但是在没有 surfaceView.setZOrderOnTop(true) 的情况下渲染时只有背景可见 我需要避免使用 setZOrde
我正在尝试在 Android 上使用 GLSurfaceView 并遇到问题。我正在使用 this OpenGL article 中的代码.它运行良好,但当我旋转设备时,我注意到分配的内存在增长。 所
我有一个 GLSurfaceView,我在其中使用 OpenGL 显示一些动画。 我现在想给这个 View 添加一个按钮。这是如何实现的? 不涉及xml布局能不能做到? 最佳答案 您可以手动构建 Vi
我正在做一个项目,我们需要记录渲染的 OpenGL 表面。 (例如,如果我们使用 GLsurfaceView,我们需要记录表面以及来自 MIC 的音频) 目前我通过将视频源设置为 VIDEO_SOUR
我尝试使用 GLSurfaceView 进行渲染,并通过 docs我设置格式: getHolder().setFormat(PixelFormat.TRANSLUCENT); 我使用的是 GLSurf
我的程序在两个 Activity 之间切换,每个 Activity 都会膨胀一个使用 VBO 的派生 GLSurfaceView。 在两个Activity之间来回切换几次后,程序崩溃并抛出如下异常:
我正在尝试在 android 上开始使用 opengl。 我找到的所有教程都假定 GLSurfaceView 可用。当我尝试编译我的项目时,我得到了 GLSurfaceView cannot be r
我目前正在开发一个 Android 应用程序,我希望在单击按钮时重新启动 glSurfaceView。即当单击按钮时,应再次将图像读入程序并重置所有纹理。我应该怎么办?谢谢。 最佳答案 听起来您只想在
虽然我发现了一个关于 Sharing the GLES20 context... 的问题,我觉得我的情况比较宽泛一些。 我有两个 GLSurfaceView 在 FrameLayout 中彼此分层。
我正在尝试使用 MediaCodec 播放视频并通过 GLSurfaceView 呈现它,以便我可以进行帧回调。 package com.alwaysinnovating.aimediacodec;
我是一名优秀的程序员,十分优秀!