Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to reduce CPU uages with Opengl ?

How to reduce CPU uages with Opengl ?

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsgame-devtutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GAJERA
    wrote on last edited by
    #1

    Hi All I am using gluBuild2DMipmaps() for show live video buffer. but it is using the CPU around 50%. Please suggest how to reduce CPU usages. Here I am sending you the source code for render.

    for (int loop=0; loop<2; loop++) // Loop To Draw Our 4 Views
    {
    if (loop==0) // If We Are Drawing The First Scene
    {
    m_bRenderFromVideo=FALSE;
    if(m_pbVideoData)
    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, m_iVideoHeight,m_iVideoWidth ,GL_LUMINANCE, GL_UNSIGNED_BYTE, m_pbVideoData);

    		glViewport(m\_iNoOfColumn - m\_iNoOfColumn \* m\_iSizeVideo.x, m\_iNoOfRow - m\_iNoOfRow \* m\_iSizeVideo.y, 
    		m\_iNoOfColumn \* m\_iSizeVideo.x, m\_iNoOfRow \* m\_iSizeVideo.y);
    		glPushMatrix();
    
    		gluOrtho2D(-window\_width/4, window\_width/4, -window\_height/4, window\_height/4);
    		//glDrawPixels( window\_width/2,  window\_height/2, GL\_LUMINANCE,GL\_UNSIGNED\_BYTE, (void\*)m\_pbVideoData);
    		glLoadIdentity ();											// Reset The Projection Matrix
    
    		glDisable(GL\_TEXTURE\_GEN\_S);								// Enable Texture Coord Generation For S (NEW)
    		glDisable(GL\_TEXTURE\_GEN\_T);								// Enable Texture Coord Generation For T (NEW)
    
    		glDisable(GL\_LIGHTING);
    		glBegin(GL\_QUADS);											// Begin Drawing A Single Quad
    		// We Fill The Entire 1/4 Section With A Single Textured Quad.
    	
    		glTexCoord2f(1.0f, 1.0f); glVertex3f( 21.0f,  18.3f, -10.0f);
    		glTexCoord2f(0.0f, 1.0f); glVertex3f(-21.0f,  18.3f, -10.0f);
    		glTexCoord2f(0.0f, 0.0f); glVertex3f(-21.0f, -18.3f, -10.0f);
    		glTexCoord2f(1.0f, 0.0f); glVertex3f( 21.0f, -18.3f, -10.0f);
    		glEnd();	
    
    		glScalef(m\_fScale, m\_fScale, m\_fScale);
    		glRotated(m\_fRAngle\[0\],0.0, 0.0,1.0);
    		//glRotated(0,0.0,0.0, m\_fRAngle\[0\]);
    		//glRotated(0,0.0,0.0,m\_fRAngle\[0\]);	   
    
    		
    	}
    	else		
    	{
    		glPushMatrix();
    		glViewport(0, 0, window\_width, window\_height);
    		//float len = 28.0f;			
    		//glMatrixMode(GL\_PROJECTION);
    		glLoadIdentity();
    	//	glOrtho(-len, len, -len, len, -len\*100.0f, len\*100.0f);	
    	//	glMatrixMode(GL\_MODELVIEW);
    
    		glScalef(m\_fScale, m\_fScale, m\_fScale);
    		glRotated(m\_fRAngle\[0\],1.0, 0.0, 0.0);
    		glRotated(m\_fRAngle\[1\],0.0,1.0, 0.0);
    		glRotated(m\_fRAngle\[2\],0.0,0.0,1.0);	   
    
    
    	}
    	
    	
    }
    
    E C 2 Replies Last reply
    0
    • G GAJERA

      Hi All I am using gluBuild2DMipmaps() for show live video buffer. but it is using the CPU around 50%. Please suggest how to reduce CPU usages. Here I am sending you the source code for render.

      for (int loop=0; loop<2; loop++) // Loop To Draw Our 4 Views
      {
      if (loop==0) // If We Are Drawing The First Scene
      {
      m_bRenderFromVideo=FALSE;
      if(m_pbVideoData)
      gluBuild2DMipmaps(GL_TEXTURE_2D, 3, m_iVideoHeight,m_iVideoWidth ,GL_LUMINANCE, GL_UNSIGNED_BYTE, m_pbVideoData);

      		glViewport(m\_iNoOfColumn - m\_iNoOfColumn \* m\_iSizeVideo.x, m\_iNoOfRow - m\_iNoOfRow \* m\_iSizeVideo.y, 
      		m\_iNoOfColumn \* m\_iSizeVideo.x, m\_iNoOfRow \* m\_iSizeVideo.y);
      		glPushMatrix();
      
      		gluOrtho2D(-window\_width/4, window\_width/4, -window\_height/4, window\_height/4);
      		//glDrawPixels( window\_width/2,  window\_height/2, GL\_LUMINANCE,GL\_UNSIGNED\_BYTE, (void\*)m\_pbVideoData);
      		glLoadIdentity ();											// Reset The Projection Matrix
      
      		glDisable(GL\_TEXTURE\_GEN\_S);								// Enable Texture Coord Generation For S (NEW)
      		glDisable(GL\_TEXTURE\_GEN\_T);								// Enable Texture Coord Generation For T (NEW)
      
      		glDisable(GL\_LIGHTING);
      		glBegin(GL\_QUADS);											// Begin Drawing A Single Quad
      		// We Fill The Entire 1/4 Section With A Single Textured Quad.
      	
      		glTexCoord2f(1.0f, 1.0f); glVertex3f( 21.0f,  18.3f, -10.0f);
      		glTexCoord2f(0.0f, 1.0f); glVertex3f(-21.0f,  18.3f, -10.0f);
      		glTexCoord2f(0.0f, 0.0f); glVertex3f(-21.0f, -18.3f, -10.0f);
      		glTexCoord2f(1.0f, 0.0f); glVertex3f( 21.0f, -18.3f, -10.0f);
      		glEnd();	
      
      		glScalef(m\_fScale, m\_fScale, m\_fScale);
      		glRotated(m\_fRAngle\[0\],0.0, 0.0,1.0);
      		//glRotated(0,0.0,0.0, m\_fRAngle\[0\]);
      		//glRotated(0,0.0,0.0,m\_fRAngle\[0\]);	   
      
      		
      	}
      	else		
      	{
      		glPushMatrix();
      		glViewport(0, 0, window\_width, window\_height);
      		//float len = 28.0f;			
      		//glMatrixMode(GL\_PROJECTION);
      		glLoadIdentity();
      	//	glOrtho(-len, len, -len, len, -len\*100.0f, len\*100.0f);	
      	//	glMatrixMode(GL\_MODELVIEW);
      
      		glScalef(m\_fScale, m\_fScale, m\_fScale);
      		glRotated(m\_fRAngle\[0\],1.0, 0.0, 0.0);
      		glRotated(m\_fRAngle\[1\],0.0,1.0, 0.0);
      		glRotated(m\_fRAngle\[2\],0.0,0.0,1.0);	   
      
      
      	}
      	
      	
      }
      
      E Offline
      E Offline
      Emilio Garavaglia
      wrote on last edited by
      #2

      You have two choiches: 1) Buy a computer with a faster CPU 2) Check if the OpenGL settings on your computer are fine with your hardware (that may be OpenGL capable itself, but may be the library doesn't know it) Seriously: there is nothing strange in your program. Simply, OGL is a bad beast! The only thing to check is the driver of your graphic card (are they the correct ones? sometime the OS setups guess wrong settings) and relative settings (if they are), as well as the OGL settings in the control panel (if there are).

      2 bugs found. > recompile ... 65534 bugs found. :doh:

      1 Reply Last reply
      0
      • G GAJERA

        Hi All I am using gluBuild2DMipmaps() for show live video buffer. but it is using the CPU around 50%. Please suggest how to reduce CPU usages. Here I am sending you the source code for render.

        for (int loop=0; loop<2; loop++) // Loop To Draw Our 4 Views
        {
        if (loop==0) // If We Are Drawing The First Scene
        {
        m_bRenderFromVideo=FALSE;
        if(m_pbVideoData)
        gluBuild2DMipmaps(GL_TEXTURE_2D, 3, m_iVideoHeight,m_iVideoWidth ,GL_LUMINANCE, GL_UNSIGNED_BYTE, m_pbVideoData);

        		glViewport(m\_iNoOfColumn - m\_iNoOfColumn \* m\_iSizeVideo.x, m\_iNoOfRow - m\_iNoOfRow \* m\_iSizeVideo.y, 
        		m\_iNoOfColumn \* m\_iSizeVideo.x, m\_iNoOfRow \* m\_iSizeVideo.y);
        		glPushMatrix();
        
        		gluOrtho2D(-window\_width/4, window\_width/4, -window\_height/4, window\_height/4);
        		//glDrawPixels( window\_width/2,  window\_height/2, GL\_LUMINANCE,GL\_UNSIGNED\_BYTE, (void\*)m\_pbVideoData);
        		glLoadIdentity ();											// Reset The Projection Matrix
        
        		glDisable(GL\_TEXTURE\_GEN\_S);								// Enable Texture Coord Generation For S (NEW)
        		glDisable(GL\_TEXTURE\_GEN\_T);								// Enable Texture Coord Generation For T (NEW)
        
        		glDisable(GL\_LIGHTING);
        		glBegin(GL\_QUADS);											// Begin Drawing A Single Quad
        		// We Fill The Entire 1/4 Section With A Single Textured Quad.
        	
        		glTexCoord2f(1.0f, 1.0f); glVertex3f( 21.0f,  18.3f, -10.0f);
        		glTexCoord2f(0.0f, 1.0f); glVertex3f(-21.0f,  18.3f, -10.0f);
        		glTexCoord2f(0.0f, 0.0f); glVertex3f(-21.0f, -18.3f, -10.0f);
        		glTexCoord2f(1.0f, 0.0f); glVertex3f( 21.0f, -18.3f, -10.0f);
        		glEnd();	
        
        		glScalef(m\_fScale, m\_fScale, m\_fScale);
        		glRotated(m\_fRAngle\[0\],0.0, 0.0,1.0);
        		//glRotated(0,0.0,0.0, m\_fRAngle\[0\]);
        		//glRotated(0,0.0,0.0,m\_fRAngle\[0\]);	   
        
        		
        	}
        	else		
        	{
        		glPushMatrix();
        		glViewport(0, 0, window\_width, window\_height);
        		//float len = 28.0f;			
        		//glMatrixMode(GL\_PROJECTION);
        		glLoadIdentity();
        	//	glOrtho(-len, len, -len, len, -len\*100.0f, len\*100.0f);	
        	//	glMatrixMode(GL\_MODELVIEW);
        
        		glScalef(m\_fScale, m\_fScale, m\_fScale);
        		glRotated(m\_fRAngle\[0\],1.0, 0.0, 0.0);
        		glRotated(m\_fRAngle\[1\],0.0,1.0, 0.0);
        		glRotated(m\_fRAngle\[2\],0.0,0.0,1.0);	   
        
        
        	}
        	
        	
        }
        
        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #3

        GAJERA wrote:

        but it is using the CPU around 50%.

        How does your main loop looks like ? I am guessing that you have a continuous loop without any sleep and that your program runs on a double core. In that case what happens is that your loop will be executed continuously and you will probably get a very high framerate. If you can live with a lower (and fixed) framerate, you can simply execute your drawing code every x msec (choose an appropriate time interval between two frames). The rest of the time, your program should sleep (well in fact wait for user events). You can find more info in one of my articles here[^]

        Cédric Moonen Software developer
        Charting control [v3.0] OpenGL game tutorial in C++

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups