• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Alessandro

Clarification about GL_LINE_STRIP and Vertex Arrays

10 posts in this topic

I need to render a bunch of GL_LINE_STRIP primitives and the render function looks like this:

[code]
glPushMatrix();
glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer(3, GL_FLOAT, 0, verts);
glDrawElements( GL_LINE_STRIP, numIndices, GL_UNSIGNED_INT, indices );
glDisableClientState( GL_VERTEX_ARRAY );
glPopMatrix();
[/code]

I already packed the verts array, and I'm a bit confused about the indices assignment.

The number of indices is actually equal to ([b]number of line strips[/b]), or to the ([b]number of line strips[/b] [b]*[/b] [b]number of line segments[/b]) ?
0

Share this post


Link to post
Share on other sites
The number of indices is just what it says; the number of indices to draw. If you have an index array that contains four indices that makes up your line strip, then the parameter is four. The parameter has exactly the same meaning for any type of primitive you can draw.
1

Share this post


Link to post
Share on other sites
Say you have [i][b]N[/b][/i] line strips, each with [b][i]V[/i][/b] number of vertices.

The number of indices should be [b][i]N*V[/i][/b] (since a line strip draws a connected group of line segments from the first vertex to the last), correct?

[s]But how glDrawElements understand where a line strip ends and a new one begins?[/s]

I think I found out that I can't call a unique glDrawElements to draw all the line strips at once. I will have to use glMultiDrawElements.

Here is an example I found:

[code]
static GLubyte oneIndices[] = {0, 1, 2, 3, 4, 5, 6};
static GLubyte twoIndices[] = {7, 1, 8, 9, 10, 11};
static GLsizei count[] = {7, 6};
static GLvoid * indices[2] = {oneIndices, twoIndices};
glMultiDrawElements(GL_LINE_STRIP, count, GL_UNSIGNED_BYTE,indices, 2);
[/code]

I wonder how I'd define the indices[] array in case I have one global array of indices, since the element count it's always the same (in the example they use two separate indices and they have a different number of elements).
0

Share this post


Link to post
Share on other sites
You just put pointers to the parts of the global index array you want to draw from in the [i]indices[/i] array instead of pointers to two different arrays.
[source]
static GLvoid *indices[] = {globalindices, globalindices+10, globalindices+42};
[/source]
2

Share this post


