yes I have used glGenBuffers()
createVertBuffer(indexBuffer);
//Method used:
private static int createVertBuffer(int ID)
{
deleteVertBuffer(ID);
ID = glGenBuffers();
return ID;
}
private static void deleteVertBuffer(int ID)
{
if (ID != 0)
{
glDeleteBuffers(ID);
ID = 0;
}
}
Probably how i’m doing it is incorrect and should just say “indexBuffer = glGenBuffer();” and leave the fancy method stuff out.
Also elFarto I’m going to read that thread a bit and see, It seems close to my error and I tried changing the binding of my buffer and even using and glEnable still get this error:
[NOTE]Exception in thread “main” org.lwjgl.opengl.OpenGLException: Cannot use offsets when Element Array Buffer Object is disabled
at org.lwjgl.opengl.GLChecks.ensureElementVBOenabled(GLChecks.java:105)
at org.lwjgl.opengl.GL11.glDrawElements(GL11.java:1117)
at terrain.Chunk.drawChunk(Chunk.java:320)
at terrain.Terrain.draw(Terrain.java:84)
at Main.render(Main.java:145)
at Main.main(Main.java:83)
[/NOTE]
If you are wondering how I put data into some of my buffers I have a init method that runs before the drawChunk can even be called.
when I run this code: (PS the part of the code with a problem I added a bunch of “//” spacers so you can quickly scroll to it.)
public void drawChunk()
{
ByteBuffer off = BufferUtils.createByteBuffer(1);
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
//Below is suppose to take a float? Ref code:
//glMultMatrixf( glm::value_ptr(m_LocalToWorldMatrix) );
// glMultMatrix(m);
/* Setting up texture stage 0 (or bottom texture) */
glActiveTexture( GL_TEXTURE0 );
glMatrixMode( GL_TEXTURE );
glPushMatrix();
// glScalef(32.0f, 32.0f, 1.0f); scaling out for now
glEnable( GL_TEXTURE_2D );
glBindTexture(GL_TEXTURE_2D, textures[0]);
glClientActiveTexture( GL_TEXTURE0 );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glBindBuffer( GL_ARRAY_BUFFER, tex0Buffer);
glTexCoordPointer(2, GL_FLOAT, 0, off );
// Disable lighting because it changes the primary color of the vertices that are
// used for the multitexture blending.
glDisable( GL_LIGHTING );
// Texture Stage 1
// Perform a linear interpolation between the output of stage 0
// (i.e texture0) and texture1 and use the RGB portion of the vertex's
// color to mix the two.
glActiveTexture(GL_TEXTURE1 );
glMatrixMode( GL_TEXTURE );
glPushMatrix();
// glScalef( 32.0f, 32.0f , 1.0f );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, textures[1] );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE );
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR );
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR );
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_PRIMARY_COLOR );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_COLOR );
glClientActiveTexture(GL_TEXTURE1);
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glBindBuffer( GL_ARRAY_BUFFER, tex1Buffer );
glTexCoordPointer(2, GL_FLOAT, 0, off );
// Texture Stage 2
// Perform a linear interpolation between the output of stage 1
// (i.e texture0 mixed with texture1) and texture2 and use the ALPHA
// portion of the vertex's color to mix the two.
glActiveTexture( GL_TEXTURE2 );
glMatrixMode( GL_TEXTURE );
glPushMatrix();
// glScalef( 32.0f, 32.0f , 1.0f );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, textures[2] );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE );
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR );
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR );
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_PRIMARY_COLOR );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA );
glClientActiveTexture(GL_TEXTURE2);
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glBindBuffer( GL_ARRAY_BUFFER, tex2Buffer );
glTexCoordPointer(2, GL_FLOAT, 0, off );
//Rendering
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_COLOR_ARRAY );
glEnableClientState( GL_NORMAL_ARRAY );
glBindBuffer( GL_ARRAY_BUFFER, vboVertexHandle );
glVertexPointer( 3, GL_FLOAT, 0, off );
// glBindBuffer( GL_ARRAY_BUFFER, color );
// glColorPointer( 4, GL_FLOAT, 0, 0 );
glBindBuffer( GL_ARRAY_BUFFER, vboNormalHandle );
glNormalPointer( GL_FLOAT, 0, off );
//
//
//
//
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, indexBuffer );
glDrawElements(GL_TRIANGLES, m_index.length, GL_UNSIGNED_INT, (long)0);
// glDrawArrays(GL_TRIANGLES, 0, 3); //Works but causes crashes and weird rendering
//
//
//
//Cleanup
glDisableClientState( GL_NORMAL_ARRAY );
glDisableClientState( GL_COLOR_ARRAY );
glDisableClientState( GL_VERTEX_ARRAY );
glActiveTexture(GL_TEXTURE2);
glPopMatrix();
glDisable(GL_TEXTURE_2D);
glClientActiveTexture(GL_TEXTURE2);
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
glActiveTexture(GL_TEXTURE1);
glPopMatrix();
glDisable(GL_TEXTURE_2D);
glClientActiveTexture(GL_TEXTURE1);
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
glActiveTexture(GL_TEXTURE0);
glPopMatrix();
glDisable(GL_TEXTURE_2D);
glClientActiveTexture(GL_TEXTURE0);
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
glBindBuffer( GL_ARRAY_BUFFER, 0 );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
glMatrixMode( GL_MODELVIEW );
glPopMatrix();
}
Also Thank you guys for posting.
Edit:
Also sorry that this code is a mess, as some of the the spots I’m putting a byteBuffer called “off” that is size one, could be giving me grief but idk I’m new to all this (VBOs and OpenGL)