Skip to main content
GameDev.net gamedev.net
🔒 Locked

VAO problem

Started by furrymaster Jun 8, 2010 at 12:57 AM 12 replies 2.5k views
Original Post
furrymaster
furrymaster
Hi, I have problem with VAO, I think Ive done everything well, but its not working... I dont know what is wrong, can you help me?
Here
s code:
init:
glGenVertexArrays(1,&arrayBuffer);			glBindVertexArray(arrayBuffer);			glGenBuffers(1, &idv);//vertexy			glBindBuffer(GL_ARRAY_BUFFER, idv);			glBufferData(GL_ARRAY_BUFFER, verts*(isXYZ?3:2)*sizeof(float), vertices, GL_STATIC_DRAW);                        glVertexAttribPointer((GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0); 			glEnableVertexAttribArray(0);			glGenBuffers(1, &idc);//tex coords			glBindBuffer(GL_ARRAY_BUFFER, idc);			glBufferData(GL_ARRAY_BUFFER, verts*2*sizeof(float), coords, GL_STATIC_DRAW);                        glVertexAttribPointer((GLuint)1, 2, GL_FLOAT, GL_FALSE, 0, 0); 			glEnableVertexAttribArray(1);						glGenBuffers(1, &idn);//normals			glBindBuffer(GL_ARRAY_BUFFER, idn);			glBufferData(GL_ARRAY_BUFFER,verts*3*sizeof(float), normals, GL_STATIC_DRAW);			glVertexAttribPointer((GLuint)2, 3, GL_FLOAT, GL_FALSE, 0, 0); 			glEnableVertexAttribArray(2);			glGenBuffers(1, &idi);//indices			glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, idi);			glBufferData(GL_ELEMENT_ARRAY_BUFFER,indices*sizeof(unsigned int), indexes, GL_STATIC_DRAW);                        glEnableVertexAttribArray(3);//with or without this?

render:
glBindVertexArray(arrayBuffer);//buffer VAO         	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, idi);//index buffer	glDrawElements(GL_TRIANGLES,indices,GL_UNSIGNED_INT,0);//index count	glBindVertexArray(0);
If I helped you rate me
karwosts
karwosts
Also give a better description of the problem than "it's not working"
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
furrymaster
furrymaster
GlError is 0.
Quote:
Also give a better description of the problem than "it's not working"

I really dont't know what I can tell you more...
I have no errors, verts,coords,normals and indices are the same as in VBO(which is working without any problem). Maybe I give bad macro or I use bad function somewhere?
If I helped you rate me
karwosts
karwosts
Do you just have a blank screen then?

If that is the case than say so, "Not working" could mean 50 different things.


Also you don't want this: "glEnableVertexAttribArray(3);//with or without this?"
Indices are not a vertex attrib. Don't know if that's your only problem though.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Shintah
Shintah
As karwosts said.

glVertexAttribPointer((GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0);

This is wrong I think. You should be passing the location for the attribute in the shader program that is bound, not just an arbitrary int.

Use glGetAttribLocation to get the location of an attribute from a shader and use that as argument for glVertexAttribPointer and glEnableVertexAttribArray.
furrymaster
furrymaster
Quote:

Do you just have a blank screen then?
If that is the case than say so, "Not working" could mean 50 different things.

Yes it draws nothing.

Quote:

Also you don't want this: "glEnableVertexAttribArray(3);//with or without this?"
Indices are not a vertex attrib. Don't know if that's your only problem though.

Even without this its not working
If I helped you rate me
furrymaster
furrymaster
Quote:
Original post by Shintah
As karwosts said.

glVertexAttribPointer((GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0);

This is wrong I think. You should be passing the location for the attribute in the shader program that is bound, not just an arbitrary int.

Use glGetAttribLocation to get the location of an attribute from a shader and use that as argument for glVertexAttribPointer and glEnableVertexAttribArray.


You wrote lasrt message at the same time as me:),
But if i dont want to send pointers to shader? I only want to render without any vert/frag shader, just draw
If I helped you rate me
karwosts
karwosts
You should be using glVertexPointer/glNormalPointer/glTexcoordPointer instead of glVertexAttribPointer and use glEnableClientState (look up the arguments) instead of glEnableVertexAttribArray if you don't have a shader.

I think they may work on some implementation if you guess the right integer, but I don't think that behavior is in the spec.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
furrymaster
furrymaster
But thats VBO not VAO... So can u tell me for what(for example) is VAO? I thought thats sth like VBO but for animation etc.
If I helped you rate me
karwosts
karwosts
No, I think you are confused. glVertexPointer and glVertexAttribPointer are equivalent functions, the former is used for sending vertices to the fixed function pipeline, the latter for sending arbitrary vertex data to a shader.

VAO is just a small wrapper around VBO's that help you get a minor performance benefit by reducing the number of calls needed to change state. You can use them with glVertexPointer or glVertexAttribPointer, that doesn't matter. VAO just sets up your pointers.

Read this, paying particular attention to the "Legacy Notes".

VAO
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
furrymaster
furrymaster
oh, I think i understand, thats for exaple to make easyer to use attributes in shader like tengens, binormal etc?
If I helped you rate me
karwosts
karwosts
Yeah you use glVertexAttribPointer for any data you want to send to a shader. It can be any arbitrary data that you want.

You just define an input variable in the shader, compile it, ask the gpu which vertex attribute corresponds to that variable, and then set the pointer with glVertexAttribPointer.

If you don't have a shader then you don't need to use it.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
furrymaster
furrymaster
SO if I dont use shader for some kind of object, VBO is enough(/ok)?

edit:
and if I want use shader and draw object i should do like this?:
glEnableClientState(GL_NORMAL_ARRAY);		glEnableClientState(GL_TEXTURE_COORD_ARRAY);		glEnableClientState(GL_VERTEX_ARRAY);glBindVertexArray(arrayBuffer);//buffer VAOglBindBuffer(GL_ARRAY_BUFFER, idv);		glVertexPointer((isXYZ?3:2), GL_FLOAT, 0, 0);		glBindBuffer(GL_ARRAY_BUFFER, idn);		glNormalPointer(GL_FLOAT, 0, 0);		glBindBuffer(GL_ARRAY_BUFFER, idc);		glTexCoordPointer(2, GL_FLOAT, 0, 0); 		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, idi);	glDrawElements(GL_TRIANGLES,indices,GL_UNSIGNED_INT,0);//index count	glBindVertexArray(0);
If I helped you rate me

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.