/*
* This Code Was Created By Jeff Molofee 2000
* A HUGE Thanks To Fredric Echols For Cleaning Up
* And Optimizing This Code, Making It More Flexible!
* If You've Found This Code Useful, Please Let Me Know.
* Visit My Site At nehe.gamedev.net
*/
#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 <stdio.h>
#include <math.h>
#include <string.h>
#define PT 1
#define STROKE 2
#define END 3
#define PI 3.1415926
typedef struct charpoint {
GLfloat x, y;
int type;
} CP;
CP Pdata[] = {
{0, 0, PT}, {0, 10, PT}, {4, 10, PT}, {5, 9, PT}, {5, 6, PT},
{4, 5, PT}, {0, 5, END}
};
CP Rdata[] = {
{0, 0, PT}, {0, 10, PT}, {4, 10, PT}, {5, 9, PT}, {5, 6, PT},
{4, 5, PT}, {0, 5, STROKE}, {3, 5, PT}, {5, 0, END}
};
CP Ddata[] = {
{0, 0, PT}, {0, 10, PT}, {4, 10, PT}, {6, 8, PT},
{6, 2, PT}, {4, 0, PT},{0, 0, END}
};
CP Odata[] = {{0, 2, PT},{0, 8, PT},{2, 10, PT},{4, 10, PT},{6, 8, PT},{6, 2, PT},{4, 0, PT},
{2, 0, PT},{0, 2,END }
};
CP Tdata[] = {
{0, 10, PT}, {6, 10, STROKE}, {3, 10, PT}, {3, 0, PT},{3, 0, END}
};
CP Ndata[] = {
{0, 0, PT}, {0, 10, PT},{6, 0, PT}, {6, 10, PT}, {6, 10, END}
};
CP Adata[] = {
{ 0, 0, PT}, {0, 9, PT}, {1, 10, PT}, {4, 10, PT},
{5, 9, PT}, {5, 0, STROKE}, {0, 5, PT}, {5, 5, END}
};
CP Edata[] = {
{5, 0, PT}, {0, 0, PT}, {0, 10, PT}, {5, 10, STROKE},
{0, 5, PT}, {4, 5, END}
};
CP Sdata[] = {
{0, 1, PT}, {1, 0, PT}, {4, 0, PT}, {5, 1, PT}, {5, 4, PT},
{4, 5, PT}, {1, 5, PT}, {0, 6, PT}, {0, 9, PT}, {1, 10, PT},
{4, 10, PT}, {5, 9, END}
};
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
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
GLuint texture[3], texture_one[3], texture_container[3], CubeMap[6];
GLuint cubeface[6];
GLuint base;
bool flag = true;
const int recwidth = 180;
const int recheight = 180;
const float alpha = 1.0;
float xdistance = 0.0;
float ydistance = 0.0;
int stoneweight = 8;
int stonesize = 4;
int eyex = 0, eyez = 0.0, eyey = 0;
float angle = 90.0;
float eyePosition[3];
GLfloat vertices[3*recheight*recwidth];
GLfloat texcoords[2*recheight*recwidth];
GLfloat waterbottomcoords[2*recheight*recwidth];
GLfloat bottomvertices[3*recheight*recwidth];
GLfloat normals[3*recheight*recwidth];
GLfloat vertices2[3*recheight*recwidth] ;
GLfloat waterbottomcoords2[2*recheight*recwidth];
GLfloat *display = vertices;
GLfloat *current = vertices2;
GLfloat xpos, ypos;
float waterwidth = 30.0;
bool bdrop = false;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
float angle_x(45.0f);
float angle_y(45.0f);
const int NodesOfT = 20;
double t = 0 ;
void sinewave(void)
{
static bool init = false;
t=(int
)(t+PI/60)%60;
if(!init)
{
for(int j=2; j<recheight-2; j++)
for (int i=2; i<recwidth-2; i++)
{
int offset = j*recwidth + i;
display[3*offset + 2] = sin(i*2*PI/NodesOfT);
}
init = true;
}
else
{
for(int j=2; j<recheight-2; j++)
for (int i=2; i<recwidth-2; i++)
{
int offset = j*recwidth + i;
current[3*offset + 2] = sin(i*2*PI/NodesOfT+t);
}
}
GLfloat *ptmp =display;
display = current;
current = ptmp;
}
static void printStrokedString(char *s)
{
GLsizei len = strlen(s);
glCallLists(len, GL_BYTE, (GLbyte *)s);
}
static void drawLetter(CP *l)
{
glBegin(GL_LINE_STRIP);
while (1) {
switch (l->type) {
case PT:
glVertex2fv(&l->x);
break;
case STROKE:
glVertex2fv(&l->x);
glEnd();
glBegin(GL_LINE_STRIP);
break;
case END:
glVertex2fv(&l->x);
glEnd();
glTranslatef(8.0, 0.0, 0.0);
return;
}
l++;
}
}
void DrawWaterBottom(void)
{
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, bottomvertices);
glTexCoordPointer(2, GL_FLOAT, 0, waterbottomcoords);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture_container[2]);
glPushMatrix();
glTranslatef(0.0, 0.0, 4.0);
for(int j=0;j<recheight-1;j++)
{
glNormal3f(0.0, 0.0, 1.0);
glBegin(GL_QUAD_STRIP);
for(int i=0;i<recwidth ;i++)
{
glArrayElement((j+1)*recwidth+i);
glArrayElement(j*recwidth+i);
}
glEnd();
}
glPopMatrix();
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
void drawwater(void)
{
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, display);
glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
glNormalPointer(GL_FLOAT,0 ,normals);
glColor3f(1.0f, 1.0f, 1.0f);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_COLOR, GL_ONE);
glEnable(GL_TEXTURE_GEN_S); // Enable Texture Coord Generation For S (NEW)
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, CubeMap[2]);
glPushMatrix();
glRotatef(270, 1.0, 0.0, 0.0);
glTranslatef(0.0, 0.0, 7.0);
//for(int j=0;j<recheight-1;j++)
//{
// glBegin(GL_QUAD_STRIP);
// for(int i=0;i<recwidth ;i++)
// {
// glArrayElement((j+1)*recwidth+i);
// glArrayElement(j*recwidth+i);
// }
// glEnd();
//}
for(int j=0;j<recheight-1;j++)
{
glBegin(GL_LINE_STRIP);
for(int i=0;i<recwidth ;i++)
{
glArrayElement(j*recwidth+i);
}
glEnd();
}
glPopMatrix();
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
}
void AdjustViewByMouse()
{
static int mouse_x=0;
static int mouse_y=0;
if(fullscreen == true)
{
POINT newpos;
GetCursorPos(&newpos);
angle_x+=(newpos.y - mouse_y)/360.0f;
angle_y+=(newpos.x - mouse_x)/360.0f;
if(angle_x>3.14159f/2.0f) angle_x=3.14159f/2.0f;
if(angle_x<-3.14159f/2.0f) angle_x=-3.14159f/2.0f;
SetCursorPos(320, 240);
}
if(GetAsyncKeyState(VK_LBUTTON))
{
POINT newpos;
GetCursorPos(&newpos);
angle_x+=(newpos.y - mouse_y)/360.0f;
angle_y+=(newpos.x - mouse_x)/360.0f;
//confine the movement
if(angle_x>3.14159f/2.0f) angle_x=3.14159f/2.0f;
if(angle_x<-3.14159f/2.0f) angle_x=-3.14159f/2.0f;
}
POINT pos;
GetCursorPos(&pos);
mouse_x=pos.x;
mouse_y=pos.y;
}
void CubeBox()
{
float cubewidth = 1000.0;
glDisable(GL_LIGHTING);
glColor3f(1.0f, 1.0f, 1.0f);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, CubeMap[0]);
glBegin(GL_QUADS);
glTexCoord2f(0, 1); glVertex3f(cubewidth, cubewidth, cubewidth);
glTexCoord2f(0, 0); glVertex3f(cubewidth, -cubewidth, cubewidth);
glTexCoord2f(1, 0); glVertex3f(cubewidth, -cubewidth, -cubewidth);
glTexCoord2f(1, 1); glVertex3f(cubewidth, cubewidth, -cubewidth);
glEnd();
glBindTexture(GL_TEXTURE_2D, CubeMap[1]);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 1.0); glVertex3f(-cubewidth, cubewidth, -cubewidth);
glTexCoord2f(0.0, 0.0); glVertex3f(-cubewidth, -cubewidth, -cubewidth);
glTexCoord2f