[?] Leaving Immediate Mode (drawing a VBO)

Started by
14 comments, last by _Pickle_ 12 years, 7 months ago
Now I am really confused :mellow:

I don't think I asked the questions in the best manor possible.

Are VBO's, VAO's, and Vertex Arrays all the same thing?

So basically I have a Vertex Buffer Object named resources.vBuffer and I am trying to draw it.
I want it to use the program I have loaded into memory also.

I know that the VBO is in the GPU's memory as I checked with gDEBugger.
(If noone has used that tool, I highly recommend it! It will show redundant state changes as well as everything in the GPU memory.)

So everything is created and is where it needs to be, all I have to do is draw that VBO.
(also the Shader Calculates the Texture Coords.)



Here is what I think is needed without the code specific to drawing the VBO:

void render()
{
glUseProgram(resources.program);
glUniform1f(resources.uniforms.fade_factor, resources.fade_factor);

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, resources.textures[0]);
glUniform1i(resources.uniforms.textures[0], 0);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, resources.textures[1]);
glUniform1i(resources.uniforms.textures[1], 1);

//
// I need to add the code here that will draw the VBO
//

SDL_GL_SwapBuffers();
}
If this post was helpful please +1 or like it !

Webstrand
Advertisement

Are VBO's, VAO's, and Vertex Arrays all the same thing?[/quote]

No, the 3 are different. vertex array is basically your vertices in RAM. GL would send them to the video card every time you make a draw call.
VBO can potentially be stored in VRAM. The driver decides what to do with it and there is no way to know what the driver is doing.
===Just use VBO like everyone else is doing.

VAO was introduced in GL 2.0 as an extension I believe (glGenVertexArraysARB and glBindVertexArrayARB).
Then they went into core with GL 3.0 (glGenVertexArrays and glBindVertexArray) but you are not forced to use them. GL 3.1 forces you to render everything with a VAO bound.
===A VAO is a wrapper object for glBindBuffer and the gl****Pointer calls. It is suppose to increase performance since the driver would have less validation work to do every time you call to glBindVertexArray.

VBO
http://www.opengl.or...x_Buffer_Object

VAO
http://www.opengl.or...ex_Array_Object

More VBO
http://www.opengl.org/wiki/VBO_-_more
http://www.opengl.or...-_just_examples

and good old vertex arrays
http://www.opengl.or...i/Vertex_Arrays

and Tutorials for the GL 3.x generation
http://www.opengl.org/wiki/Tutorials

so yes, you will be using VAO in conjuction to VBO just like those guys in the Tutorials.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
If you only want non-deprecated stuff, you need to stop mixing in deprecated stuff (like glVertexPointer, use of which is enabled via client state and only in a compatibility profile). Also, leaving behind immediate mode doesn't necessarily mean leaving behind the compatibility profiles, so it may have been helpful to specify that up front. Are you certain the forward-compatibility profile you want to use is actually supported by your card? What does glGetString(GL_VERSION) actually return?

VAO and VBO are not exactly the same thing. A VAO can hold a number of VBOs within it, and provides the "state" that is used to interpret the data. So say you have a buffer object that holds vertex data, one that holds normal data, one that holds texture coord data, and one that holds index data. You would wrap all of these individual buffers up into a single vertex array object, bind that VAO and draw elements.
Vertex Arrays store vertex data on the cpu side
VBO stores the data on the gpu be it vertex data or index data.
VAO stores the attributes that define the data in VBO's

Vertex arrays basically made the cpu transfer vertex/index data and attributes (gl*Pointer) every loop to the gpu. If the vertex data doesnt change or only parts then that data could be stored once and updated as needed. Thats where VBO's came in. VAO are actually new to me as Ive been working in the GLES versions. But it looks like a nice thing, with either GLES 1.X/2.0 the attributes have to be specified every time a vertex array or vbo is used.
It also seems with 2.0/3.0 the directions have been to buffer/store as much data one time on the gpu side with minimal changes as needed.
Thanks for all the links!

I have decided to use VAO's now, because I am trying to limit my usage of deprecated OpenGL 3.1 functions.

However I still can't get this to draw without using an Element Array Buffer.

So basically the problem is, currently I have to use an element list.
However all the vertices will be unique. Meaning I'm just sending a list of unique numbers which is a waste. ex: 0,1,2,3
So I need to know how to draw the Verticies set by glVertexAttribPointer() without using an element list.
I will be drawing all of them and once I get to the point of alomost 20,000 verts I dont want to have a list going from 0 to 19,999.
There has to be a way to do this.

Thanks again!
CoderWalker


void render()
{
glUseProgram(resources.program);
glUniform1f(resources.uniforms.fade_factor, resources.fade_factor);

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, resources.textures[0]);
glUniform1i(resources.uniforms.textures[0], 0);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, resources.textures[1]);
glUniform1i(resources.uniforms.textures[1], 1);

/*glBindBuffer(GL_ARRAY_BUFFER, resources.vBuffer);
glVertexPointer( 3, GL_FLOAT, sizeof(GLfloat)*3, (char *) NULL );
glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 ); */

glBindBuffer(GL_ARRAY_BUFFER, resources.vBuffer);

// Specify that it's data is vertex data.
glVertexAttribPointer(
resources.attributes.position, // attribute //
3, // size //
GL_FLOAT, // type //
GL_FALSE, // normalized? //
sizeof(GLfloat)*3, // stride //
(void*)0 // array buffer offset //
);

//Everything below this I want to remove
glEnableVertexAttribArray(resources.attributes.position);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, resources.eBuffer);
glDrawElements(
GL_TRIANGLE_STRIP, // mode //
4, // count //
GL_UNSIGNED_SHORT, // type //
(void*)0 // element array buffer offset //
);
glDisableVertexAttribArray(resources.attributes.position);
//Everything above this I want to remove

SDL_GL_SwapBuffers();
}
If this post was helpful please +1 or like it !

Webstrand
If all vertices are different than you can use glDrawArrays

This topic is closed to new replies.

Advertisement