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.....