PDA

View Full Version : VBOs and material properties



gmseed
11-14-2011, 12:43 PM
Hi

Can material properties [ambient properties, etc] be used in conjunction with VBOs? And if so, what is the best approach and does anyone know of some good tutorials?

I've checked the red-book but couldn't find anything about mixing VBOs and material properties.

Thanks.

Graham

Alfonse Reinheart
11-14-2011, 02:03 PM
I've checked the red-book but couldn't find anything about mixing VBOs and material properties.

And why would you? What do buffer objects have to do with fixed-function material properties? The two concepts have nothing to do with one another.

It's like asking if you can use textures with buffer objects. Only it makes less sense, because at least there, fixed-function texturing usually relies on texture coordinates taken from vertex attributes.

In short, there is no interaction between fixed-function lighting and using buffer objects.

lorant
11-14-2011, 10:25 PM
gmseed, the equivalent of material properties in a modern opengl approach (i.e. one where you do everything via VBOs), is to write your own vertex and fragment shaders.

VBOs can contain any kind of data, so you can put "material properties" in them, but since you are using your own lighting algorithm, they are not the material properties defined by opengl. From the API point of view, they are just data, it's your code that will decide that such VBO (or part of it) represent ambient/diffuse/specular/... components. Depending on the lighting algorithm used, you will need different data.

Unfortunately, last time I checked there was very few tutorials for non-fixed function OpenGL coding. One that seems very good is here:

http://www.arcsynthesis.org/gltut/index.html

There's a part on lighting.

remdul
11-15-2011, 03:07 AM
This thread may be relevant: http://www.opengl.org/discussion_boards/...6059#Post306059 (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Main=58958&Number=3060 59#Post306059)

V-man
11-15-2011, 05:59 AM
I guess you are asking if you can use glMaterial. Yes you can. BTW, there are many ways to send vertices to the graphics cards and non of them state that you can't use some particular function.

The best approach? I guess the best approach is to call glMaterial before rendering your geometry.

For VBO specific info,
http://www.opengl.org/wiki/Vertex_Buffer_Object
http://www.opengl.org/wiki/VBO_-_more
http://www.opengl.org/wiki/VBO_-_just_examples

no, you will not find any calls for glMaterial.

tksuoran
11-24-2011, 03:27 AM
With the legacy fixed function pipeline it is possible to control some material properties per vertex from the VBO. Enable GL_COLOR_MATERIAL and use glColorMaterial() to choose which material property to control.

All of that is deprecated of course.

V-man
11-27-2011, 01:22 AM
You can also have a per vertex material ambient, emission, diffuse, specular and shininess with shaders, which means you have more control with shaders. With fixed function, you can only control one of the properties per vertex.

gmseed
12-02-2011, 08:56 AM
@Alfonso states: "there is no interaction between fixed-function lighting and using buffer objects".

As indicated with other posts, the following works:



glv.glColorMaterial( GL.GL_FRONT_AND_BACK, GL2.GL_AMBIENT_AND_DIFFUSE ); // call glColorMaterial before enabling GL_COLOR_MATERIAL
glv.glEnable( GL2.GL_COLOR_MATERIAL );


This allows VBOs [without shaders] to be used and existing material properties used.

Alfonse Reinheart
12-02-2011, 10:12 AM
This allows VBOs [without shaders] to be used and existing material properties used.

And it would work just as well if you were using client-side vertex arrays instead of buffer objects. My point is that the use of buffer objects to supply vertex arrays (aka: VBO) has nothing to do with how lighting works.