Link to post
Share on other sites
Thanks Bob, will try that. I was just playing (that's the correct term) with glDrawRangeElements: obviously this stuff is rocket science for me.

The following call correctly draw 6 points:

[code]
glDrawRangeElements( GL_POINTS, 0, 5, 6, GL_UNSIGNED_INT, indices );
[/code]

Now, (newbie thought) that is supposed to be equivalent:
[code]
glDrawRangeElements( GL_POINTS, 0, 2, 3, GL_UNSIGNED_INT, indices );
glDrawRangeElements( GL_POINTS, 3, 5, 3, GL_UNSIGNED_INT, indices );
[/code]

I mean, I just make two "partial" calls, correctly passing the proper indicies. Instead, to my surprise, [b]glDrawRangeElements( GL_POINTS, 3, 5, 3, GL_UNSIGNED_INT, indices ); [/b]it just matches with the [b]glDrawRangeElements( GL_POINTS, 0, 2, 3, GL_UNSIGNED_INT, indices );[/b] Only the first 3 points are drawn...

How is that possible, since I specified different indicies? [img]http://public.gamedev.net//public/style_emoticons/default/wacko.png[/img] [img]http://public.gamedev.net//public/style_emoticons/default/blink.png[/img] [img]http://public.gamedev.net//public/style_emoticons/default/huh.png[/img]
0

Share this post


Link to post
Share on other sites
If you want the third line to draw the second half, then you have to point the index array to the second half as well.
[source]
glDrawRangeElements( GL_POINTS, 3, 5, 3, GL_UNSIGNED_INT, indices+3 )
[/source]
Otherwise you're drawing the same thee vertices twice.

The pointer and the number of indices to draw exclusively determine what values to read from the index array. The range-parameters are not what sub-part of the index array to draw, but what values OpenGL can expect when reading the index array. In the third call, 3 and 5 does not mean "draw between indices 3 and 5", it means "when reading index values pointed to by the pointer, the index values are expected to be between 3 and 5".
1

Share this post


Link to post
Share on other sites
Bob thank you for the explanation, I now understood what I was doing wrong. glDrawRangeElements now works fine in my application, and they are much faster than glDrawArrays and also glDrawElements. Tomorrow I'll try to use glDrawRangeElements with VBO's: shouldn't be too difficult now that arrays are setup properly.

About the glMultiDrawElements, I was wondering if there is a way to actually assign indices dinamically, so that instead of

[code]
static GLvoid *indices[] = {globalindices, globalindices+10, globalindices+42};
[/code]

one could do something like this:
[code]
static GLvoid **indices;
indices[0]=globalIndices;
indices[1]=globalIndices+10;
indices[2]=globalIndices+20;
[/code]

Thanks again for the precious help and patience. My mind is more oriented to arts and painting, but mathematics and 3D graphics, even if I'm such a rookie at those, they do fascinate me (and scare sometimes [img]http://public.gamedev.net//public/style_emoticons/default/unsure.png[/img] [img]http://public.gamedev.net//public/style_emoticons/default/rolleyes.gif[/img] [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] ) ...
0

Share this post


Link to post
Share on other sites
Use a dynamic container.
[source]
std::vector<void *> indices;

indices.push_back(globalindices);
...
[/source]
Then pass a pointer to the first element to OpenGL:
[source]
glMultiDrawElements(... , &indices[0], indices.size());
[/source]
1

Share this post


Link to post
Share on other sites
Ok, here is the working code I came up thanks to Bob hints, which renders a bunch of GL_LINE_STRIP primitives using glMultiDrawElements. Maybe someone can find it useful...

[code]
// declare stuff
unsigned int *indices; // this array holds all the line strips indices
vector3_t *verts; // this array holds all the line strips vertices
int *globalIndexCount;
std::vector<void *> globalIndices; // this is a pointer to the *indices above

void setup()
{
/* ... fill verts and indices with data ... */

globalIndexCount=new int[NUM_OF_STRIPS];
for (int i=0; i<NUM_OF_STRIPS; i++)
{
globalIndexCount[i]=POINTS_PER_STRIP; // store number of points for a line strip
globalIndices.push_back(indices+i*POINTS_PER_STRIP); // store the reference to a indices data set
}
}

void render()
{
glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer(3, GL_FLOAT, 0, verts);
glPushMatrix();
glMultiDrawElements(GL_LINE_STRIP, globalIndexCount, GL_UNSIGNED_INT, (const void **) &globalIndices[0], globalIndices.size() );
glPopMatrix();
glDisableClientState( GL_VERTEX_ARRAY );
}



[/code]
0

Share this post


Link to post
Share on other sites
Hey, not finished yet: how about glMultiDrawElements + VBO's? [img]http://public.gamedev.net//public/style_emoticons/default/rolleyes.gif[/img]

I think I've setup correctly the buffers, but I can't figure out how the [b]glMultiDrawElements [/b]render call should look like:

[code]
void initGL()
{
...
glGenBuffersARB(1, &vboId);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboId);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, fullHairCounter*HAIRPOINTS*sizeof(vector3_t), verts, GL_DYNAMIC_DRAW_ARB);
glGenBuffersARB(1, &iboId);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, iboId);
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, numIndices*sizeof(unsigned int), indices, GL_DYNAMIC_DRAW_ARB);
...
}

void setupVBO()
{
...
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboId);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, fullHairCounter*HAIRPOINTS*sizeof(vector3_t), verts, GL_DYNAMIC_DRAW_ARB);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, iboId);
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, globalIndices.size() *sizeof(unsigned int), (const void **) &globalIndices[0], GL_DYNAMIC_DRAW_ARB);
...
}

void renderVBO()
{
glPushMatrix();
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboId);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, iboId);
glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer(3, GL_FLOAT, 0, 0);
glMultiDrawElements(GL_LINE_STRIP, globalIndexCount, GL_UNSIGNED_INT, 0, globalIndices.size() ); // this is clearly wrong: I don't understand how to reference data to be passed to the glMultiDrawElements...
glDisableClientState( GL_VERTEX_ARRAY );
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
glPopMatrix();
}

[/code]
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0