的OpenGL(ES) - glBindBuffer抛出:IllegalArgumentException - :剩余<尺寸() [英] OpenGL (ES) -- glBindBuffer throws IllegalArgumentException: remaining < size()

查看:266
本文介绍了的OpenGL(ES) - glBindBuffer抛出:IllegalArgumentException - :剩余<尺寸()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了顶点,使用调用glDrawArrays时正确绘制的缓冲区,但他们未能加载到一个VBO。这里的code:

I've made a buffer of vertices that correctly draw when using glDrawArrays, however they fail to load into a VBO. Here's the code:


FloatBuffer circleBuffer = ByteBuffer.allocateDirect(numVertices * 3 *
  4).order(ByteOrder.nativeOrder()).asFloatBuffer();

for (int j = 0; j < numVertices; j++) {
  circleBuffer.put((float) (Math.cos(theta)));
  circleBuffer.put((float) (Math.sin(theta)));
  circleBuffer.put(1);
  theta += 2 * Math.PI / (numVertices);
}

int[] buffer = new int[1];
int circleIndex=0;  
gl11.glGenBuffers(1, buffer,0);
circleIndex = buffer[0];
gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, circleIndex);
gl11.glBufferData(GL11.GL_ARRAY_BUFFER, circleBuffer.capacity() * 4,
  circleBuffer, GL11.GL_STATIC_DRAW);

我所输出的缓冲器的容量,它是105,其余为0。我还试图重新分配FloatBuffer作为缓冲剂。什么是错在这里?谢谢!

I outputed the capacity of the buffer and it is 105, and the remaining is 0. I also tried reassigning the FloatBuffer as a Buffer. What's wrong here? Thanks!


ERROR/AndroidRuntime(7127): java.lang.IllegalArgumentException: remaining() < size
ERROR/AndroidRuntime(7127): at com.google.android.gles_jni.GLImpl.glBufferData(Native Method)

编辑 - 解决方案

EDIT -- Solution


buffer.flip();

推荐答案

一个Java异常应该由不喜欢它们的参数的方法来刻意抛出。它延伸的RuntimeException,这意味着它不需要被抓住。
奇异的名字尽管如此,可以重新多个参数之间present不满意约束。你越是使用,并检查参数,你越是对异常移动方法调用正确的。
在许多情况下,code,它抛出NullPointerException异常应该是参数检查和引发此,一个体面的explanitory消息。

A Java exception which should be deliberately thrown by methods that don't like their parameters. It extends RuntimeException, which means it does not need to be caught. The singular name notwithstanding, can represent unsatisfied constraint between more parameters. The more you use and check the parameters, the more you move towards exception in the method invocation proper. In many cases, code that is throwing NullPointerException should be argument-checking and throwing this, with a decent explanitory message.

这篇关于的OpenGL(ES) - glBindBuffer抛出:IllegalArgumentException - :剩余&LT;尺寸()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