Program starting to become laggy...

This is a discussion on Program starting to become laggy... within the Game Programming forums, part of the General Programming Boards category; I'll post the code at school tomorrow, but here is my predicament... My System specs at school are as follows: ...

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964

    Program starting to become laggy...

    I'll post the code at school tomorrow, but here is my predicament... My System specs at school are as follows:

    P4 2.4 GHZ
    Intel Extreme Graphics controller (i think its a 32 meg card)
    512 mb of memory
    Nice monitor, High refresh rate (80 hz or so)

    Alright, thats a pretty decent computer and the application I'm writing should NOT be slow at all....

    There are about 400 quads on my screen (a grid of seats(392 of them)) and multiple boxes that are used as buttons...

    Is there a better way to manage my drawings other than just a loop that creates 392 in a specific pattern? I've heard of things like buffers that need to be used, but like, omgooses... its running soooo slow!

    It REALLY started running slow when I added a large quad to look like a menu.... I'm not sure if I want to post the code, theres about 1000 lines of relevant code and like 800 more lines you can just assume for..... Is it my Code that is slowing down? Note that I AM a beginning programming, for 2 years about now, so I'm ~probably~ missing something that has to do with memory management???

    BTW I'm using OpenGL and C++ (edit)
    Last edited by Shamino; 10-06-2005 at 06:01 PM.

  2. #2
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    400 quads = 533.3 tri's. Sounds like loading that many tri's through software would slow down you're program alot. If you don't have anything fatally wrong in your engine, (you aren't loading the quads in the render loop are you?) then it's the graphics card. As far as I know 32 megs don't support hardware vertex processing/lighting which speeds up stuff tremendously. If its a big scene where you move around alot, try using a viewing frustrum and if its really big set up nodes. As for memory management, just make sure you delete stuff when you're done with it. I've seen people not delete Buffers when loading their meshes and having 1000 buffers allocated to play with.
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  3. #3

    Join Date
    May 2005
    Posts
    1,041
    You would have to post code and/or an executable, but I'm guessing you're either doing something incredibly amateur such as, as mentioned, loading the data each frame in your render loop (which probably isn't the case) or it's just your display adapter.
    I'm not immature, I'm refined in the opposite direction.

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    400 quads isn't even enough for any modern video card to even blink at. They can handle well in the range of 2 to 6 million triangles on the screen. In fact they can push more pixels to the screen in one frame than there are total pixels on the screen. My guess is you are recreating the vertex buffer each frame. Don't do this. If you loop from 0 to 400 each frame or say 200 across and 200 down that is an O(n^2) operation per frame which will kill your frame rates.

    Create the vertex buffer.
    If it's static, in that you do not need to alter it on the fly, create it as such.
    If it's dynamic, in that you might alter it on the fly or in the game, create it as dynamic.
    If you are locking the vertex buffer - lock and unlock only once per frame - not once per primitive.
    It's also wise to only lock a portion of the vertex buffer - the portion you need to alter and leave the rest alone.

    This is a screenshot in wireframe of a brute force terrain render. I'm sure I've exceeded 400 quads here.

    Posting some code would help.
    Last edited by VirtualAce; 10-06-2005 at 11:20 PM.

  5. #5
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    I'd also be willing to bet you have a lot of glBegin's, glEnds, glDisable's, glEnable's and other such things in the code. Check your code and make sure you've set up your code such that you have the minimum amout of gl state changes - they add up fairly quickly.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  6. #6
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Working on getting the code together to post it, yes I do have alot of GLbegins/ends/translatef/color, here goes

  7. #7
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Main.CPP
    Code:
    #include <windows.h>		// Header File For Windows
    #include <gl\gl.h>			// Header File For The OpenGL32 Library
    #include <gl\glu.h>			// Header File For The GLu32 Library
    #include <gl\glaux.h>		// Header File For The Glaux Library
    #include <stdlib.h>
    #include <math.h>
    #include "header\function.h"
    #include "header\Window.h"
    #include "header\font.h"
    #include "header\filesave.h"
    #include "texture.h"
    
    
    GLfloat in;
    
    int InitGL(GLvoid)
    {
    	if(!getTex())
    		return false;
    
    //	glEnable(GL_TEXTURE_2D);
    	glClearColor (0.0f, 0.0f, 0.0f, 0.0f);								// Black Background						// (Set To Any Color You Wish)
    	glEnable (GL_DEPTH_TEST);											// Enable Depth Testing
    	glShadeModel (GL_SMOOTH);											// Select Smooth Shading				// (Set To Flat Shading If You Wish)
    	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);					// Set Perspective Calculations To Most Accurate
    	glEnable(GL_BLEND);
    	glBlendFunc(GL_SRC_ALPHA,GL_ONE);
    	glAlphaFunc(GL_GREATER,0.1f);										// Set Alpha Testing (To Make Black Transparent)
    
    	glEnable(GL_ALPHA_TEST);											// Enable Alpha Testing (To Make Black Transparent)
    	
    
    	glEnable(GL_DEPTH_TEST);							// Enables Depth Testing
    	glDepthFunc(GL_LEQUAL);		
    	BuildFont();
    
    
    	for(l=0; l<3; l++)
    	LS.loadvars(n[l].is[0], n[l].is[1], n[l].is[2], fname[l]);
    
    	LS.Loadtic();
    	LS.LoadAmount();
    
    
    
    	for(h=0; h<3; h++)
    	{
    	for(l=0; l<3; l++)
    	{
    		for(j=1; j<=28; j++)
    		{
    			for(k=1; k<=14; k++)
    			{
    			if(n[h].is[l][k][j] == 0)
    				n[h].s[l][k][j].sold = false;
    			else
    				n[h].s[l][k][j].sold = true;
    
    			}
    		}
    	}
    	}
    
    
    n[0].Active = true;
    buttonActive= false;
    
    drawSection = 1;
    return TRUE;
    }
    
    
    
    
    int DrawGLScene(GLvoid)
    {
    	
    	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);				// Clear Screen And Depth Buffer
    
    
    glDisable(GL_TEXTURE_2D);
    		glLoadIdentity();
    
    		mouse.x = x_mouse;
    		mouse.y = y_mouse;
    
    		glTranslatef(mouse.x, mouse.y, 2);
    		glColor3f(1, 1, 1);
    
    		glBegin(GL_QUADS);
    			glVertex2f(0, 0);
    			glVertex2f(10, 0);
    			glVertex2f(10, 10);
    			glVertex2f(0, 10);
    		glEnd();
    
    
    		if(menu)
    		{
    			Button[3].Create (100, 100, "Continue", buttonActive);
    	
    		}else{
    	
    		////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////
    		//////////////////////////////////////////////////////////////
    glLoadIdentity();
    glColor3f(1, 1, 1);
    glPrint(1, 550, 50, "Tickets: %5.0f", tic);
    glPrint(1, 550, 70, "Price:  %6.2f", price);
    glPrint(3, 550, 500, "Total tickets: %5.0f", totaltic);
    glPrint(1, 550, 520, "Total amount:  $%6.2f", totalprice);
    ///////////////////
    
    
    	glLoadIdentity();
    
    	glTranslatef(0, 0, 0);
    	type_text(Playername, 30);
    	glPrint(0, 400, 300, Playername);
    
    glLoadIdentity();
    glTranslatef(0, 0, 0);
    
    glColor3f(pay_hover, 1, 1);
    
    glBegin(GL_LINE_STRIP);
    glVertex2f(600, 280);
    glVertex2f(700, 280);
    glVertex2f(700, 310);
    glVertex2f(600, 310);
    glVertex2f(600, 280);
    glEnd();
    
    //Pay button///////
    glPrint(1, 630, 300, "PAY");
    glColor3f(1,1,1);
    
    
    
    
    glPrint(0, 346, 23, "Night 1");
    glLoadIdentity();
    
    
    glBegin(GL_LINE_STRIP);
    	glVertex2f(340, 10);
    	glVertex2f(340, 30);
    	glVertex2f(390, 30);
    	glVertex2f(390, 10);
    	glVertex2f(340, 10);
    	glEnd();
    glPrint(0, 406.5, 23, "Night 2");
    glLoadIdentity();
    	glBegin(GL_LINE_STRIP);
    	glVertex2f(400, 10);
    	glVertex2f(400, 30);
    	glVertex2f(450, 30);
    	glVertex2f(450, 10);
    	glVertex2f(400, 10);
    	glEnd();
    glPrint(0, 466, 23, "Night 3");
    glLoadIdentity();
    	glBegin(GL_LINE_STRIP);
    	glVertex2f(460, 10);
    	glVertex2f(460, 30);
    	glVertex2f(510, 30);
    	glVertex2f(510, 10);
    	glVertex2f(460, 10);
    	glEnd();
    
    glPrint(0, 341.5, 55, "Section 1");
    glLoadIdentity();
    glBegin(GL_LINE_STRIP);
    	glVertex2f(340, 40);
    	glVertex2f(340, 60);
    	glVertex2f(390, 60);
    	glVertex2f(390, 40);
    	glVertex2f(340, 40);
    	glEnd();
    glPrint(0, 401, 55, "Section 2");
    glLoadIdentity();
    	glBegin(GL_LINE_STRIP);
    	glVertex2f(400, 40);
    	glVertex2f(400, 60);
    	glVertex2f(450, 60);
    	glVertex2f(450, 40);
    	glVertex2f(400, 40);
    	glEnd();
    glPrint(0, 461.5, 55, "Section 3");
    glLoadIdentity();
    	glBegin(GL_LINE_STRIP);
    	glVertex2f(460, 40);
    	glVertex2f(460, 60);
    	glVertex2f(510, 60);
    	glVertex2f(510, 40);
    	glVertex2f(460, 40);
    	glEnd();
    
    
    /////////////////////////////////////////////////////////
    //////////--- Create Menu Looking Objects----////////////
    /////////////////////////////////////////////////////////
    
    glLoadIdentity();
    glTranslatef(525, 0, 0);
    glColor3f(0.0f, 0.0f, 1.0f);
    	glBegin(GL_QUADS);							// Draw A Quad
    		glVertex2f(0, 0);				// Top Left
    		glVertex2f(0, 600);				// Top Right
    		glVertex2f(300, 600);				// Bottom Right
    		glVertex2f(300, 0);				// Bottom Left
    	glEnd();
    ////////////////////////////////
    ///Print the seats' letters and number
    glLoadIdentity();
    glTranslatef(0, 1, 0);
    int ymove;
    for(j=1; j<=28; j++)
    {
    	glLoadIdentity();
    	ymove = j * 19.3;
    
    glPrint(0, 280, ymove, row[j]);
    }
    
    
    glLoadIdentity();
    glTranslatef(0, 0, 0);
    int xmove;
    for(j=1; j<=14; j++)
    {
    	glLoadIdentity();
    	xmove = j* 18.5;
    
    	glPrint(0, xmove, 555, seatnum[j]);
    }
    
    
    /////////////////////////////////////////
    
    glEnable(GL_TEXTURE_2D);
    
    Button[0].Create (340, 10, "Night 1", buttonActive);
    
    
    
    
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    		if(n[0].Active)
    		{
    			
    			n[0].DrawRow(drawSection);
    			if(drawSection == 1)
    				for(j=1; j<=28; j++)
    					for(k=1; k<=14; k++)
    					{
    						n[0].s[0][k][j].active = true;
    						n[0].s[1][k][j].active = false;
    						n[0].s[2][k][j].active = false;
    
    					}
    
    			if(drawSection == 2)
    				for(j=1; j<=28; j++)
    					for(k=1; k<=14; k++)
    					{
    						n[0].s[0][k][j].active = false;
    						n[0].s[1][k][j].active = true;
    						n[0].s[2][k][j].active = false;
    					}
    
    
    			if(drawSection == 3)
    				for(j=1; j<=28; j++)
    					for(k=1; k<=14; k++)	
    					{
    						n[0].s[0][k][j].active = false;
    						n[0].s[1][k][j].active = false;
    						n[0].s[2][k][j].active = true;
    					}
    		}
    
    		////////////////////////////////////////////////////////////////////////
    		if(n[1].Active)
    		{
    			n[1].DrawRow(drawSection);
    			if(drawSection == 1)
    				for(j=1; j<=28; j++)
    					for(k=1; k<=14; k++)
    					{
    						n[1].s[0][k][j].active = true;
    						n[1].s[1][k][j].active = false;
    						n[1].s[2][k][j].active = false;
    
    					}
    
    			if(drawSection == 2)
    				for(j=1; j<=28; j++)
    					for(k=1; k<=14; k++)
    					{
    						n[1].s[0][k][j].active = false;
    						n[1].s[1][k][j].active = true;
    						n[1].s[2][k][j].active = false;
    					}
    
    
    			if(drawSection == 3)
    				for(j=1; j<=28; j++)
    					for(k=1; k<=14; k++)	
    					{
    						n[1].s[0][k][j].active = false;
    						n[1].s[1][k][j].active = false;
    						n[1].s[2][k][j].active = true;
    					}
    		}
    
    		///////////////////////////////////////////////////////////////////////
    		if(n[2].Active)
    		{
    			n[2].DrawRow(drawSection);
    			if(drawSection == 1)
    				for(j=1; j<=28; j++)
    					for(k=1; k<=14; k++)
    					{
    						n[2].s[0][k][j].active = true;
    						n[2].s[1][k][j].active = false;
    						n[2].s[2][k][j].active = false;
    
    					}
    
    			if(drawSection == 2)
    				for(j=1; j<=28; j++)
    					for(k=1; k<=14; k++)
    					{
    						n[2].s[0][k][j].active = false;
    						n[2].s[1][k][j].active = true;
    						n[2].s[2][k][j].active = false;
    					}
    
    
    			if(drawSection == 3)
    				for(j=1; j<=28; j++)
    					for(k=1; k<=14; k++)	
    					{
    						n[2].s[0][k][j].active = false;
    						n[2].s[1][k][j].active = false;
    						n[2].s[2][k][j].active = true;
    					}
    		}
    
    
    }
    
    
    return TRUE;
    }
    
    
    
    
    
    
    
    
    LRESULT CALLBACK WndProc(	HWND	hWnd,			// Handle For This Window
    							UINT	uMsg,			// Message For This Window
    							WPARAM	wParam,			// Additional Message Information
    							LPARAM	lParam)			// Additional Message Information
    {
    	switch (uMsg)									// Check For Windows Messages
    	{
    		case WM_MOUSEMOVE:										// Watch For Mouse Status
    		{
    			x_mouse = LOWORD(lParam);							// Check Mouse Position
    			y_mouse = HIWORD(lParam);	
    	
    			return 0;											// Return To The Message Loop
    		}
    
    		case WM_LBUTTONDOWN:
    			{
    			if((mouse.x > 550 && mouse.x < 650) && (mouse.y > 280 && mouse.y < 310))
    				{
    					pay_hover=0;
    					
    				}
    
    
    				return 0;
    			}
    
    
    
    
    		case WM_LBUTTONUP:
    			{
    				if(menu)
    				{
    					if((mouse.x > 100 || mouse.x < 200) &&
    						(mouse.y > 100 || mouse.y < 500))
    				{
    					menu = false;
    				}
    				}
    
    
    
    
    
    
    
    
    
    				pay_hover=1;
    
    			for(h=0; h<3; h++)			
    			{
    				if(n[h].Active)
    				for(l=0; l<3; l++)
    				{
    						
    					for(j=1;j<=28;j++)
    					{
    						for(k=1;k<=14;k++)
    						{
    							if(n[h].s[l][k][j].active)					
    
    						if( (myAbsd(n[h].s[l][k][j].x  - mouse.x) < 10.0) &&		
    							(myAbsd(n[h].s[l][k][j].y - mouse.y) < 10.0))
    						{					
    							if(n[h].is[l][k][j] == 0)
    							{
    								n[h].is[l][k][j] = 1;
    								n[h].s[l][k][j].sold = true;
    								tic+= 1;
    								price += 1.50;		
    							}else
    							{
    								n[h].is[l][k][j] = 0;
    								n[h].s[l][k][j].sold = false;
    
    									if(tic > 0)
    									{
    										tic-=1;
    										price -= 1.50;
    									}else{
    										totaltic -=1;
    										totalprice -= 1.50;
    										}							
    									}
    								}					
    							}
    						}
    					}
    				}
    
    
    
    			if((mouse.x > 550 && mouse.x < 650) && (mouse.y > 280 && mouse.y < 310))
    				{
    
    					totaltic += tic;
    					totalprice += price;
    
    					tic=0;
    					price=0;
    					
    					
    					
    					for(h=0; h<3; h++)			
    						LS.savevars(n[h].is[0], n[h].is[1], n[h].is[2], fname[h]);
    			
    			
    				LS.SaveTic(totaltic);
    				LS.SaveAmount(totalprice);
    				}
    
    
    
    				return 0;
    		}
    
    
    
    
    
    
    		case WM_ACTIVATE:							// Watch For Window Activate Message
    		{
    			if (!HIWORD(wParam))					// Check Minimization State
    			{
    				active=TRUE;						// Program Is Active
    			}
    			else
    			{
    				active=FALSE;						// Program Is No Longer Active
    			}
    
    			return 0;								// Return To The Message Loop
    		}
    
    		case WM_SYSCOMMAND:							// Intercept System Commands
    		{
    			switch (wParam)							// Check System Calls
    			{
    				case SC_SCREENSAVE:					// Screensaver Trying To Start?
    				case SC_MONITORPOWER:				// Monitor Trying To Enter Powersave?
    				return 0;							// Prevent From Happening
    			}
    			break;									// Exit
    		}
    
    		case WM_CLOSE:								// Did We Receive A Close Message?
    		{
    			PostQuitMessage(0);						// Send A Quit Message
    			return 0;								// Jump Back
    		}
    
    		case WM_KEYDOWN:							// Is A Key Being Held Down?
    		{
    			keys[wParam] = TRUE;					// If So, Mark It As TRUE
    			return 0;								// Jump Back
    		}
    
    		case WM_KEYUP:								// Has A Key Been Released?
    		{
    			keys[wParam] = FALSE;					// If So, Mark It As FALSE
    			return 0;								// Jump Back
    		}
    
    		case WM_SIZE:								// Resize The OpenGL Window
    		{
    			ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));  // LoWord=Width, HiWord=Height
    			return 0;								// Jump Back
    		}
    	}
    
    	// Pass All Unhandled Messages To DefWindowProc
    	return DefWindowProc(hWnd,uMsg,wParam,lParam);
    }
    
    int WINAPI WinMain(	HINSTANCE	hInstance,			// Instance
    					HINSTANCE	hPrevInstance,		// Previous Instance
    					LPSTR		lpCmdLine,			// Command Line Parameters
    					int			nCmdShow)			// Window Show State
    {
    	MSG		msg;									// Windows Message Structure
    	BOOL	done=FALSE;								// Bool Variable To Exit Loop
    
    
    	// Ask The User Which Screen Mode They Prefer
    //	if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
    //	{
    
    //	}
    
    	// Create Our OpenGL Window
    	if (!CreateGLWindow("Ticket Seller",800,600,32,fullscreen))
    	{
    		return 0;									// Quit If Window Was Not Created
    	}
    
    	while(!done)									// Loop That Runs While done=FALSE
    	{
    		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))	// Is There A Message Waiting?
    		{
    			if (msg.message==WM_QUIT)				// Have We Received A Quit Message?
    			{
    				done=TRUE;							// If So done=TRUE
    			}
    			else									// If Not, Deal With Window Messages
    			{
    				TranslateMessage(&msg);				// Translate The Message
    				DispatchMessage(&msg);				// Dispatch The Message
    			}
    		}
    		else										// If There Are No Messages
    		{
    	
    			if (active)								// Program Active?
    			{
    				if (keys[VK_ESCAPE])				// Was ESC Pressed?
    				{
    					done=TRUE;						// ESC Signalled A Quit
    				}
    
    				if(keys['1'])
    				{
    					n[0].Active = true;
    					n[1].Active = false;
    					n[2].Active = false;
    				}
    
    				if(keys['2'])
    				{
    					n[0].Active = false;
    					n[1].Active = true;
    					n[2].Active = false;
    				}
    
    				if(keys['3'])
    				{
    					n[0].Active = false;
    					n[1].Active = false;
    					n[2].Active = true;
    				}
    
    				if(keys[VK_SPACE])
    				{
    					if(menu)
    						menu = false;
    					else{
    					if(buttonActive)
    						buttonActive = false;
    					else
    						buttonActive = true;
    					}
    				}
    
    
    
    
    
    
    				if(keys['Q'])
    				{
    					drawSection = 1;
    
    				}
    				if(keys['W'])
    				{
    					drawSection = 2;
    				}
    
    				if(keys['E'])
    				{
    					drawSection = 3;
    				}
    
    
    
    
    				else								// Not Time To Quit, Update Screen
    				{
    					DrawGLScene();					// Draw The Scene
    					SwapBuffers(hDC);				// Swap Buffers (Double Buffering)
    				}
    			}
    		}
    	}
    
    	// Shutdown
    	KillGLWindow();									// Kill The Window
    	return (msg.wParam);							// Exit The Program
    }
    Function.h
    Code:
    #ifndef GL_FRAMEWORK__INCLUDED
    #define GL_FRAMEWORK__INCLUDED
    
    #include <windows.h>		// Header File For Windows
    #include <gl\gl.h>			// Header File For The OpenGL32 Library
    #include <gl\glu.h>			// Header File For The GLu32 Library
    #include <gl\glaux.h>		// Header File For The Glaux Library
    #include <math.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    #pragma comment( lib, "opengl32.lib" )									// Search For OpenGL32.lib While Linking
    #pragma comment( lib, "glu32.lib" )	
    
    HDC			hDC=NULL;		// Private GDI Device Context
    HGLRC		hRC=NULL;		// Permanent Rendering Context
    HWND		hWnd=NULL;		// Holds Our Window Handle
    HINSTANCE	hInstance;		// Holds The Instance Of The Application
    //------------------------------------------------------------------------------
    //		Global Variables
    //---------------------------------------------------------------------------------
    
    bool	keys[256];			// Array Used For The Keyboard Routine
    bool	active=TRUE;		// Window Active Flag Set To TRUE By Default
    bool	fullscreen=true;	// Fullscreen Flag Set To Fullscreen Mode By Default
    
    char Playername[100];
    bool buttonActive;
    bool menu = TRUE;
    
    GLuint texture[4];
    
    int pay_hover=1;			//the PAY button will change color when press
    int base[4];				//the font will be store in here
    int j, k, l, h;					//for the 'for' loop
    
    float x_mouse, y_mouse;		//define the coordinate of the mouse
    float tic;					//store number of tickets when the user click a seat
    float price;				//store the amount of money
    float totaltic;				//the total of tickets sold
    float totalprice;			//the total amount of money
    int drawSection;
    char fname[3][30]= { "save/Night1/data.dat", "save/Night2/data.dat", "save/Night3/data.dat"};
    
    //---------------------------------------------------------------------\
    //					Mouse function
    //-----------------------------------------------------------------------
    typedef struct
    {
    	float x, y;			//struct that draw a mouse and display on the screen
    }MouseMove;				//so the user know where the mouse is
    MouseMove mouse;
    
    //-----------------------------------------------------------------------------------------------------------\
    //			SEATS CLASS
    //--------------------------------------------------------------------------------------------------------------
    
    class Nights
    {
    	public:
    
    	bool Active;
    	int is[3][15][29];//store number 1 or 0 to toggle the bool 'sold' value in 
    
    
    	struct Seats								//Seats struct;
    	{	
    		int seatnum;
    		bool active;
    		bool sold;
    		float x, y;
    
    	};
    		Seats s[3][15][29];		//declare 3 section in an auditorium
    
    
    
    	void DrawRow(int w)		//draw the blocks
    	{
    		
    		if(w == 1)
    		{
    			for(j=1;j<=28;j++)
    			{
    				for(k=1;k<=14;k++)
    				{
    				glLoadIdentity();							// Reset The Current Modelview Matrix
    				glTranslatef(0.0f,0.0f,0.0f);			
    				s[0][k][j].x=k*19.0f;	
    				s[0][k][j].y=j*19.0f;					
    				glTranslatef(s[0][k][j].x,s[0][k][j].y,0.0f);	
    				
    				if(s[0][k][j].sold == false)
    				{
    					glColor3f(1, 0, 0);
    				}else
    				{
    					glColor4f(0.0f,1.0f,0.0f, 0.7f);			
    				}
    
    				glBindTexture(GL_TEXTURE_2D, texture[0]);
    				glBegin(GL_QUADS);							// Draw A Quad 
    				glTexCoord2f(0, 0);	glVertex2f( -10.0f,  10.0f);			// Top Left
    				glTexCoord2f(1, 0);	glVertex2f(  10.0f,  10.0f);			// Top Right
    				glTexCoord2f(1, 1);	glVertex2f(  10.0f, -10.0f);			// Bottom Right
    				glTexCoord2f(0, 1);	glVertex2f( -10.0f, -10.0f);			// Bottom Left
    				glEnd();		
    				}
    			}	
    		}
    
    
    		if(w == 2)
    		{
    			for(j=1;j<=28;j++)
    			{
    				for(k=1;k<=14;k++)
    				{
    				glLoadIdentity();							// Reset The Current Modelview Matrix
    				glTranslatef(0.0f,0.0f,0.0f);			
    				s[1][k][j].x=k*19.0f;	
    				s[1][k][j].y=j*19.0f;					
    				glTranslatef(s[1][k][j].x,s[1][k][j].y,0.0f);	
    				
    				if(s[1][k][j].sold == false)
    				{
    					glColor3f(1, 0, 0);
    				}else
    				{
    					glColor4f(0.0f,1.0f,0.0f, 0.7f);			
    				}
    
    				glBegin(GL_QUADS);							// Draw A Quad 
    				glTexCoord2f(0, 0);	glVertex2f( -10.0f,  10.0f);			// Top Left
    				glTexCoord2f(1, 0);	glVertex2f(  10.0f,  10.0f);			// Top Right
    				glTexCoord2f(1, 1);	glVertex2f(  10.0f, -10.0f);			// Bottom Right
    				glTexCoord2f(0, 1);	glVertex2f( -10.0f, -10.0f);			// Bottom Left
    				glEnd();		
    				}
    			}	
    		}
    
    		if(w == 3)
    		{
    			for(j=1;j<=28;j++)
    			{
    				for(k=1;k<=14;k++)
    				{
    				glLoadIdentity();							// Reset The Current Modelview Matrix
    				glTranslatef(0.0f,0.0f,0.0f);			
    				s[2][k][j].x=k*19.0f;	
    				s[2][k][j].y=j*19.0f;					
    				glTranslatef(s[2][k][j].x,s[2][k][j].y,0.0f);	
    				
    				if(s[2][k][j].sold == false)
    				{
    					glColor3f(1, 0, 0);
    				}else
    				{
    					glColor4f(0.0f,1.0f,0.0f, 0.7f);		
    				}
    
    				glBegin(GL_QUADS);							// Draw A Quad 
    				glTexCoord2f(0, 0);	glVertex2f( -10.0f,  10.0f);			// Top Left
    				glTexCoord2f(1, 0);	glVertex2f(  10.0f,  10.0f);			// Top Right
    				glTexCoord2f(1, 1);	glVertex2f(  10.0f, -10.0f);			// Bottom Right
    				glTexCoord2f(0, 1);	glVertex2f( -10.0f, -10.0f);			// Bottom Left
    				glEnd();		
    				}
    			}	
    		}
    
    
    	}
    };
    
    Nights n[3];
    Nights blah;
    //------------------------------------------------------------------------------------------------\
    //		Function that find absolute value of a number
    //------------------------------------------------------------------------------------------------
    inline GLdouble myAbsd(GLdouble A)	// Absolute value function
    {
      if (A < 0)
      A = -A; 
      return A;
    }
    
    //----------------------------------------------------------------------------------------\
    //				Hold the name of the seats
    //-----------------------------------------------------------------------------------------
    
    char row[29][3] = {" ", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
    					"O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "AA", "BB"};
    char seatnum[15][3]={"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14"};
    //-------------------------------------------------------------------------------------------\
    //--------------------------------------------------------------------------------------------
    
    //////////////////////////////////////////////////////////////////
    //----------Function for typing text----------------------///////
    
    void type_text( char tekst[], int max )	{
    		int d = strlen( tekst );
    		for( int w = 32; w < 126; w++ )
    			if( keys[ w ] && d < max ) {				
    				tekst[ d++ ] = w;
    				keys[ w ] = false;
    			}
    		if( keys[ 8 ] ) {
    			if( d > 0 )
    				tekst[ --d ] = 0;
    			keys[ 8 ] = false;
    		}
    	}
    /////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////
    //--------- Function for Giving each seat a number-------//
    
    void numbermakerthing()
    {
    	for(h=0; h<3; h++)			
    		{
    		for(l=0; l<3; l++)
    			{
    			for(j=1;j<=28;j++)
    				{
    				for(k=1;k<=14;k++)
    					{
    					blah.s[h][k][j].seatnum += 1; 
    				}
    			}
    		}
    	}
    
    }
    
    ///////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////
    #endif
    There it is, theres no render loops i don't believe... but we'll see what you guys say about it

  8. #8
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Last edited by Shamino; 10-07-2005 at 07:41 AM.

  9. #9
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Quote Originally Posted by Bubba
    I'm sure I've exceeded 400 quads here.
    I'm sure you've exceeded 4000 quads.

    Quote Originally Posted by Shamino
    Intel Extreme Graphics controller (i think its a 32 meg card)
    Intel Extreme Graphics happens to be built into the motherboard. Regardless, it is likely the 32MB setting can be raised - it probably has a maximum of 64 or 128MB. When you get a chance, pay a visit to your CMOS (on my system, hitting delete during bootup enters it) and check out the settings for your video.

    Quote Originally Posted by durban
    As far as I know 32 megs don't support hardware vertex processing/lighting which speeds up stuff tremendously.
    The memory amount is usually a good way to tell, but not with onboard. Most systems with onboard can be set to use somewhere between 8 and 256MB so it isn't too good a way to tell with that.

  10. #10
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    on the video report it shows the card can use up to 96 mb of video memory

  11. #11
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Not bad I suppose. You might want to find out if it has an AGP or PCI Express 16x slot in case you wish to upgrade. Who makes it and what model is it?

  12. #12
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Unfortunately upgrading is not an option, it is a school project, making it for the school, to manage their plays ticket sales n stuff... So it will always run on a school computer.....

    Seriously? My code is fine?

  13. #13
    ---
    Join Date
    May 2004
    Posts
    1,379
    It's probably all those evil nested 'for' loops in your DrawRow method.
    Sorry I can't really give any advice on changing it but that is probably what is slowing it down.

    Something else to look at,
    Code:
    glTexCoord2f(0, 0);         // <- this function takes floats as parameters
    glTexCoord2d(0, 0);        // <- use this
    glTexCoord2f(0.0f, 0.0f); // <- or this
    Last edited by sand_man; 10-07-2005 at 08:37 AM.

  14. #14
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    The loops would be a processor anchor, not a video anchor, the processor is a p4 2.4 ghz, im sure that isnt the problem....

    2f?
    2d?
    ???

    you want me to put 0.0 there instead of 0 you mean? because its taking time to switch it to a 0.0?

    I can't see how that is slowing me down

  15. #15
    Amazingly beautiful user.
    Join Date
    Jul 2005
    Location
    If you knew I'd have to kill you
    Posts
    254
    One thing I see is that you have "glBegin() and glEnd()" after each polygon. This causes a major slow down (several orders of magnitude on one program I was working on).
    So, try to do more than one Quad at once. Remember, every 8 glVertex's forms a new quad, so you do not need a glEnd/glBegin for each one.

    If you want to change texture in between, try putting all the textures into one big texture, and changing UV coordinates instead (this does not require glEnd/glBegin).


    Your program should still run reasonably though. Are accelerated graphics drivers installed on the box, and is OpeNGL supported?

    Good luck.
    Programming Your Mom. http://www.dandongs.com/

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Starting C++;First Program
    By Caliban in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2009, 01:41 PM
  2. Starting a program
    By mcgeady in forum C++ Programming
    Replies: 3
    Last Post: 02-25-2006, 11:52 AM
  3. starting program
    By Ideswa in forum C++ Programming
    Replies: 3
    Last Post: 02-20-2006, 01:36 PM
  4. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21