-1
\$\begingroup\$

I'm creating a 3D display for a big object. I've managed to display it with OpenGL primitives, but it is very slow. I am using C#, powered by the TAO Framework.

I want to use the Vertex Buffer Object (VBO) optimization, but when I lose focus on the OpenGL window (even without hiding it), the display driver is blocked for some seconds; enough to shutdown my screens.

How do I fix this?


This is the code to load the object in to a VBO buffer:

void LoadVBO()
{
    Gl.glGenBuffersARB(1, out VBOObject.VBOid);
    Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER, VBOObject.count);

    Gl.glBufferDataARB(Gl.GL_ARRAY_BUFFER_ARB, 
        (IntPtr)(VBOObject.count * 3 * sizeof(float)), VBOObject.xyz, 
        Gl.GL_STATIC_DRAW_ARB);
}

The working code:

Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
LoadVBO();

// Black Background
Gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
// Depth Buffer Setup
Gl.glClearDepth(1.0f);
// The Type Of Depth Testing (Less Or Equal)
Gl.glDepthFunc(Gl.GL_LEQUAL);
// Enable Depth Testing
Gl.glEnable(Gl.GL_DEPTH_TEST);
// Select Smooth Shading
Gl.glShadeModel(Gl.GL_SMOOTH);
// Set Perspective Calculations To Most Accurate
Gl.glHint(Gl.GL_PERSPECTIVE_CORRECTION_HINT, Gl.GL_NICEST);
// Enable Textures
Gl.glEnable(Gl.GL_TEXTURE_2D);
// Set The Color To White
Gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, VBOObject.count);
Gl.glVertexPointer(3, Gl.GL_FLOAT, 0, null);

while (!toquit)
{
    // Loop That Runs While done = false
    DrawGLScene();
    // Process Events
    Application.DoEvents();
    bool res = Gdi.SwapBuffers(hDC);
}

Gl.glDisableClientState(Gl.GL_VERTEX_ARRAY);

The display method:

 private void DrawGLScene()
    {
        Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
        Gl.glLoadIdentity();

        Glu.gluLookAt(212, 60, 194, 186, 55, 171, 0, 1, 0); 

        Gl.glRotatef(xv, 1f, 0f, 0f);
        Gl.glRotatef(yv, 0f, 1f, 0f);
        Gl.glRotatef(zv, 0f, 0f, 1f);

        Gl.glDrawArrays(Gl.GL_LINES, 0, VBOObject.count);
    }
\$\endgroup\$
  • 1
    \$\begingroup\$ Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, VBOObject.count); should be Gl.glBindBufferARB(Gl.GL_ARRAY_BUFFER_ARB, VBOObject.VBOid); \$\endgroup\$ – ratchet freak Feb 5 '16 at 10:50
  • \$\begingroup\$ @ratchetfreak You beat me by 20 seconds. (should have been posted as an answer, though!) \$\endgroup\$ – Trevor Powell Feb 5 '16 at 10:51
0
\$\begingroup\$

yeah, thank you, But still the problem. ...

here, my code: https://drive.google.com/open?id=0B_j9kxE7xxc2S0RaQkx1Ty1waVE

the "Tableau X.txt", "Tableau Y.txt" and "Tableau Z.txt" contains the x, y,z datas for each profiles.

\$\endgroup\$
0
\$\begingroup\$

So, I've done some code updates.

I've tested the TaoFrameWork test program for VBO (essai.cs). this one works.

next I wanted to adapt it to my case. But nothing is displayed (display.cs).

I've tried to center my object, to change the scale, but nothing.....

Here, the link to the source files.

http://www.developpez.net/forums/d1567177/applications/developpement-2d-3d-jeux/api-graphiques/opengl/csharp-taoframework-utilisation-vbo/

Thank you.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.