why the GUI so slow on win32 opengl

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

umen
Not too shy to talk
Not too shy to talk
Posts: 26
Joined: Mon Sep 12, 2011 08:24

why the GUI so slow on win32 opengl

Postby umen » Wed Sep 14, 2011 13:10

Hi
sorry for cross posting , i post this question on begginers section but without lock. so i will ask here .
im doing simple opengl win32 without any glut tester , but it become very slow when i
set

Code: Select all

CEGUI::System::getSingleton().renderGUI();
in the main look .
can please someone take allok in the code and can tell me what im doing wrong here :
thanks

Code: Select all

#include <windows.h>
#include <gl/gl.h>
#include <CEGUI.h>
#include <RendererModules/OpenGL/CEGUIOpenGLRenderer.h>
#define PATH_MAX 256
#define CEGUI_DATAPATH "D:/cpp/3d/opengl_gui/glsample/Debug/CEGUIRes"
 
// Function Declarations

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC);
void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC);
 
// WinMain
// Win32 MessageProc callback
bool d_mouseInWindow = false;
CEGUI::OpenGLRenderer* d_renderer;
CEGUI::GeometryBuffer* d_fps_geometry;

char *getDataPathPrefix()
{
   static char dataPathPrefix[PATH_MAX];
   strcpy(dataPathPrefix,CEGUI_DATAPATH);
   return dataPathPrefix;
}

void mouseEnters()
{
    if (!d_mouseInWindow)
    {
        d_mouseInWindow = true;
        ShowCursor(false);
    }
}

