I am using a .net implementation of the arc ball code to display a number of co joined spheres together in a box. Each sphere which makes one shape is specifed by an element in an array which is read from text file.
The code runs fine but I find that rotating the box around is tremendously slow. In this case I am reading in say 100 shapes - each of 3 spheres. I am reading in the information from a text file when the int WINAPI WinMain function is called. and passing these parameters to the Draw function. I find this is very slow and I dont understand exactly why? I should be passing all the variables by reference each time Draw is called hence minimum overhead.
I would use Display lists but all information is in the array.
Am I doing something very silly here?
Below is a snippet of the code:
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
Application application; // Application Structure
GL_Window window; // Window Structure
Keys keys; // Key Structure
BOOL isMessagePumpActive; // Message Pump Active?
MSG msg; // Window Message Structure
DWORD tickCount; // Used For The Tick Counter
// Fill Out Application Data
application.className = "OpenGL"; // Application Class Name
application.hInstance = hInstance; // Application Instance
// Fill Out Window
ZeroMemory (&window, sizeof (GL_Window)); // Make Sure Memory Is Zeroed
window.keys = &keys; // Window Key Structure
window.init.application = &application; // Window Application
window.init.title = "Lipid Modelling in Open GL";
window.init.width = 800; // Window Width
window.init.height = 600; // Window Height
window.init.bitsPerPixel = 32; // Bits Per Pixel
window.init.isFullScreen = TRUE; // Fullscreen? (Set To TRUE)
readmyfile(arr_lipids, N, mybeforefile);
readmyfile(arr_lipids2, N, myafterfile);
Normalise(arr_lipids,N,Xbox,Ybox,Zbox,scalefactor);
Normalise(arr_lipids2,N,Xbox,Ybox,Zbox,scalefactor);
ZeroMemory (&keys, sizeof (Keys)); // Zero keys Structure
// Ask The User If They Want To Start In FullScreen Mode?
if (MessageBox (HWND_DESKTOP, "Would You Like To Run In Fullscreen Mode?", "Start FullScreen?", MB_YESNO | MB_ICONQUESTION) == IDNO)
{
window.init.isFullScreen = FALSE; // If Not, Run In Windowed Mode
}
// Register A Class For Our Window To Use
if (RegisterWindowClass (&application) == FALSE) // Did Registering A Class Fail?
{
// Failure
MessageBox (HWND_DESKTOP, "Error Registering Window Class!", "Error", MB_OK | MB_ICONEXCLAMATION);
return -1; // Terminate Application
}
g_isProgramLooping = TRUE; // Program Looping Is Set To TRUE
g_createFullScreen = window.init.isFullScreen; // g_createFullScreen Is Set To User Default
while (g_isProgramLooping) // Loop Until WM_QUIT Is Received
{
// Create A Window
window.init.isFullScreen = g_createFullScreen; // Set Init Param Of Window Creation To Fullscreen?
if (CreateWindowGL (&window) == TRUE) // Was Window Creation Successful?
{
// At This Point We Should Have A Window That Is Setup To Render OpenGL
if (Initialize (&window, &keys, sigma, Xbox, N, scalefactor, arr_lipids, arr_lipids2) == FALSE) // Call User Intialization
{
// Failure
TerminateApplication (&window); // Close Window, This Will Handle The Shutdown
}
else // Otherwise (Start The Message Pump)
{ // Initialize was a success
isMessagePumpActive = TRUE; // Set isMessagePumpActive To TRUE
while (isMessagePumpActive == TRUE) // While The Message Pump Is Active
{
// Success Creating Window. Check For Window Messages
if (PeekMessage (&msg, window.hWnd, 0, 0, PM_REMOVE) != 0)
{
// Check For WM_QUIT Message
if (msg.message != WM_QUIT) // Is The Message A WM_QUIT Message?
{
DispatchMessage (&msg); // If Not, Dispatch The Message
}
else // Otherwise (If Message Is WM_QUIT)
{
isMessagePumpActive = FALSE; // Terminate The Message Pump
}
}
else // If There Are No Messages
{
if (window.isVisible == FALSE) // If Window Is Not Visible
{
WaitMessage (); // Application Is Minimized Wait For A Message
}
else // If Window Is Visible
{
// Process Application Loop
tickCount = GetTickCount (); // Get The Tick Count
Update (tickCount - window.lastTickCount); // Update The Counter
window.lastTickCount = tickCount; // Set Last Count To Current Count
Draw (N,sigma,scalefactor,arr_lipids,arr_lipids2, Xbox); // Draw Our Scene
SwapBuffers (window.hDC); // Swap Buffers (Double Buffering)
}
}
} // Loop While isMessagePumpActive == TRUE
}