2010-09-25 61 views
2

我在OpenGL中使用JOGL。我正在通过显示列表绘制所有内容。我想弄清楚如何指定材料。OpenGL:带显示列表的材质?

我一直在看这个documentation。以下看起来非常简单:

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(); 

我该怎么做显示列表?没有他们,我的应用程序太慢了。

回答

0

首先,您应该意识到,根据您的硬件,不能保证使用显示列表会使速度的差异更小。目前有利的解决方案是使用顶点缓冲区对象。

就显示列表而言,它非常简单。您基本上只是将您的绘图显示到显示列表中,然后当您想要显示某些内容时,您会告诉它使用glCallList播放显示列表。有些操作不能放入显示列表中,但至少在内存服务的时候(尽管它可能不会 - 我现在有一段时间没有使用列表),您可以将glMaterialfv放入显示列表中。

1

glMaterial调用放到您的显示列表中。

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();