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