ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Try changing GL_UNSIGNED_BYTE to GL_FLOAT, since test is a float array, not a unsigned char array.
Other than that, there are many other things that could cause it to not work, but seeing only that code segment won't help. Are you sure you have a GL context, etc?
Maybe it's because i have an old version of opengl because glMultiDrawElements(); doesn't work at all(gives compilation errors).
So i'il check if nvidia has released a new opengl version this month.
Hylke
Did you try changing that constant? Because that is one definite problem in the small code segment you posted.
Just off the top of my head I can think of a number of possible reasons it's not displaying anything.
OpenGL isn't initialized, thus no context to render to
You have your MODELVIEW and PROJECTION matrices setup wrong
It could be getting clipped by the front or back clipping plane
You are using double buffering but never flip the buffer
You have lighting enabled, but no light
Your color/material settings are set to the same as your background color
There are also many other reasons that you may not be seeing anything. You will have to give more details of your code to be able to determine the exact problem.
About glMultiDrawElements(), I think this is a relatively new method for OpenGL, though I can't tell you what version it was added in. You can check the OpenGL specs, and check the version of your OpenGL implementation with glGetString(GL_VERSION);
Originally posted by deiussum Did you try changing that constant? Because that is one definite problem in the small code segment you posted.
Just off the top of my head I can think of a number of possible reasons it's not displaying anything.
OpenGL isn't initialized, thus no context to render to
You have your MODELVIEW and PROJECTION matrices setup wrong
It could be getting clipped by the front or back clipping plane
You are using double buffering but never flip the buffer
You have lighting enabled, but no light
Your color/material settings are set to the same as your background color
There are also many other reasons that you may not be seeing anything. You will have to give more details of your code to be able to determine the exact problem.
About glMultiDrawElements(), I think this is a relatively new method for OpenGL, though I can't tell you what version it was added in. You can check the OpenGL specs, and check the version of your OpenGL implementation with glGetString(GL_VERSION);
neither of the things you came up with was wrong.
I thought glMultiDrawElements came with one of the latest versions.
b.t.w. i've just formatted my pc and forgot to back up my codes.So i'il make a new one and post it here.
Hylke
Ok. I see what the problem is. You are trying to use glDrawElements like glDrawArrays. (I get the 2 mixed up myself all the time too, and should have looked at the man pages first thing to see if that's what the problem was.)
You have 2 options.
1. Just use glDrawArrays like so:
glDrawArrays(GL_TRIANGLES, 0, 3);
2. Create an array of INDICES into your triangles array like so:
It could, but that last 3 in "indices" would never be used. What the indices are is in index into the vertex array. Index 0 indicates the first x elements of your float array. (x being 3 for your first example, 4 when you add a w component)
when you also enable things like texcoord arrays, normal arrays, etc. that index is also an index into that array.
What glDrawElements buys you, is that if you have a number of duplicate vertices, you only need the vertex in the array once, and can simply have multiple values in your index array.
the first triangle is drawn with vertices 0, 1, 2.
the second triangle is drawn with vertices 3, 1, 2, translated 1 unit to the right
Here's the code: (BTW, you also have to get rid of glShadeModel(GL_FLAT) to see the different colors, flat shading uses only thet color of one of the vertices for the face.
Code:
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
GLfloat triangle[] = { 0.5, 0.5, 0.0, // index 0
-0.5, 0.0, 0.0, // index 1
0.5, 0.0, 0.0, // index 2
-0.5, 0.5, 0.0 }; // index 3
GLfloat colors[] = { 1.0, 0.0, 0.0, // index 0
0.0, 1.0, 0.0, // index 1
0.0, 0.0, 1.0, // index 2
1.0, 1.0, 1.0 }; // index 3
unsigned int indices[] = {0, 1, 2};
unsigned int indices2[] = {3, 1, 2};
glVertexPointer(3 ,GL_FLOAT, 0, triangle);
glColorPointer(3, GL_FLOAT, 0, colors);
// Draw triangle 1 using set of indices
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices);
// Draw triangle 2 using set of indices2, moved to the right a bit
glPushMatrix();
glTranslatef(1.0, 0.0, 0.0);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices2);
glPopMatrix();
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glFlush();
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.