我有一段時間,我讀過有關VBO,這就是我的了:許多四邊形,沒有充足的FPS儘管VBO
http://img64.imageshack.us/img64/5733/fps8.jpg
好吧,這是比以前好多了。它在Release上編譯。我使用VBO(可能,如果everthing的確定)和glDrawArrays繪製。
這是繪圖代碼。請給我建議如何優化它。我想要與地形...呃幾千FPS,是真的嗎?
void DrawVBO (void)
{
int i;
CVert* m_pVertices;
CTexCoord* m_pTexCoords;
unsigned int m_nTextureId;
m_pVertices = NULL;
m_pTexCoords = NULL;
m_nVertexCount = 0;
m_nVBOVertices = m_nVBOTexCoords = m_nTextureId = 0;
if(IsExtensionSupported("GL_ARB_vertex_buffer_object"))
{
// Pobierz wskaźniki na funkcje OpenGL
glGenBuffersARB = (PFNGLGENBUFFERSARBPROC) wglGetProcAddress("glGenBuffersARB");
glBindBufferARB = (PFNGLBINDBUFFERARBPROC) wglGetProcAddress("glBindBufferARB");
glBufferDataARB = (PFNGLBUFFERDATAARBPROC) wglGetProcAddress("glBufferDataARB");
glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)
wglGetProcAddress("glDeleteBuffersARB");
}
todrawquads=0;
nIndex=0;
// my function counting how many quads I will draw
for (i=0;i<MAX_CHUNKS_LOADED;i++)
{
if (chunks_loaded[i].created==1)
{
countquads(i);
}
}
m_nVertexCount=4*todrawquads;
m_pVertices = new CVec[m_nVertexCount];
m_pTexCoords = new CTexCoord[m_nVertexCount];
// another my function adding every quad which i'm going to draw (its verticles) to array
for (i=0;i<MAX_CHUNKS_LOADED;i++)
{
if (chunks_loaded[i].created==1)
{
addchunktodraw(i,m_pVertices,m_pTexCoords);
}
}
glClearColor (1,1,1, 0.0);
glColor3f(1,1,1);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Modelview Matrix
fps++;
// Camera settings.
//gluLookAt (zom, zom, zom, 0.0, 0.0, 0.0, 0, 0, 1);
gluLookAt (zoom, zoom, zoom, 0.0, 0.0, 0.0, 0, 0, 1);
glRotatef((rot_x/180 * 3.141592654f),1,0,0);
glRotatef((rot_y/180 * 3.141592654f),0,1,0);
glRotatef((rot_z/180 * 3.141592654f),0,0,1);
//m_nTextureId = t_terrain;
// Generate And Bind The Vertex Buffer
glGenBuffersARB(1, &m_nVBOVertices); // Get A Valid Name
glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_nVBOVertices); // Bind The Buffer
// Load The Data
glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_nVertexCount*3*sizeof(float), m_pVertices, GL_STATIC_DRAW_ARB);
// Generate And Bind The Texture Coordinate Buffer
glGenBuffersARB(1, &m_nVBOTexCoords); // Get A Valid Name
glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_nVBOTexCoords); // Bind The Buffer
// Load The Data
glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_nVertexCount*2*sizeof(float), m_pTexCoords, GL_STATIC_DRAW_ARB);
// Enable Pointers
glEnableClientState(GL_VERTEX_ARRAY); // Enable Vertex Arrays
glEnableClientState(GL_TEXTURE_COORD_ARRAY); // Enable Texture Coord Arrays
glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_nVBOVertices);
glVertexPointer(3, GL_FLOAT, 0, (char *) NULL); // Set The Vertex Pointer To The Vertex Buffer
glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_nVBOTexCoords);
glTexCoordPointer(2, GL_FLOAT, 0, (char *) NULL); // Set The TexCoord Pointer To The TexCoord Buffe
glDrawArrays(GL_QUADS, 0, m_nVertexCount); // Draw All Of The Triangles At Once
glDisableClientState(GL_VERTEX_ARRAY); // Disable Vertex Arrays
glDisableClientState(GL_TEXTURE_COORD_ARRAY); // Disable Texture Coord Arrays
liniergb();
glutSwapBuffers();
delete [] m_pVertices; m_pVertices = NULL;
delete [] m_pTexCoords; m_pTexCoords = NULL;
}
那麼我能用它做什麼? (上面的代碼正選賽功能)
編輯
我搬到這個:
if(IsExtensionSupported("GL_ARB_vertex_buffer_object"))
{
// Pobierz wskaźniki na funkcje OpenGL
glGenBuffersARB = (PFNGLGENBUFFERSARBPROC) wglGetProcAddress("glGenBuffersARB");
glBindBufferARB = (PFNGLBINDBUFFERARBPROC) wglGetProcAddress("glBindBufferARB");
glBufferDataARB = (PFNGLBUFFERDATAARBPROC) wglGetProcAddress("glBufferDataARB");
glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)
wglGetProcAddress("glDeleteBuffersARB");
}
我的主要功能。可能沒有改善。
edit2
現在,我也可以看到它正在吃內存。每隔幾秒,程序內存使用量就會越來越多......出了什麼問題?我沒有刪除什麼?
edit3
好的,非常感謝sooooo。我已經移動了一些代碼以外的繪製功能和...更多的FPS! 非常感謝!
http://img197.imageshack.us/img197/5193/fpsfinal.jpg
這是640x640塊(40,從而更大的次)映射與650'000四邊形(約70倍以上),並仍然〜170幀。太好了!沒有內存泄漏。再次感謝 !
你想要「幾千FPS」?真? – 2011-06-13 13:18:02
您的渲染循環是否定時?是vsynch啓用? – 2011-06-13 13:18:27
嗯也許3000-6000 fps我不知道是否只有約9000四邊形。現在的電腦真的很多嗎?事實上,後面我想畫出比這更大的地形,但如果我知道我將有50fps,我就無法繼續前進。 – dj8000 2011-06-13 13:20:33