Что означает эта ошибка? 'Эмулятор: glTexImage2D:' Я предполагаю, что это связано с эмулятором, но приложение не работает на моем телефоне либо. Я работал с холстами, растровыми изображениями и всеми видами представлений, и в двух проектах я получаю эту ошибку. Может кто-нибудь мне помочь? Разместим код из обоих проектов, где написано это.
Эмулятор: glTexImage2D: получил ошибку pre :( 0x502 внутренний 0x1907 формат 0x1907 тип 0x1401
Error
Пожалуйста, всем, у кого есть идеи, я попробовал решения практически из всего, что я могу найти, и пока не повезло. Я был бы очень признателен за ваш вклад. Сейчас я пытаюсь выполнить это руководство -2-п-Create-A-SurfaceView / 11-2-п-Create-A-surfaceview.html .
MainActivity.java
public class MainActivity extends AppCompatActivity {
private GameView mGameView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Lock orientation into landscape.
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
// Create a GameView and bind it to this activity.
// You don't need a ViewGroup to fill the screen, because the system
// has a FrameLayout to which this will be added.
mGameView = new GameView(this);
// Android 4.1 and higher simple way to request fullscreen.
mGameView.setSystemUiVisibility(SYSTEM_UI_FLAG_FULLSCREEN);
setContentView(mGameView);
}
/**
* Pauses game when activity is paused.
*/
@Override
protected void onPause() {
super.onPause();
mGameView.pause();
}
/**
* Resumes game when activity is resumed.
*/
@Override
protected void onResume() {
super.onResume();
mGameView.resume();
}
}
GameView.java
public class GameView extends SurfaceView implements Runnable {
private boolean mRunning;
private Thread mGameThread = null;
private Path mPath;
private Context mContext;
private FlashlightCone mFlashlightCone;
private Paint mPaint;
private Bitmap mBitmap;
private RectF mWinnerRect;
private int mBitmapX;
private int mBitmapY;
private int mViewWidth;
private int mViewHeight;
private SurfaceHolder mSurfaceHolder;
public GameView(Context context) {
this(context, null);
}
public GameView(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
mSurfaceHolder = getHolder();
mPaint = new Paint();
mPaint.setColor(Color.DKGRAY);
mPath = new Path();
}
/**
* We cannot get the correct dimensions of views in onCreate because
* they have not been inflated yet. This method is called every time the
* size of a view changes, including the first time after it has been
* inflated.
*
* @param w Current width of view.
* @param h Current height of view.
* @param oldw Previous width of view.
* @param oldh Previous height of view.
*/
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mViewWidth = w;
mViewHeight = h;
mFlashlightCone = new FlashlightCone(mViewWidth, mViewHeight);
// Set font size proportional to view size.
mPaint.setTextSize(mViewHeight / 5);
mBitmap = BitmapFactory.decodeResource(
mContext.getResources(), R.drawable.steemlogo);
setUpBitmap();
}
/**
* Runs in a separate thread.
* All drawing happens here.
*/
public void run() {
Canvas canvas;
while (mRunning) {
// If we can obtain a valid drawing surface...
if (mSurfaceHolder.getSurface().isValid()) {
// Helper variables for performance.
int x = mFlashlightCone.getX();
int y = mFlashlightCone.getY();
int radius = mFlashlightCone.getRadius();
// Lock the canvas. Note that in a more complex app, with
// more threads, you need to put this into a try/catch block
// to make sure only one thread is drawing to the surface.
// Starting with O, you can request a hardware surface with
// lockHardwareCanvas().
// See https://developer.android.com/reference/android/view/
// SurfaceHolder.html#lockHardwareCanvas()
canvas = mSurfaceHolder.lockCanvas();
// Fill the canvas with white and draw the bitmap.
canvas.save();
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(mBitmap, mBitmapX, mBitmapY, mPaint);
// Add clipping region and fill rest of the canvas with black.
mPath.addCircle(x, y, radius, Path.Direction.CCW);
canvas.clipPath(mPath, Region.Op.DIFFERENCE);
canvas.drawColor(Color.BLACK);
// If the x, y coordinates of the user touch are within a
// bounding rectangle, display the winning message.
if (x > mWinnerRect.left && x < mWinnerRect.right
&& y > mWinnerRect.top && y < mWinnerRect.bottom) {
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(mBitmap, mBitmapX, mBitmapY, mPaint);
canvas.drawText(
"WIN!", mViewWidth / 3, mViewHeight / 2, mPaint);
}
// Clear the path data structure.
mPath.rewind();
// Restore the previously saved (default) clip and matrix state.
canvas.restore();
// Release the lock on the canvas and show the surface's
// contents on the screen.
mSurfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
/**
* Updates the game data.
* Sets new coordinates for the flashlight cone.
*
* @param newX New x position of touch event.
* @param newY New y position of touch event.
*/
private void updateFrame(int newX, int newY) {
mFlashlightCone.update(newX, newY);
}
/**
* Calculates a randomized location for the bitmap
* and the winning bounding rectangle.
*/
private void setUpBitmap() {
mBitmapX = (int) Math.floor(
Math.random() * (mViewWidth - mBitmap.getWidth()));
mBitmapY = (int) Math.floor(
Math.random() * (mViewHeight - mBitmap.getHeight()));
mWinnerRect = new RectF(mBitmapX, mBitmapY,
mBitmapX + mBitmap.getWidth(),
mBitmapY + mBitmap.getHeight());
}
/**
* Called by MainActivity.onPause() to stop the thread.
*/
public void pause() {
mRunning = false;
try {
// Stop the thread == rejoin the main thread.
mGameThread.join();
} catch (InterruptedException e) {
}
}
/**
* Called by MainActivity.onResume() to start a thread.
*/
public void resume() {
mRunning = true;
mGameThread = new Thread(this);
mGameThread.start();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
// Invalidate() is inside the case statements because there are
// many other motion events, and we don't want to invalidate
// the view for those.
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
setUpBitmap();
// Set coordinates of flashlight cone.
updateFrame((int) x, (int) y);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
// Updated coordinates for flashlight cone.
updateFrame((int) x, (int) y);
invalidate();
break;
default:
// Do nothing.
}
return true;
}
}
FlashlightCone.java
public class FlashlightCone {
private int mX;
private int mY;
private int mRadius;
public FlashlightCone(int viewWidth, int viewHeight) {
mX = viewWidth / 2;
mY = viewHeight / 2;
// Adjust the radius for the narrowest view dimension.
mRadius = ((viewWidth <= viewHeight) ? mX / 3 : mY / 3);
}
/**
* Update the coordinates of the flashlight cone.
*
* @param newX Changed value for x coordinate.
* @param newY Changed value for y coordinate.
*/
public void update(int newX, int newY) {
mX = newX;
mY = newY;
}
public int getX() {
return mX;
}
public int getY() {
return mY;
}
public int getRadius() {
return mRadius;
}
}
Я недавно обратился за помощью, с другим проектом, та же проблема. Вот эта ссылка, Really Weird Emulator Error ?! glTexImage2D - Ошибка растрового изображения / холста? ..
Спасибо всем за помощь, и я очень ценю ваши усилия!