开发者

OpenGL: Materials with Display Lists?

I am using JOGL with OpenGL. I'm drawing everything through开发者_如何转开发 display lists. I'm trying to figure out how to specify materials.

I've been looking at this documentation. The following looks pretty straightforward:

glPushMatrix();
    glTranslatef (-1.25, 3.0, 0.0);
    glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess);
    glMaterialfv(GL_FRONT, GL_EMISSION, no_mat);
    auxSolidSphere();
glPopMatrix();

How can I do this with display lists? Without them, my app is way too slow.


Put the glMaterial calls into your display list.

int displayList = glGenLists(1);
glNewList(displayList, GL_COMPILE);
FloatBuffer ambient = BufferUtils.createFloatBuffer(4);
ambient.put(1.0f); // red
ambient.put(0.0f); // green
ambient.put(0.5f); // blue
ambient.put(1.0f); // alpha
ambient.flip(); // now OpenGL can read the buffer
glMaterial(GL_FRONT, GL_AMBIENT, ambient);
// put other material properties here
// put glVertex/glColor calls here
glEndList();


First, you should realize that, depending on your hardware, there's no guarantee that using a display list will make even a slight difference in speed. The currently-favored solution would be to use a vertex buffer object instead.

As far as doing it with a display list goes, it's pretty straightforward. You basically just do your drawing to the display list, then when you want to display something you tell it to play the display list with glCallList. There are some operations you can't put into a display list, but at least if memory serves (though it may not -- I haven't used lists in a while now) you can put glMaterialfv into a display list just fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