- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试使用 GLSurface 来显示自定义 View 。
我的xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="net.letsense.matrixtest.MainActivity">
<android.opengl.GLSurfaceView
android:layout_width="300dp"
android:layout_height="300dp"
android:id="@+id/my_surface_view"
/>
</android.support.constraint.ConstraintLayout>
我的主要
package net.letsense.matrixtest;
import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
/**
* Created by borislegovic on 03/11/2017.
*/
public class Main extends Activity {
private int mPositionHandle;
private int mColorHandle;
private GLSurfaceView mGLView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create a GLSurfaceView instance and set it
// as the ContentView for this Activity.
// mGLView = new MyGLSurfaceView(this);
// mGLView = findViewById(R.id.my_surface_view);
//mGLView.setEGLContextClientVersion(2);
// mGLView = new MyGLSurfaceView(this);
// setContentView(mGLView);
}
@Override
protected void onPause() {
// The following call pauses the rendering thread.
// If your OpenGL application is memory intensive,
// you should consider de-allocating objects that
// consume significant memory here.
super.onPause();
// mGLView.onPause();
}
@Override
protected void onResume() {
// The following call resumes a paused rendering thread.
// If you de-allocated graphic objects for onPause()
// this is a good place to re-allocate them.
super.onResume();
// mGLView.onResume();
}
}
奇怪的是我没有对 surfaceView 对象做任何事情,它仍然让我崩溃:
java.lang.NullPointerException:尝试在空对象引用上调用虚方法“void android.opengl.GLSurfaceView$GLThread.surfaceCreated()” 在 android.opengl.GLSurfaceView.surfaceCreated(GLSurfaceView.java:524)
最佳答案
你的GLSurfaceView没有初始化,你需要初始化它。
首先创建类MyGLRenderer:
class MyGLRenderer implements GLSurfaceView.Renderer {
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
gl.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
}
public void onSurfaceChanged(GL10 gl, int w, int h) {
gl.glViewport(0, 0, w, h);
}
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
}
}
然后将其添加到您的OnCreate 方法中:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mGLView = (GLSurfaceView) this.findViewById(R.id.my_surface_view);
mGLView.setRenderer(new MyGLRenderer());
}
您可以阅读有关 OpenGL ES 的更多信息 here .
关于空对象引用上的 android.opengl.GLSurfaceView$GLThread.surfaceCreated()',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47139348/
我刚刚向 Android 市场发布了我的应用程序的新版本,我的新版本在 Activity 中有一个 GLSurfaceView。尽管我没有做任何花哨的事情,但我有一个庞大的用户群,那里有很多不合标准的
我有一个问题。我的应用程序总是崩溃。代码来自this网站...这是一个非常好的教程,我做了他写的所有内容,但无论如何它都崩溃了...我是 openGlES 的新手,所以这可能是我犯的一个非常简单的错误
我使用 opengl ES 2.0 开发 opengl android 应用程序。我的应用程序崩溃并在日志中写入: 07-28 22:55:29.460 13407-13420/? E/Android
我正在使用 opengl-es 在 android 中使用多线程制作游戏: class World{ protected static final AtomicInteger entityLo
尝试使用 Map 对象添加对象时,在此函数的第 4 行出现并发修改异常: public void reloadResources() { taskQueue.add(new GLRes
我正在尝试使用 GLSurface 来显示自定义 View 。 我的xml 我的主要 package net.letsense.matrixtest; import android.a
我正在实现 Google Maps V2,并在其上绘制从外部 GPX 文件、设备路径、设备当前位置和交付点位置接收的交付路线。问题是它大部分时间都有效......接下来是我得到的错误(当它不工作时):
我正在开发一个使用 OpenGL ES 的应用程序,并且在启动应用程序逻辑之前尝试将纹理加载到内存中。我尝试了一些解决方案,但没有成功。 我的 Activity Oncreate 代码。我的 Acti
在我可以在我的 GLSurfaceView 中渲染任何东西之前,我必须运行大量的初始化 这些必须在 OpenGL 线程上完成。 然而,这会在初始化期间挂起我的主线程。 这是我的代码: @Overrid
我在谷歌上搜索了很多,发现了一些关于堆栈溢出的线程,但它没有帮助。我正在尝试通过调用 Intent 来使用 Android 的内置摄像头。这适用于 2.1,但在 2.2 上我得到“致命异常:GLThr
我正在使用 libgdx 制作安卓游戏。游戏运行良好,但在添加此行后应用程序开始随机关闭。game.debugRenderer.render(game.world,playerCamera.combi
我创建 cocos2d-x 应用程序我正在使用 cocos2d-2.0-x-2.0.4尝试在 Android 模拟器上从 Eclipse 运行应用程序时出现错误。 12-04 08:03:13.792
我是一名优秀的程序员,十分优秀!