与OpenGL和Java兼容的抽屉
我正在尝试使用与OpenGL和Java兼容的抽屉,java,opengl,geometry-instancing,Java,Opengl,Geometry Instancing,我正在尝试使用glDrawerElementsInstanced()在不同位置渲染一个三角形100次 我没有把它弄对。我尝试了不同的教程,但都是针对c++的,而不是针对java的。最后一个是 下面是我的示例代码: float offsets = new float[300]; int i = 0; float offset = 0.1f; for (int x = -10; x < 10; x += 2) { for (int y = -10; y < 10; y += 2
glDrawerElementsInstanced()
在不同位置渲染一个三角形100次
我没有把它弄对。我尝试了不同的教程,但都是针对c++的,而不是针对java的。最后一个是
下面是我的示例代码:
float offsets = new float[300];
int i = 0;
float offset = 0.1f;
for (int x = -10; x < 10; x += 2) {
for (int y = -10; y < 10; y += 2) {
offsets[i] = (float) x / 10.0f + offset;
offsets[i + 1] = (float) y / 10.0f + offset;
offsets[i + 2] = 0.0f;
i += 3;
}
}
FloatBuffer attribData = BufferUtils.createFloatBuffer( offsets.length );
attribData.put( offsets, 0,offsets.length );
attribData.flip();
int bufferID = glGenBuffer();
glBindBuffer( GL_ARRAY_BUFFER, bufferID );
glBufferData( GL_ARRAY_BUFFER, 0, m_iUsage );
glBufferData( GL_ARRAY_BUFFER, attribData, m_iUsage );
glEnableVertexAttribArray(index);
glVertexAttribPointer(index,3,GL_FLOAT, false,0,null);
glVertexAttribDivisor(index,1);
glBindVertexArray( m_iVAOid );
glDrawElementsInstanced(GL_TRIANGLES, 3,GL_UNSIGNED_INT,0, 100);
glBindVertexArray( 0 );
此时,我渲染一个中心为0,0,0的正方形。顶点着色器是什么样子的?到目前为止呈现了什么?我在提供的代码中没有看到任何错误。再次检查您的制服是否已设置。当您调用GLVERTEXATTRIBFORMATIONS时,vao是否已绑定?如果不是,那就是错误
#version 330 core
layout(location=0) in vec3 aPosition;
layout(location=1) in vec3 aColor;
layout(location=2) in vec3 aOffset;
out vec3 fColor;
uniform mat4 uModel;
uniform mat4 uView;
uniform mat4 uProjection;
void main(void)
{
gl_Position = uProjection * uView * uModel* vec4(aPosition+aOffset, 1.0);
fColor = aColor;
}