Thread: Can I have some Sample Code? (OpenGL, glDrawPixels();)

  1. #31
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    A Display List is a cache of OpenGL commands that can be executed with a single call. OpenGL holds all the transforms or whatever in memory until they are called, and does not recalculate everything every frame. Some GL commands cannot be used inside the list definition, this is from MSDN...

    Certain commands are not compiled into the display list, but are executed immediately, regardless of the display list mode. These commands are glColorPointer, glDeleteLists, glDisableClientState, glEdgeFlagPointer, glEnableClientState, glFeedbackBuffer, glFinish, glFlush, glGenLists, glIndexPointer, glInterleavedArrays, glIsEnabled, glIsList, glNormalPointer, glPopClientAttrib, glPixelStore, glPushClientAttrib, glReadPixels, glRenderMode, glSelectBuffer, glTexCoordPointer, glVertexPointer, and all of the glGet routines.

    Similarly, glTexImage2D and glTexImage1D are executed immediately and not compiled into the display list when their first argument is GL_PROXY_TEXTURE_2D or GL_PROXY_TEXTURE_1D, respectively.

    When the glEndList function is encountered, the display list definition is completed by associating the list with the unique name list (specified in the glNewList command). If a display list with name list already exists, it is replaced only when glEndList is called.

    The glCallList and glCallLists functions can be entered into display lists. The commands in the display list or lists executed by glCallList or glCallLists are not included in the display list being created, even if the list creation mode is GL_COMPILE_AND_EXECUTE.
    So, if your draw code is something like this pseudocode..

    Code:
    for (every object to be drawn) {
       glLoadIdentity();
       glTranslatef(object location);
       glBegin(POLY_TYPE);
       //draw geometry
       glEnd();
    }
    You can optimize that using a display list and putting the glBegin/glEnd set into the list (along with any other OpenGL calls that are the same for every object).

    Code:
    for (every object to be drawn) {
       glLoadIdentity();
       glTranslatef(object location);
       glCallList(object id);  //provided every object has the same geometry
    }
    Setup the list during your program initinilization, and then in your draw code you just call glCallList(object id). Which is essentally, a function call to everything you put in the list, only faster because its already been calculated and saved behind the scenes by OpenGL. I use display lists alot, if you have a thousand different objects, then your probably dont want to create a display list for each. But if you have a few dozen, then display lists may be the way to go.

    The Red Book has an excellent chapter detailing the function and use of Display Lists.

  2. #32
    Computer guy
    Join Date
    Sep 2005
    Location
    I'm lost!!!
    Posts
    200
    Ok, the project that me and Shamino are working on contains 392 quads on the screen, which means looping the glCallList() is the same as draw 392 quads with loop.

    This:
    Code:
    for(blah, blah, blah){
       for(blah, blah, blah)
         {
                glTranslatef(blah, blah, blah);
                       glBegin();
                            //Vertex
                       glEnd();
          }
    }
    is same as:
    Code:
    glNewList(box, GL_COMPILE);
             glBegin(GL_QUADS);
               //vertex
             glEnd();
    glEndList();
    
    for(blah, blah, blah){
       for(blah, blah, blah)
         {
                glTranslatef(blah, blah, blah);
                       glCallList(box)
          }
    }
    neither way it still loops the glBegin() and glEnd();
    But thanks for showing those stuff anyway
    Hello, testing testing. Everthing is running perfectly...for now

  3. #33
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Eber!!!!!!!!! Good to see ya's. Where ya been hiding? Eber is the man to ask for GL...I just know Direct3D and I was attempting to write a standard vertex array system that wasn't connected to any one API. You could have used the vertex array system in a DOS engine. I'm out of this thread now......cuz I don't know GL.

  4. #34
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    hdragon has exactly the same thoughts as I have, only because there is no difference in speed when we use a display list and when we don't.....

    If you're saying there is a difference, the difference is within 1-5 fps....

    You're saying calling it from memory is faster than writing it on the fly.... but it isn't much faster, because I can't notice much difference when we add the code...

  5. #35
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    Using a display list cannot be slower that calling the functions standard. The real speed boost you get from DisplayLists is when you have matrix manipulation routines, lighting models, or materials.

    But on a practical level, if you cant draw 400 identical polygons with a single display list. There is a bottleneck in your code that is somewhere else, and not in the way you are drawing polys.

    Hey Bubba, yeah, I have been out of the loop. I havent touched a program in over a year, but now im back working on a new project. I have been writing a novel, its an action packed fantasy adventure, I am very close to finishing, just need to get motivated on these last few rewrites

  6. #36
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    I'll post the new optimized code tomorrow at school, everything possible is put in a display list, might be a few things left out of the loop but we'll see what you have to say ...

    We have SERIOUS matrix manipulation routines....
    we're working with a [3][14][28] and we have 9 of them.... each has like 3 different variables that change all the time... but how can displays help the background code, that really doesn't have anything to do with what is being drawn?

    Also About Display Lists....

    functions like glColor3f/4f etc etc.... if you put those colors in a display list all by themselves.... is it more efficient than calling a glColor3f 100 times even if you make it the same color?

    *wants to be your apprentice*
    Last edited by Shamino; 10-25-2005 at 06:25 PM.

  7. #37
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    OMG, you can put a for loop in a display list!!!

    So instead of freakin looping at all, i can loop those quads and precompile 392 of them without lifting a finger....

    I won't have to loop the call function on the fly, all I gotta do is call the function...
    instead of loop + call the function 392 times, right eber?

    Wait, that won't work will it? I can't change the translatef while its in a display list can I ?

    I'll post code soon
    Last edited by Shamino; 10-25-2005 at 09:28 PM.

  8. #38
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    Quote Originally Posted by Shamino
    OMG, you can put a for loop in a display list!!!

    So instead of freakin looping at all, i can loop those quads and precompile 392 of them without lifting a finger....

    I won't have to loop the call function on the fly, all I gotta do is call the function...
    instead of loop + call the function 392 times, right eber?

    Wait, that won't work will it? I can't change the translatef while its in a display list can I ?

    I'll post code soon
    You can put a Translatef in a display list, but if you are changing the values from frame to frame, then thats no good. Remember that the list is only going to save gl functions, so while the for loop appears to function normally, what it is actually doing is compiling all the individual gl functions into the list.

  9. #39
    Computer guy
    Join Date
    Sep 2005
    Location
    I'm lost!!!
    Posts
    200
    We don't want to put the loop into the display list because the values of the quad must be change while the program runs. When we put in display list, it'll stuck there in the memory and will do nothing. Remember that Shamino, you just did that this morning.
    Hello, testing testing. Everthing is running perfectly...for now

  10. #40
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    yeah yeah, we can put the quads themselves in the list, but the arrays/loops n stuff gotta stay out of it, cuz they change, and because the lists dont actually take those commands...


    Well everything possible is in a list now, theres about 10 lists...

    FPS change might be within 1-5 fps, but it isnt enough... what the dilio...

  11. #41
    ---
    Join Date
    May 2004
    Posts
    1,379
    I think you need to re-design
    Have you done any gfx API projects before?

  12. #42
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Ok post it all right here. This is ridiculous. I can get 20 to 30 fps with the max number of tri's being rendered that my video card can handle. Something is seriously amiss folks.

  13. #43
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    Alright, every single line of code will be posted tomorrow...

    Most of it is in display lists now...

    I'd say, by a general guestimate, our fps is between 5-20.... Might put in FPS calculation code just to find out :d...

    Sandman - this is my first real project (aside from pong, which ran beautifully i might add)

    Mind you all, when I run this program at home on my p3 dual 400 mhz computer, it runs perfectly..... the difference, however, is that I have a GeForce FX 5600 video card (128 meg)....

    Imagine that..... I just threw it in perspective, maybe it isn't our code, maybe its just the schools onboard video that sucks donkey balls...
    Last edited by Shamino; 10-27-2005 at 01:25 AM.

  14. #44
    ---
    Join Date
    May 2004
    Posts
    1,379
    .....no comment

  15. #45
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    Okay, here it is, long post

    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;
    
    
    //-------------------------------------------------------------------------------------------
    //		Function create the buttons for the nights and sections
    //-------------------------------------------------------------------------------------------
    
    
    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_ALWAYS);		
    	BuildFont();
    	BuildList();
    	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;
    
    
    
    for(j=0; j<=6; j++)
    {
    	Button[j].coord.Color2 = 1;
    }
    
    Pay.coord.Color2 = 1;
    
    Button[1].coord.active = true;
    Button[4].coord.active = true;
    
    
    
    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);
    
    		glCallList(MouseQuad);
    
    		if(menu)
    		{	
    			glCallList(MenuText);
    			glPrint(2, 50, 160, "Ticket Price");
    			glPrint(0, 160, 100, ShowName);
    			glPrint(0, 160, 130, ShowDate);
    			glPrint(0, 160, 160, ticketPrice);
    
    				if((mouse.x>Button[0].coord.left && mouse.x < Button[0].coord.right) &&
    					(mouse.y > Button[0].coord.top && mouse.y < Button[0].coord.bottom))
    				{
    					Button[0].coord.Color=1;
    		
    				}
    				else
    					Button[0].coord.Color =0.5f;
    
    			glLoadIdentity();
    			
    			glCallList(button0);
    
    			glCallList(button1);
    
    			glCallList(button2);
    
    
    			glLoadIdentity();
    			glTranslatef(0, 0, 10);
    			glColor4f(1, 1, 1, 1);
    			
    			if(ShowNameActive)
    			{
    				type_text(ShowName, 30);
    
    			}
    
    			if(ticketPriceActive)
    			{
    				type_text(ticketPrice, 4);
    
    			}
    
    			if(ShowDateActive)
    			{
    				type_text(ShowDate, 30);
    
    			}
    
    				glLoadIdentity();
    			glColor4f(1, 1, 1, 0.5);
    			Button[0].Create (700, 500, "Continue");
    	
    		}else
    		{
    
    
    
    ///////////////////////////////////////
    			//Determine if the Section is draw when the buttons are activated//
    
    if(Button[4].coord.active == true)
    	drawSection = 1;
    if(Button[5].coord.active == true)
    	drawSection = 2;
    if(Button[6].coord.active == true)
    	drawSection = 3;
    
    			for(j=1; j<=6; j++)
    			{
    				if((mouse.x>Button[j].coord.left && mouse.x < Button[j].coord.right) &&
    					(mouse.y > Button[j].coord.top && mouse.y < Button[j].coord.bottom))
    				{
    					Button[j].coord.Color=1;
    						
    				}
    				else
    					Button[j].coord.Color =0.5f;
    			}
    
    				if((mouse.x>Pay.coord.left && mouse.x < Pay.coord.right) &&
    					(mouse.y > Pay.coord.top && mouse.y < Pay.coord.bottom))
    				{
    					Pay.coord.Color=1;
    						
    				}
    				else
    					Pay.coord.Color =0.5f;
    			
    glLoadIdentity();
    glColor3f(1, 1, 1);
    glPrint(0, 340, 20, ShowName);
    glPrint(0, 450, 20, ShowDate);
    glPrint(1, 600, 100, "Tickets: %5.0f", tic);
    glPrint(1, 600, 120, "Price:  %6.2f", price);
    glPrint(2, 600, 500, "Total tickets: %5.0f", totaltic);
    glPrint(2, 600, 520, "Total amount:  $%6.2f", totalprice);
    
    glLoadIdentity();
    Pay.Create(630, 300, "PAY");
    
    
    
    ///Print the seats' letters and number
    glLoadIdentity();
    glColor4f(1, 1, 1, 1);
    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]);
    }
    /////////////////////////////////////////
    glLoadIdentity();
    //glColor4f(1, 1, 1, 1);
    
    
    Button[1].Create (340, 100, "Night 1");
    Button[2].Create(420, 100, "Night 2");
    Button[3].Create(500, 100, "Night 3");
    
    Button[4].Create(340, 150, "Section 1");
    Button[5].Create(420, 150, "Section 2");
    Button[6].Create(500, 150, "Section 3");
    
    glEnable(GL_TEXTURE_2D);
    
    glColor4f(1, 1, 1,1 );
    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>Pay.coord.left && mouse.x < Pay.coord.right) &&
    					(mouse.y > Pay.coord.top && mouse.y < Pay.coord.bottom))
    				{
    					
    					Pay.coord.Color2 = 0;
    						
    				}
    			//	else{
    			//		Pay.coord.Color =0.5f;	
    			//		Pay.coord.Color2 = 1;
    				//}
    
    
    				return 0;
    			}
    
    
    
    
    		case WM_LBUTTONUP:
    			{
    				if(menu)
    				{
    					if((mouse.x > Button[0].coord.left && mouse.x < Button[0].coord.right) &&
    						(mouse.y > Button[0].coord.top && mouse.y < Button[0].coord.bottom))
    				{
    					menu = false;
    				}
    
    					if((mouse.x > 150 && mouse.x<400) &&
    						(mouse.y > 85 && mouse.y < 105) && !ShowNameActive)
    					{
    						ShowNameActive = true;
    						ShowDateActive = false;
    						ticketPriceActive = false;
    					}else{
    						ShowNameActive = false;
    					}
    
    
    					if((mouse.x > 150 && mouse.x<400) &&
    						(mouse.y > 115 && mouse.y < 135) && !ShowDateActive)
    					{	
    						ShowDateActive = true;
    						ShowNameActive = false;
    						
    						ticketPriceActive = false;
    					}else{
    						ShowDateActive = false;
    					}
    
    
    					if((mouse.x > 150 && mouse.x<400) &&
    						(mouse.y > 145 && mouse.y < 165) && !ticketPriceActive)
    					{
    						ShowNameActive = false;
    						ShowDateActive = false;
    						ticketPriceActive = true;
    					}else{
    						ticketPriceActive = false;
    					}
    				
    				
    				
    				
    				
    				
    				
    				
    				}
    
    					/////////////////////////////////////////////////
    					////===Determine if the buttons are clicked========////
    				if((mouse.x>Button[1].coord.left && mouse.x < Button[1].coord.right) &&
    							(mouse.y > Button[1].coord.top && mouse.y < Button[1].coord.bottom) && !Button[1].coord.active)
    						{
    							Button[1].coord.active = true;
    							Button[2].coord.active = false;
    							Button[3].coord.active = false;
    
    							n[0].Active = true;
    							n[1].Active = false;
    							n[2].Active = false;						
    						}
    
    				if((mouse.x>Button[2].coord.left && mouse.x < Button[2].coord.right) &&
    							(mouse.y > Button[2].coord.top && mouse.y < Button[2].coord.bottom) && !Button[2].coord.active)
    						{
    							Button[1].coord.active = false;
    							Button[2].coord.active = true;
    							Button[3].coord.active = false;
    
    							n[0].Active = false;
    							n[1].Active = true;
    							n[2].Active = false;						
    						}
    
    				if((mouse.x>Button[3].coord.left && mouse.x < Button[3].coord.right) &&
    							(mouse.y > Button[3].coord.top && mouse.y < Button[3].coord.bottom) && !Button[3].coord.active)
    						{
    							Button[1].coord.active = false;
    							Button[2].coord.active = false;
    							Button[3].coord.active = true;
    
    							n[0].Active = false;
    							n[1].Active = false;
    							n[2].Active = true;						
    						}
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    				/////----3 Sections buttons==================================/////////////
    				if((mouse.x>Button[4].coord.left && mouse.x < Button[4].coord.right) &&
    							(mouse.y > Button[4].coord.top && mouse.y < Button[4].coord.bottom) && !Button[4].coord.active)
    						{
    							Button[4].coord.active = true;
    							Button[5].coord.active = false;
    							Button[6].coord.active = false;
    
    						//	drawSection = 1;					
    						}
    				if((mouse.x>Button[5].coord.left && mouse.x < Button[5].coord.right) &&
    							(mouse.y > Button[5].coord.top && mouse.y < Button[5].coord.bottom) && !Button[5].coord.active)
    						{
    							Button[4].coord.active = false;
    							Button[5].coord.active = true;
    							Button[6].coord.active = false;
    
    						//	drawSection = 2;					
    						}
    				if((mouse.x>Button[6].coord.left && mouse.x < Button[6].coord.right) &&
    							(mouse.y > Button[6].coord.top && mouse.y < Button[6].coord.bottom) && !Button[6].coord.active)
    						{
    							Button[4].coord.active = false;
    							Button[5].coord.active = false;
    							Button[6].coord.active = true;
    
    						//	drawSection = 3;
    
    						}
    					
    							
    
    
    						
    				if((mouse.x>Pay.coord.left && mouse.x < Pay.coord.right) &&
    					(mouse.y > Pay.coord.top && mouse.y < Pay.coord.bottom))
    				{
    					
    					Pay.coord.Color2 = 1;
    						
    				}else
    					Pay.coord.Color2 = 1;
    
    
    
    
    
    
    
    				
    
    
    
    
    
    
    
    
    
    				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 += ticketprice;		
    							}else
    							{
    								n[h].is[l][k][j] = 0;
    								n[h].s[l][k][j].sold = false;
    
    									if(tic > 0)
    									{
    										tic-=1;
    										price -= ticketprice;
    									}else{
    										totaltic -=1;
    										totalprice -= ticketprice;
    										}							
    									}
    								}					
    							}
    						}
    					}
    				}
    
    
    
    			if((mouse.x > Pay.coord.left && mouse.x < Pay.coord.right) && (mouse.y > Pay.coord.top && mouse.y < Pay.coord.bottom))
    				{
    
    					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['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
    }
    filesave.h

    Code:
    #include <stdio.h>
    #include <fstream>
    #include <iostream.h>
    #include <windows.h>
    #include "function.h"
    
    
    
    class LoadSave
    {
    public:
    
    int savevars(int var1[15][29], int var2[15][29], int var3[15][29], char name[])
    
    {
    	using std::ofstream;
    
    	char *t	 = new char;
    	char *t2 = new char;
    	char *t3 = new char;
    	ofstream f;
    
    
    
    	f.open(name, ios::out);
    	if (f.is_open())
    	{
    	
    
    		for(j=1;j<=28;j++)
    		{
    			for(k=1;k<=14;k++)
    			{
    				wsprintf(t,"%d",var1[k][j]);
    				f << t <<'\n';
    			}
    		}
    
    
    		for(j=1;j<=28;j++)
    		{
    			for(k=1;k<=14;k++)
    			{
    				wsprintf(t2,"%d",var2[k][j]);
    				f << t2<<'\n';
    			}
    		}
    
    		for(j=1;j<=28;j++)
    		{
    			for(k=1;k<=14;k++)
    			{
    				wsprintf(t3,"%d",var3[k][j]);
    				f << t3 << '\n';
    			}
    		}
    
    
    
    	}
    	else
    	{
    		return false;
    	}
    
    
    	return 0;
    
    
    }
    
    bool loadvars(int var1[15][29], int var2[15][29], int var3[15][29], char name[])
    {
    	using std::ifstream;
    
    	ifstream f;
        f.open(name);
        if (f.is_open())
        {
            
    
            for(j=1;j<29;j++)
            {
                for(k=1;k<15;k++)
                {
                    f >> var1[k][j]; 
                }
            }
            for(j=1;j<29;j++)
            {
                for(k=1;k<15;k++)
                {
                    f >> var2[k][j];            
                }
            }
            for(j=1;j<29;j++)
            {
                for(k=1;k<15;k++)
                {
                    f >> var3[k][j];            
                }
            }
        }
        else
        {
            return false;
        }
    
    
    
    
    
    	return true;
    
    
    }
    /////////////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////////////
    //Save/Load tickets and Total amount of money////////////////////////////////////
    
    bool SaveTic(int numtic)
    {
    	using std::ofstream;
    	ofstream savefile;
    	savefile.open("save/ticket.HC");
    
    	if(savefile.is_open())
    	{
    		savefile << numtic;
    	}
    	else
    		return false;
    
    	return true;
    
    	savefile.close();
    }
    
    bool Loadtic()
    {
    	using std::ifstream;
    	ifstream Loadfile;
    	Loadfile.open("save/ticket.HC");
    
    	if(Loadfile.is_open())
    		Loadfile >> totaltic;
    	else
    		return false;
    	return true;
    
    	Loadfile.close();
    }
    
    
    
    
    
    bool SaveAmount(float amount)
    {
    	using std::ofstream;
    	ofstream Savefile;
    	Savefile.open("save/money.HC");
    
    	if(Savefile.is_open())
    		Savefile << amount;
    	else
    		return false;
    	return true;
    	Savefile.close();
    }
    
    
    bool LoadAmount()
    {
    	using std::ifstream;
    	ifstream Loadfile;
    	Loadfile.open("save/money.HC");
    
    	if(Loadfile.is_open())
    		Loadfile >> totalprice;
    	else
    		return false;
    	return true;
    	Loadfile.close();
    }
    };
    
    LoadSave LS;
    font.h

    Code:
    #include "function.h"
    
    GLvoid BuildFont(GLvoid)								// Build Our Bitmap Font
    {
    	HFONT	font[5];										// Windows Font ID
    	HFONT	oldfont[5];									// Used For Good House Keeping
    
    	base[0] = glGenLists(96);								// Storage For 96 Characters
    	base[1] = glGenLists(96);
    	base[2] = glGenLists(96);
    	base[3] = glGenLists(96);
    
    	font[0] = CreateFont(-12,							// Height Of Font
    						0,								// Width Of Font
    						0,								// Angle Of Escapement
    						0,								// Orientation Angle
    						FW_BOLD,						// Font Weight
    						FALSE,							// Italic
    						FALSE,							// Underline
    						FALSE,							// Strikeout
    						ANSI_CHARSET,					// Character Set Identifier
    						OUT_TT_PRECIS,					// Output Precision
    						CLIP_DEFAULT_PRECIS,			// Clipping Precision
    						ANTIALIASED_QUALITY,			// Output Quality
    						FF_DONTCARE|DEFAULT_PITCH,		// Family And Pitch
    						"Times New Roman");					// Font Name
    
    	font[1] = CreateFont(	-24,							// Height Of Font
    						0,								// Width Of Font
    						0,								// Angle Of Escapement
    						0,								// Orientation Angle
    						FW_BOLD,						// Font Weight
    						FALSE,							// Italic
    						FALSE,							// Underline
    						FALSE,							// Strikeout
    						ANSI_CHARSET,					// Character Set Identifier
    						OUT_TT_PRECIS,					// Output Precision
    						CLIP_DEFAULT_PRECIS,			// Clipping Precision
    						ANTIALIASED_QUALITY,			// Output Quality
    						FF_DONTCARE|DEFAULT_PITCH,		// Family And Pitch
    						"Times New Roman");					// Font Name
    
    	font[2] = CreateFont(	-16,							// Height Of Font
    						0,								// Width Of Font
    						0,								// Angle Of Escapement
    						0,								// Orientation Angle
    						FW_BOLD,						// Font Weight
    						FALSE,							// Italic
    						FALSE,							// Underline
    						FALSE,							// Strikeout
    						ANSI_CHARSET,					// Character Set Identifier
    						OUT_TT_PRECIS,					// Output Precision
    						CLIP_DEFAULT_PRECIS,			// Clipping Precision
    						ANTIALIASED_QUALITY,			// Output Quality
    						FF_DONTCARE|DEFAULT_PITCH,		// Family And Pitch
    						"Arial");					// Font Name
    
    
    	font[3] = CreateFont(	-24,							// Height Of Font
    						0,								// Width Of Font
    						0,								// Angle Of Escapement
    						0,								// Orientation Angle
    						FW_BOLD,						// Font Weight
    						FALSE,							// Italic
    						FALSE,							// Underline
    						FALSE,							// Strikeout
    						ANSI_CHARSET,					// Character Set Identifier
    						OUT_TT_PRECIS,					// Output Precision
    						CLIP_DEFAULT_PRECIS,			// Clipping Precision
    						ANTIALIASED_QUALITY,			// Output Quality
    						FF_DONTCARE|DEFAULT_PITCH,		// Family And Pitch
    						"Arial");					// Font Name
    
    
    
    
    	for(j = 0; j<=3; j++)
    	{
    	oldfont[j] = (HFONT)SelectObject(hDC, font[j]);           // Selects The Font We Want
    	wglUseFontBitmaps(hDC, 32, 96, base[j]);				// Builds 96 Characters Starting At Character 32
    	SelectObject(hDC, oldfont[j]);							// Selects The Font We Want
    	DeleteObject(font[j]);	// Delete The Font
    	}
    }
    
    GLvoid KillFont(GLvoid)									// Delete The Font List
    {
    	glDeleteLists(base[0], 96);							// Delete All 96 Characters
    }
    
    
    
    
    class Buttons
    {
    public:
    
    	struct Coords
    	{
    	float left, top, right, bottom;
    	float Color, Color2;
    	bool active;
    	};
    
    	Coords coord;
    
    	void Create(float xCor, float yCor, char *Name)
    	{
    		coord.left = xCor;
    		coord.top = yCor;
    		coord.right = coord.left+70;
    		coord.bottom = coord.top+20;
    
    		glLoadIdentity();
    		glColor4f(1, 1, 1, 1);
    		glPrint(0, coord.left+15, coord.top+15, Name);
    
    		glLoadIdentity();
    		glEnable(GL_TEXTURE_2D);
    		glBegin(GL_QUADS);
    
    		if(coord.active)
    			glColor4f(1, 0, 1, 1);
    		else
    			glColor4f( 1, coord.Color2, 1, coord.Color);
    
    		
    			glBindTexture(GL_TEXTURE_2D, texture[3]);
    
    			glTexCoord2d(0, 0); 	glVertex2d(coord.left, coord.top);
    			glTexCoord2d(1, 0); 	glVertex2d(coord.right, coord.top);
    			glTexCoord2d(1, 1); 	glVertex2d(coord.right, coord.bottom);
    			glTexCoord2d(0, 1); 	glVertex2d(coord.left, coord.bottom);
    		
    
    		glEnd();
    	glDisable(GL_TEXTURE_2D);
    
    
    	}
    };
    
    Buttons Button[10], Pay;
    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>
    
    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 menu = TRUE;
    
    GLuint texture[5];
    GLuint box;
    GLuint button0, button1, button2;
    GLuint MouseQuad;
    GLuint MenuText;
    GLuint ProgramText;
    GLuint colors0, colors1;
    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
    int SeatTemp[3][15][29];
    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"};
    char CSeat[5];
    bool ShowNameActive = false;
    bool ticketPriceActive = false;
    bool ShowDateActive = false;
    char ShowName[100];
    char ticketPrice[10];
    char ShowDate[100];
    float ticketprice = 1.5;// = atof(ticketPrice);
    
    GLvoid glPrint(int f, float x, float y, const char *fmt, ...)					// Custom GL "Print" Routine
    {
    	char		text[256];								// Holds Our String
    	va_list		ap;										// Pointer To List Of Arguments
    
    	if (fmt == NULL)									// If There's No Text
    		return;											// Do Nothing
    
    	va_start(ap, fmt);									// Parses The String For Variables
    	    vsprintf(text, fmt, ap);						// And Converts Symbols To Actual Numbers
    	va_end(ap);											// Results Are Stored In Text
    
    	glPushAttrib(GL_LIST_BIT);							// Pushes The Display List Bits
    	if(f == 0)
    	glListBase(base[0] - 32);								// Sets The Base Character to 32
    
    	if(f==1)
    	glListBase(base[1] - 32);
    	if(f==2)
    	glListBase(base[2] - 32);
    	if(f==3)
    	glListBase(base[3] - 32);
    
    
    	glLoadIdentity();
    	glTranslatef(x, y, -10.0f);
    	glRasterPos2f(0, 0);
    	glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);	// Draws The Display List Text
    	glPopAttrib();										// Pops The Display List Bits
    }
    void BuildList()
    {
    	box = glGenLists(1);
    	glNewList(box, GL_COMPILE);
    				glBegin(GL_QUADS);
    				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();
    	glEndList();
    		button0 = glGenLists(2);
    	glNewList(button0, GL_COMPILE);
    				glLoadIdentity();
    			glColor4f(1, 1, 1, 0.3f);				
    			glBegin(GL_QUADS);
    				glVertex2f(150, 85);
    				glVertex2f(400, 85);
    				glVertex2f(400, 105);
    				glVertex2f(150, 105);
    			glEnd();
    	glEndList();
    		button1 = glGenLists(3);
    	glNewList(button1, GL_COMPILE);
    			glBegin(GL_QUADS);
    				glVertex2f(150, 115);
    				glVertex2f(400, 115);
    				glVertex2f(400, 135);
    				glVertex2f(150, 135);
    			glEnd();
    	glEndList();
    		button2 = glGenLists(4);
    	glNewList(button2, GL_COMPILE);
    			glBegin(GL_QUADS);
    				glVertex2f(150, 145);
    				glVertex2f(400, 145);
    				glVertex2f(400, 165);
    				glVertex2f(150, 165);
    			glEnd();
    	glEndList();
    			MouseQuad = glGenLists(5);
    	glNewList(MouseQuad, GL_COMPILE);
    		glEnable(GL_TEXTURE_2D);
    		glBindTexture(GL_TEXTURE_2D, texture[3]);
    
    		glBegin(GL_QUADS);
    		glColor4f(1, 1, 1, 1);
    			glTexCoord2f(1, 1);	glVertex2f(0, 0);
    			glTexCoord2f(1, 0);	glVertex2f(20, 0);
    			glTexCoord2f(0, 0);	glVertex2f(20, 20);
    			glTexCoord2f(0, 1);	glVertex2f(0, 20);
    		glEnd();
    		glDisable(GL_TEXTURE_2D);
    	glEndList();
    		colors0 = glGenLists(6);
    	glNewList(colors0, GL_COMPILE);
    					glColor3f(1, 0, 0);
    	glEndList();	
    	colors1 = glGenLists(7);
    	glNewList(colors1, GL_COMPILE);
    				glColor4f(0.0f,1.0f,0.0f, 0.7f);
    	glEndList();
    
    	MenuText = glGenLists(7);
    	glNewList(MenuText, GL_COMPILE);
    			glPrint(2, 50, 100, "Show Name");
    			glPrint(2, 50, 130, "Show Date");
    			glPrint(2, 50, 160, "Ticket Price");
    	glEndList();
    
    	ProgramText = glGenLists(8);
    	glNewList(ProgramText, GL_COMPILE);
    			
    	glEndList();
    }
    
    /*
    void DrawSquare(int left, int top, int right, int bottom)
    {
    	glBegin(GL_LINES);
    	glColor4f(1, 1, 1, 1);
    	glVertex2d(left, top);
    	glVertex2d(right, top);
    
    	glVertex2d(right, top);
    	glVertex2d(right, bottom);
    
    	glVertex2d(right, bottom);
    	glVertex2d(left, bottom);
    
    	glVertex2d(left, bottom);
    	glVertex2d(left, top);
    	glEnd();
    
    
    }
    
    
    void DrawGrid(int left, int top, int right, int bottom, int w, int h)
    {
    	for(int i=left; i<right; i+= w)
    	{
    		for(int o=top; o<bottom; o+= h)
    		{
    			DrawSquare(i,o,i+w,o+h );
    		}
    	}
    }
    */
    
    //---------------------------------------------------------------------\
    //					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)
    				{
    					glCallList(colors0);
    				}else
    				{
    					glCallList(colors1);			
    				}
    					glCallList(box);
    				}
    			}	
    		}
    
    
    		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)
    				{
    					glCallList(colors0);
    				}else
    				{
    					glCallList(colors1);			
    				}	
    					glCallList(box);
    				}
    			}	
    		}
    
    		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)
    				{
    					glCallList(colors0);
    				}else
    				{
    					glCallList(colors1);		
    				}
    					glCallList(box);
    				}
    			}	
    		}
    
    
    	}
    };
    
    Nights n[3];
    
    //------------------------------------------------------------------------------------------------\
    //		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;
    		}
    	}
    /////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////
    
    #endif
    texture.h

    Code:
    #include "header\function.h"
    
    
    AUX_RGBImageRec *Loadbmp(char *name)
    {
    
    	FILE *file = NULL;
    
    	if(!name)
    		return NULL;
    
    	file=fopen(name, "r");
    
    	if(file)
    	{
    
    		fclose(file);
    		return auxDIBImageLoad(name);
    
    	}
    	return NULL;
    
    }
    
    int getTex()
    {
    
    	int stat = false;
    
    	AUX_RGBImageRec *texImage[4];
    
    	memset(texImage,0,sizeof(void *)*4);
    
    	if((texImage[0] = Loadbmp("graphic/3.bmp"))&&
    	   (texImage[1] = Loadbmp("graphic/b1.bmp"))&&
    	   (texImage[2] = Loadbmp("graphic/b2.bmp")) &&
    	   (texImage[3] = Loadbmp("graphic/mouse.bmp")))
    	{
    		stat = true;
    
    		glGenTextures(4, &texture[0]);
    
    		for(l=0; l<4; l++)
    		{
    		glBindTexture(GL_TEXTURE_2D, texture[l]);
    
    		glTexImage2D(GL_TEXTURE_2D, 0, 3, texImage[l]->sizeX, texImage[l]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texImage[l]->data);
    
    		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    	}}
    	for(l=0; l<4; l++)
    	{
    		if(texImage[l])
    		{
    			if(texImage[l]->data)
    			{
    				free(texImage[l]->data);
    			}
    			free(texImage[l]);
    		}
    	}
    		return stat;
    
    }
    Window.h


    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 "function.h"
    
    
    
    LRESULT	CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);	// Declaration For WndProc
    
    
    GLvoid ReSizeGLScene(GLsizei width, GLsizei height)		// Resize And Initialize The GL Window
    {
    	if (height==0)										// Prevent A Divide By Zero By
    	{
    		height=1;										// Making Height Equal One
    	}
    
    	glViewport(0,0,width,height);						// Reset The Current Viewport
    
    	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
    	glLoadIdentity();									// Reset The Projection Matrix
    
    	glOrtho(0.0f, 800, 600, 0.0f, -10.0f, 10.0f);
    	glMatrixMode(GL_MODELVIEW);							// Select The Modelview Matrix
    	glLoadIdentity();									// Reset The Modelview Matrix
    }
    
    int InitGL(GLvoid);
    
    
    GLvoid KillGLWindow(GLvoid)								// Properly Kill The Window
    {
    	if (fullscreen)										// Are We In Fullscreen Mode?
    	{
    		ChangeDisplaySettings(NULL,0);					// If So Switch Back To The Desktop
    		ShowCursor(TRUE);								// Show Mouse Pointer
    	}
    
    	if (hRC)											// Do We Have A Rendering Context?
    	{
    		if (!wglMakeCurrent(NULL,NULL))					// Are We Able To Release The DC And RC Contexts?
    		{
    			MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
    		}
    
    		if (!wglDeleteContext(hRC))						// Are We Able To Delete The RC?
    		{
    			MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
    		}
    		hRC=NULL;										// Set RC To NULL
    	}
    
    	if (hDC && !ReleaseDC(hWnd,hDC))					// Are We Able To Release The DC
    	{
    		MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
    		hDC=NULL;										// Set DC To NULL
    	}
    
    	if (hWnd && !DestroyWindow(hWnd))					// Are We Able To Destroy The Window?
    	{
    		MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
    		hWnd=NULL;										// Set hWnd To NULL
    	}
    
    	if (!UnregisterClass("OpenGL",hInstance))			// Are We Able To Unregister Class
    	{
    		MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
    		hInstance=NULL;									// Set hInstance To NULL
    	}
    }
    
    /*	This Code Creates Our OpenGL Window.  Parameters Are:					*
     *	title			- Title To Appear At The Top Of The Window				*
     *	width			- Width Of The GL Window Or Fullscreen Mode				*
     *	height			- Height Of The GL Window Or Fullscreen Mode			*
     *	bits			- Number Of Bits To Use For Color (8/16/24/32)			*
     *	fullscreenflag	- Use Fullscreen Mode (TRUE) Or Windowed Mode (FALSE)	*/
     
    
    BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
    {
    	GLuint		PixelFormat;			// Holds The Results After Searching For A Match
    	WNDCLASS	wc;						// Windows Class Structure
    	DWORD		dwExStyle;				// Window Extended Style
    	DWORD		dwStyle;				// Window Style
    	RECT		WindowRect;				// Grabs Rectangle Upper Left / Lower Right Values
    	WindowRect.left=(long)0;			// Set Left Value To 0
    	WindowRect.right=(long)width;		// Set Right Value To Requested Width
    	WindowRect.top=(long)0;				// Set Top Value To 0
    	WindowRect.bottom=(long)height;		// Set Bottom Value To Requested Height
    
    	fullscreen=fullscreenflag;			// Set The Global Fullscreen Flag
    
    	hInstance			= GetModuleHandle(NULL);				// Grab An Instance For Our Window
    	wc.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;	// Redraw On Size, And Own DC For Window.
    	wc.lpfnWndProc		= (WNDPROC) WndProc;					// WndProc Handles Messages
    	wc.cbClsExtra		= 0;									// No Extra Window Data
    	wc.cbWndExtra		= 0;									// No Extra Window Data
    	wc.hInstance		= hInstance;							// Set The Instance
    	wc.hIcon			= LoadIcon(NULL, IDI_WINLOGO);			// Load The Default Icon
    	wc.hCursor			= LoadCursor(NULL, IDC_ARROW);			// Load The Arrow Pointer
    	wc.hbrBackground	= NULL;									// No Background Required For GL
    	wc.lpszMenuName		= NULL;									// We Don't Want A Menu
    	wc.lpszClassName	= "OpenGL";								// Set The Class Name
    
    	if (!RegisterClass(&wc))									// Attempt To Register The Window Class
    	{
    		MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
    		return FALSE;											// Return FALSE
    	}
    	
    	if (fullscreen)												// Attempt Fullscreen Mode?
    	{
    		DEVMODE dmScreenSettings;								// Device Mode
    		memset(&dmScreenSettings,0,sizeof(dmScreenSettings));	// Makes Sure Memory's Cleared
    		dmScreenSettings.dmSize=sizeof(dmScreenSettings);		// Size Of The Devmode Structure
    		dmScreenSettings.dmPelsWidth	= width;				// Selected Screen Width
    		dmScreenSettings.dmPelsHeight	= height;				// Selected Screen Height
    		dmScreenSettings.dmBitsPerPel	= bits;					// Selected Bits Per Pixel
    		dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
    
    		// Try To Set Selected Mode And Get Results.  NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
    		if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
    		{
    			// If The Mode Fails, Offer Two Options.  Quit Or Use Windowed Mode.
    			if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
    			{
    				fullscreen=FALSE;		// Windowed Mode Selected.  Fullscreen = FALSE
    			}
    			else
    			{
    				// Pop Up A Message Box Letting User Know The Program Is Closing.
    				MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP);
    				return FALSE;									// Return FALSE
    			}
    		}
    	}
    
    	if (fullscreen)												// Are We Still In Fullscreen Mode?
    	{
    		dwExStyle=WS_EX_APPWINDOW;								// Window Extended Style
    		dwStyle=WS_POPUP;										// Windows Style
    		ShowCursor(FALSE);										// Hide Mouse Pointer
    	}
    	else
    	{
    		dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;			// Window Extended Style
    		dwStyle=WS_OVERLAPPEDWINDOW;							// Windows Style
    	}
    
    	AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);		// Adjust Window To True Requested Size
    
    	// Create The Window
    	if (!(hWnd=CreateWindowEx(	dwExStyle,							// Extended Style For The Window
    								"OpenGL",							// Class Name
    								title,								// Window Title
    								dwStyle |							// Defined Window Style
    								WS_CLIPSIBLINGS |					// Required Window Style
    								WS_CLIPCHILDREN,					// Required Window Style
    								0, 0,								// Window Position
    								WindowRect.right-WindowRect.left,	// Calculate Window Width
    								WindowRect.bottom-WindowRect.top,	// Calculate Window Height
    								NULL,								// No Parent Window
    								NULL,								// No Menu
    								hInstance,							// Instance
    								NULL)))								// Dont Pass Anything To WM_CREATE
    	{
    		KillGLWindow();								// Reset The Display
    		MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
    		return FALSE;								// Return FALSE
    	}
    
    	static	PIXELFORMATDESCRIPTOR pfd=				// pfd Tells Windows How We Want Things To Be
    	{
    		sizeof(PIXELFORMATDESCRIPTOR),				// Size Of This Pixel Format Descriptor
    		1,											// Version Number
    		PFD_DRAW_TO_WINDOW |						// Format Must Support Window
    		PFD_SUPPORT_OPENGL |						// Format Must Support OpenGL
    		PFD_DOUBLEBUFFER,							// Must Support Double Buffering
    		PFD_TYPE_RGBA,								// Request An RGBA Format
    		bits,										// Select Our Color Depth
    		0, 0, 0, 0, 0, 0,							// Color Bits Ignored
    		0,											// No Alpha Buffer
    		0,											// Shift Bit Ignored
    		0,											// No Accumulation Buffer
    		0, 0, 0, 0,									// Accumulation Bits Ignored
    		16,											// 16Bit Z-Buffer (Depth Buffer)  
    		0,											// No Stencil Buffer
    		0,											// No Auxiliary Buffer
    		PFD_MAIN_PLANE,								// Main Drawing Layer
    		0,											// Reserved
    		0, 0, 0										// Layer Masks Ignored
    	};
    	
    	if (!(hDC=GetDC(hWnd)))							// Did We Get A Device Context?
    	{
    		KillGLWindow();								// Reset The Display
    		MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
    		return FALSE;								// Return FALSE
    	}
    
    	if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))	// Did Windows Find A Matching Pixel Format?
    	{
    		KillGLWindow();								// Reset The Display
    		MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
    		return FALSE;								// Return FALSE
    	}
    
    	if(!SetPixelFormat(hDC,PixelFormat,&pfd))		// Are We Able To Set The Pixel Format?
    	{
    		KillGLWindow();								// Reset The Display
    		MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
    		return FALSE;								// Return FALSE
    	}
    
    	if (!(hRC=wglCreateContext(hDC)))				// Are We Able To Get A Rendering Context?
    	{
    		KillGLWindow();								// Reset The Display
    		MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
    		return FALSE;								// Return FALSE
    	}
    
    	if(!wglMakeCurrent(hDC,hRC))					// Try To Activate The Rendering Context
    	{
    		KillGLWindow();								// Reset The Display
    		MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
    		return FALSE;								// Return FALSE
    	}
    
    	ShowWindow(hWnd,SW_SHOW);						// Show The Window
    	SetForegroundWindow(hWnd);						// Slightly Higher Priority
    	SetFocus(hWnd);									// Sets Keyboard Focus To The Window
    	ReSizeGLScene(width, height);					// Set Up Our Perspective GL Screen
    
    	if (!InitGL())									// Initialize Our Newly Created GL Window
    	{
    		KillGLWindow();								// Reset The Display
    		MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
    		return FALSE;								// Return FALSE
    	}
    
    	return TRUE;									// Success
    }
    
    
    
    
    
    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
    There it is, we'll see what you guys have to say.... don't say its the loops, its not, i fixed the render issue with the display lists, its no longer creating the quads on the fly.....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SMS sample code
    By hagenuk in forum C Programming
    Replies: 1
    Last Post: 05-30-2008, 11:47 AM
  2. Sample code please help!!!
    By aewing30 in forum C Programming
    Replies: 6
    Last Post: 05-29-2008, 10:51 AM
  3. The code sample of classes in the tutorial. :o
    By Wall in forum C++ Programming
    Replies: 3
    Last Post: 08-20-2004, 09:18 AM
  4. looking for book with sample code
    By stella in forum C++ Programming
    Replies: 5
    Last Post: 06-25-2003, 10:48 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM