PDA

View Full Version : how do I use glDrawPrimitive ?



McZ
09-02-2001, 11:31 PM
Can anyone explane how to use glDrawPrimitive ?? or where I can find a tutorial about it http://www.opengl.org/discussion_boards/ubb/smile.gif

Thanks for your answer http://www.opengl.org/discussion_boards/ubb/smile.gif

DaViper
09-03-2001, 06:02 AM
hmmm never heard read oer saw anything about that. You sure it is existing?

DFrey
09-03-2001, 07:14 AM
Looks like someone had D3D on their mind as it does have a DrawPrimitive command. http://www.opengl.org/discussion_boards/ubb/tongue.gif

DaViper
09-03-2001, 07:34 AM
geee I should have known, that i have to learn something about 3D3 to answer and post questions in here http://www.opengl.org/discussion_boards/ubb/wink.gif http://www.opengl.org/discussion_boards/ubb/biggrin.gif



[This message has been edited by DaViper (edited 09-03-2001).]

McZ
09-03-2001, 11:25 PM
ops.. it should be glDrawElement http://www.opengl.org/discussion_boards/ubb/smile.gif

TerranFury
09-04-2001, 04:48 AM
You specify your vertex arrays as you normally would, but making sure that all are the same size. For example, if you are using color, texture coordinate, and vertex arrays, then the color specified at color array entry x will be applied to the vertex in vertex array slot x, and the texture coordinate will come from the 'x'th element of your texture coordinate array.

That much is simple.

Now you create another array, this one of an integer data type (usually GLuint). Each entry in it is an array index in your vertex, color, and texture arrays. So if your index array looks like this:




GLuint index[] = {0, 4, 1, 5, 2, 6, 3, 7, 4, 8, 5, 9, 6, 10, 7, 11};


Then it will draw the vertex in vertexarray[0] with texture coordinate of texcoord[0] and color of colorarry[0]. And then it'll do the same thing with, but with the array data at index 4 of each array, and then 1, and then 5, and so on.

You can also use interleaved arrays. They work the same way.

The advantage to using GLDrawElements is that each vertex is transformed once. So, as you saw in my example array of indices, I had several verteces referenced twice. But one of them would only need to be transformed once.

Hope that helps.

[This message has been edited by TerranFury (edited 09-04-2001).]

Randolph
09-05-2001, 12:03 PM
I can add also, that you should use glEnableClientState(xxxx) and then glXXXXPointer() functions if you wanna render primitive from separate arrays, or glInterleavedArrays() function if you wanna d3d-like non-strided primitive rendering.