lwjgl vbo fatal error ??

I have been looking at dis code for more than an hour and its getting annoying. I have generated a nice stack of fatal error logs already. Maybe someone can help meh? :’(

.render();


public class Mesh3D {

	public static int target = GL_ARRAY_BUFFER;
	
	public int vertexHandle;
	public int size;

	private int position = 0;
	private float[] vertices;

	public Mesh3D(int size) {
		vertexHandle = glGenBuffers();
		this.size = size;
		vertices = new float[size * 3];
	}

	public void put(float x, float y, float z) {
		vertices[position++] = x;
		vertices[position++] = y;
		vertices[position++] = z;
	}
	
	public void put(float x, float y, float z, float width, float height){
		put(x, y, z);
		put(x+width, y, z);
		put(x+width, y+height, z);
		put(x, y+height, z);
	}

	public void upload() {
		FloatBuffer buffer = BufferUtils.createFloatBuffer(size*3);
		buffer.put(vertices);
		buffer.flip();
		
		glBindBuffer(target, vertexHandle);
		glBufferData(target, buffer, GL_STATIC_DRAW);
	}

	public void render() {
		
		glEnableClientState(GL_VERTEX_ARRAY);
		
		
		glBindBuffer(target, vertexHandle);
		glVertexPointer(3, GL_FLOAT, 3 << 2, 0l);
		glBindBuffer(target, 0);

		// FATAL ERROR OCCURS ON NEXT LINE
		glDrawArrays(GL_QUADS, 0, size);
		
		
		glDisableClientState(GL_VERTEX_ARRAY);
		
	}
	
	public void clear() {
	}

}


glVertexPointer(3, GL_FLOAT, 3 << 2, 0l);

should be


glVertexPointer(3, GL_FLOAT, 0, 0L);

the integer 3 in bits looks like this

0000 0000 0000 0011

when you do 3 << 2, you shift the bits 2 spaces to the left.

this turns 3 into

0000 0000 0000 1100

which is the number 12, this is giving you the wrong stride value

[edit]
i wrote 24 instead of 12, fixed it

[double edit]

sorry i’m wrong here never even thought of doing. i always just multiply by 4

I believe it is stride in bytes, but either way it doesn’t work if I put 0, 3, or 18. If stride is messed up, it would only not display at all or render something glitchy.

do you ever put values into verticies?

Try printing out the values of verticies.

It doesn’t matter, they are 0 by default, which shouldn’t cause any problem, I will make sure to put them manually and try though.

Sorry had a lapse between different languages, your right, having values shouldn’t cause any errors


      verticies = new float[size * 3];
      ...
      glDrawArrays(GL_QUADS, 0, size);

if you put the parameter of size as 4, it will make a buffer with 12 vertices and try to draw 4 quads (which needs 16 vertices)

size*3 means each vertex is composed of xyz. That means that vertices.length/3 = verticesAmount

In that case make sure that number is divisible by 4. Thats all i got, taking a look at it.

Sorry , Its 3 am and i’m sorta burnt out, shouldnt be trying to answer questions right now. Maybe someone better than me can help you. Good luck :slight_smile:

Just a heads up (I learned this the hard way)

glVertexPointer

is deprecated, IE, it doesn’t work in “core” more (OpenGL3+).

Normally this wouldn’t be an issue–If you’re on a PC and are on the default compatibility mode, you can use both deprecated and non-deprecated methods without worrying. If you’re on a mac however… and if you use compatibility mode (on my default), you can’t use ANY OpenGL3+ methods. If you turn off compatibility mode, and turn on core mode, you can’t use anything but OpenGL3+.

This method has been replaced with:

GL20.glVertexAttribPointer()

If you want an example on it:
http://www.lwjgl.org/wiki/index.php?title=The_Quad_with_Projection,_View_and_Model_matrices

Sorry if I’m being “that guy” that is trying to get you to do a different method of things, rather than solving your problem directly… But getting rid of deprecated methods really helps in the long run!


[EDIT]
If you want help with your current problem…
(going off of what lion king started)

If you use a size of “GL11.GL_FLOAT”, then that means there is 4 bytes per float. Since you are only using vertices which have 3 components, the stride then is 3 * 4.

Since the vertices are the first thing you’re “setting up” in your VAO, the position should be 0.

So:

glVertexPointer(3, GL_FLOAT, 12, 0L);


[EDIT 2]
glancing through your code, I feel like your drawArrays should be:

 glDrawArrays(GL_QUADS, 0, vertices.length);


[EDIT 3]
I wouldn’t use quads in a custom mesh class… It limits you greatly in what you can have meshes look like… I am not sure if my above code will work w/ quads, I know it’ll work with triangles…
If you do end up using triangles, you second put method could be written this way:

public void put(float x, float y, float z, float width, float height){
   put(x, y, z);
   put(x+width, y, z);
   put(x+width, y+height, z);
   put(x+width, y+height, z);
   put(x, y+height, z);
   put(x, y, z);
}

@orange

I changed my code to gl20 glvertexattribpointer, but the fatal error doesn’t go away no matter what I try :smiley:

Can I see your up-to-date version of the class AND your implementation of it?

dunno if this will help, but i wrote up this quick (working) program


	{	
		float[] test = 
			{ -1f, -1f,
			   0f, 1f, 
			   1f, -1f
			};
		FloatBuffer buf = BufferUtils.createFloatBuffer(6);
		buf.put(test);
		buf.rewind();

		vboID = GL15.glGenBuffers();
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
		GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buf, GL15.GL_STATIC_DRAW);
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
	}
	public void draw() 
	{
		GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
		GL11.glVertexPointer(2, GL11.GL_FLOAT, 8, 0);
		GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3);
		GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
	}

@lion king

Mhmmmmm. Your code also crashes… I will try breaking down my program into the smallest size possible to see if i’m maybe doing something wrong with states, will also try to check for opengl error.

edit–
It seems that I don’t get fatal error if I don’t do glViewport.

Something tells me that glu.gluperspective and gl11.glviewport dont mix together :smiley:
It seems that after I removed viewport call everything magically works…

Ok it seems the problem had something to do with my custom shaders. I was probably overwriting vertex attribute indices.