void mouseLeaves()
{
    if (d_mouseInWindow)
    {
        d_mouseInWindow = false;
        ShowCursor(true);
    }
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
               LPSTR lpCmdLine, int iCmdShow)
{
   
    using namespace CEGUI;
   int numSec = 100;            // number of strip sections
   int width  = 556, height = 556;
    int bpp, flags;
    int TWquit = 0;
   
    int n, numCubes = 30;
    float color0[] = { 1.0f, 0.5f, 0.0f };
    float color1[] = { 0.5f, 1.0f, 0.0f };
    float color[] = { 1, 0, 0 }; // strip color
    double ka = 5.3, kb = 1.7, kc = 4.1;
   
   WNDCLASS wc;
   HWND hWnd;
   HDC hDC;
   HGLRC hRC;
   MSG msg;
   BOOL quit = FALSE;
   float theta = 0.0f;
   
   // register window class
   wc.style = CS_OWNDC;
   wc.lpfnWndProc = WndProc;
   wc.cbClsExtra = 0;
   wc.cbWndExtra = 0;
   wc.hInstance = hInstance;
   wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
   wc.hCursor = LoadCursor( NULL, IDC_ARROW );
   wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
   wc.lpszMenuName = NULL;
   wc.lpszClassName = "GLSample";
   RegisterClass( &wc );
   
   // create main window
   hWnd = CreateWindow(
      "GLSample", "OpenGL Sample",
      WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
      0, 0, width, height,
      NULL, NULL, hInstance, NULL );
   
   // enable OpenGL for the window
   EnableOpenGL( hWnd, &hDC, &hRC );
   d_renderer = &CEGUI::OpenGLRenderer::bootstrapSystem();
   // clearing this queue actually makes sure it's created(!)
    d_renderer->getDefaultRenderingRoot().clearGeometry(CEGUI::RQ_OVERLAY);
     CEGUI::DefaultResourceProvider *drp =
      static_cast<CEGUI::DefaultResourceProvider *>
      (CEGUI::System::getSingleton().getResourceProvider());
   
   char* dataPathPrefix = getDataPathPrefix();
    char resourcePath[PATH_MAX];
   
 
    // for each resource type, set a resource group directory
    sprintf(resourcePath, "%s/%s", dataPathPrefix, "schemes/");
    drp->setResourceGroupDirectory("schemes", resourcePath);
    sprintf(resourcePath, "%s/%s", dataPathPrefix, "imagesets/");
    drp->setResourceGroupDirectory("imagesets", resourcePath);
    sprintf(resourcePath, "%s/%s", dataPathPrefix, "fonts/");
    drp->setResourceGroupDirectory("fonts", resourcePath);
    sprintf(resourcePath, "%s/%s", dataPathPrefix, "layouts/");
    drp->setResourceGroupDirectory("layouts", resourcePath);
    sprintf(resourcePath, "%s/%s", dataPathPrefix, "looknfeel/");
    drp->setResourceGroupDirectory("looknfeels", resourcePath);
    sprintf(resourcePath, "%s/%s", dataPathPrefix, "lua_scripts/");
    drp->setResourceGroupDirectory("lua_scripts", resourcePath);
    sprintf(resourcePath, "%s/%s", dataPathPrefix, "xml_schemas/");
    drp->setResourceGroupDirectory("schemas", resourcePath);

    // set the default resource groups to be used
    CEGUI::Imageset::setDefaultResourceGroup("imagesets");
    CEGUI::Font::setDefaultResourceGroup("fonts");
    CEGUI::Scheme::setDefaultResourceGroup("schemes");
    CEGUI::WidgetLookManager::setDefaultResourceGroup("looknfeels");
    CEGUI::WindowManager::setDefaultResourceGroup("layouts");
    CEGUI::ScriptModule::setDefaultResourceGroup("lua_scripts");
   
    // setup default group for validation schemas
    CEGUI::XMLParser* parser = CEGUI::System::getSingleton().getXMLParser();
    if (parser->isPropertyPresent("SchemaDefaultResourceGroup"))
        parser->setProperty("SchemaDefaultResourceGroup", "schemas"); 

 
    CEGUI::WindowManager &winMgr = CEGUI::WindowManager::getSingleton();
     SchemeManager::getSingleton().create("TaharezLook.scheme");
   System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
    DefaultWindow* root = (DefaultWindow*)winMgr.createWindow("DefaultWindow", "Root");
   System::getSingleton().setGUISheet(root);
   FrameWindow* wnd = (FrameWindow*)winMgr.createWindow("TaharezLook/FrameWindow", "Demo Window");
   root->addChildWindow(wnd);
   wnd->setPosition(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.25f)));
   wnd->setSize(UVector2(cegui_reldim(0.5f), cegui_reldim( 0.5f)));
   wnd->setMaxSize(UVector2(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
   wnd->setMinSize(UVector2(cegui_reldim(0.1f), cegui_reldim( 0.1f)));
   wnd->setText("Hello World!");
   
   
   
   // program main loop
   while ( !quit )
   {
      
      // check for messages
      if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE )  )
      {
         
         // handle or dispatch messages
         if ( msg.message == WM_QUIT )
         {
            quit = TRUE;
         }
         else
         {
            TranslateMessage( &msg );
            DispatchMessage( &msg );
         }
         
      }
      else
      {
         
         // OpenGL animation code goes here
         
         glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
         glClear( GL_COLOR_BUFFER_BIT );
         
         glPushMatrix();
         glRotatef( theta, 0.0f, 0.0f, 1.0f );
         glBegin( GL_TRIANGLES );
         glColor3f( 1.0f, 0.0f, 0.0f ); glVertex2f( 0.0f, 1.0f );
         glColor3f( 0.0f, 1.0f, 0.0f ); glVertex2f( 0.87f, -0.5f );
         glColor3f( 0.0f, 0.0f, 1.0f ); glVertex2f( -0.87f, -0.5f );
         glEnd();
         glPopMatrix();
          
         CEGUI::System::getSingleton().renderGUI();
         SwapBuffers( hDC );
         
         theta += 1.0f;
         
      }
      
   }
   
   // shutdown OpenGL
   DisableOpenGL( hWnd, hDC, hRC );
   
   // destroy the window explicitly
   DestroyWindow( hWnd );
   
   return msg.wParam;
   
}

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: why the GUI so slow on win32 opengl

Postby Kulik » Wed Sep 14, 2011 15:48

Don't cross post! Being sorry doesn't help. Also it's been barely a day...

viewtopic.php?f=10&t=5825


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 6 guests