I’m doing a 3D display for a big object.
I’ve managed to display it with opengl primitives, so it’s (very) slow
Now i want to use the VBO optimization.
But when i lost the focus on the opengl window (even without hiding it), the display driver is blocked for some seconds (enough to shutdown my screens).
Could you help me.
Thanks.
The code is below
Flow
-> Code to load the object in VBO buffer
currentwindows = new Windows3D();
toquit = false;
Gl.glGenBuffers(1, out VBOObject.VBOid);
Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, VBOObject.VBOid);
Gl.glVertexPointer(3, Gl.GL_FLOAT, 0, null);
Gl.glBufferData(Gl.GL_ARRAY_BUFFER, (IntPtr)(VBOObject.count * 3 * sizeof(float)), VBOObject.xyz, Gl.GL_STATIC_DRAW);
Gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
Gl.glHint(Gl.GL_PERSPECTIVE_CORRECTION_HINT, Gl.GL_NICEST); // Set Perspective Calculations To Most Accurate
Gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); // Set The Color To White
while (!toquit)
{
DrawGLScene();// Loop That Runs While done = false
Gdi.SwapBuffers(hDC);
Application.DoEvents();
// Process Events
}
Gl.glDeleteBuffers(1,ref VBOObject.VBOid);
Application.Exit();
return;
-> Display method.
private void DrawGLScene()
{
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
Gl.glLoadIdentity();
Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
Glu.gluLookAt(212, 60, 194, 186, 55, 171, 0, 1, 0); // This Determines Where The Camera's Position And View Is
Gl.glTranslatef(-ycentre, -xcentre, -zcentre);
Gl.glBindBuffer(Gl.GL_ARRAY_BUFFER, VBOObject.VBOid);
Gl.glVertexAttribPointer(0, 3, Gl.GL_FLOAT, Gl.GL_FALSE, 3 * sizeof(float), null);
Gl.glEnableVertexAttribArray(0);
Gl.glBindBuffer(Gl.GL_ELEMENT_ARRAY_BUFFER, 0);
Gl.glDrawArrays(Gl.GL_QUADS, 0, VBOObject.count);
Gl.glDisableVertexAttribArray(0);
Gl.glDisableClientState(Gl.GL_VERTEX_ARRAY);
}