#include #include #include #include #include #include #include using namespace std; HDC hDC=NULL; HGLRC hRC=NULL; HWND hWnd=NULL; HINSTANCE hInstance; bool keys[256]; bool active=TRUE; bool fullscreen=TRUE; bool movy1=false; bool movy2=false; bool movx1=false; bool movx2=false; GLfloat rtri; // Pöördenurk GLfloat rquad; // Pöördenurk GLfloat movx; // Liikumine GLfloat movy; // Liikumine //kabe GLfloat xpos[64]={0.0f,1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f,0.0f,1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f,0.0f,1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f,0.0f,1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f,0.0f,1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f,0.0f,1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f,0.0f,1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f,0.0f,1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f}; GLfloat ypos[64]={2.0f,2.0f,2.0f,2.0f,2.0f,2.0f,2.0f,2.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,-1.0f,-1.0f,-1.0f,-1.0f,-1.0f,-1.0f,-1.0f,-1.0f,-2.0f,-2.0f,-2.0f,-2.0f,-2.0f,-2.0f,-2.0f,-2.0f,-3.0f,-3.0f,-3.0f,-3.0f,-3.0f,-3.0f,-3.0f,-3.0f,-4.0f,-4.0f,-4.0f,-4.0f,-4.0f,-4.0f,-4.0f,-4.0f,-5.0f,-5.0f,-5.0f,-5.0f,-5.0f,-5.0f,-5.0f,-5.0f}; GLfloat col; GLfloat cols=0.0f; string laud; int v=0,m=0; int pr; void myhed(); void vyhed(); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); GLvoid ReSizeGLScene(GLsizei width, GLsizei height) { if (height==0) { height=1; } glViewport(0,0,width,height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int InitGL(GLvoid) { glShadeModel(GL_SMOOTH); glClearColor(0.5f, 0.5f, 0.5f, 0.0f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); return TRUE; } int DrawGLScene(GLvoid) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(2.0f,0.0f,-10.0f); glBegin(GL_QUADS); ///////////////////////////// // MUSTAD RUUDUD // ///////////////////////////// glColor3f(0.0f,0.0f,0.0f); //esimene rida glVertex3f(-4.0f, 4.0f, 0.0f); glVertex3f(-3.0f, 4.0f, 0.0f); glVertex3f(-3.0f, 3.0f, 0.0f); glVertex3f(-4.0f, 3.0f, 0.0f); glVertex3f(-2.0f, 4.0f, 0.0f); glVertex3f(-1.0f, 4.0f, 0.0f); glVertex3f(-1.0f, 3.0f, 0.0f); glVertex3f(-2.0f, 3.0f, 0.0f); glVertex3f( 0.0f, 4.0f, 0.0f); glVertex3f( 1.0f, 4.0f, 0.0f); glVertex3f( 1.0f, 3.0f, 0.0f); glVertex3f( 0.0f, 3.0f, 0.0f); glVertex3f( 2.0f, 4.0f, 0.0f); glVertex3f( 3.0f, 4.0f, 0.0f); glVertex3f( 3.0f, 3.0f, 0.0f); glVertex3f( 2.0f, 3.0f, 0.0f); //teine rida glVertex3f(-5.0f, 3.0f, 0.0f); glVertex3f(-4.0f, 3.0f, 0.0f); glVertex3f(-4.0f, 2.0f, 0.0f); glVertex3f(-5.0f, 2.0f, 0.0f); glVertex3f(-3.0f, 3.0f, 0.0f); glVertex3f(-2.0f, 3.0f, 0.0f); glVertex3f(-2.0f, 2.0f, 0.0f); glVertex3f(-3.0f, 2.0f, 0.0f); glVertex3f(-1.0f, 3.0f, 0.0f); glVertex3f( 0.0f, 3.0f, 0.0f); glVertex3f( 0.0f, 2.0f, 0.0f); glVertex3f(-1.0f, 2.0f, 0.0f); glVertex3f( 1.0f, 3.0f, 0.0f); glVertex3f( 2.0f, 3.0f, 0.0f); glVertex3f( 2.0f, 2.0f, 0.0f); glVertex3f( 1.0f, 2.0f, 0.0f); //kolmas rida glVertex3f(-4.0f, 2.0f, 0.0f); glVertex3f(-3.0f, 2.0f, 0.0f); glVertex3f(-3.0f, 1.0f, 0.0f); glVertex3f(-4.0f, 1.0f, 0.0f); glVertex3f(-2.0f, 2.0f, 0.0f); glVertex3f(-1.0f, 2.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glVertex3f(-2.0f, 1.0f, 0.0f); glVertex3f( 0.0f, 2.0f, 0.0f); glVertex3f( 1.0f, 2.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glVertex3f( 0.0f, 1.0f, 0.0f); glVertex3f( 2.0f, 2.0f, 0.0f); glVertex3f( 3.0f, 2.0f, 0.0f); glVertex3f( 3.0f, 1.0f, 0.0f); glVertex3f( 2.0f, 1.0f, 0.0f); //neljas rida glVertex3f(-5.0f, 1.0f, 0.0f); glVertex3f(-4.0f, 1.0f, 0.0f); glVertex3f(-4.0f, 0.0f, 0.0f); glVertex3f(-5.0f, 0.0f, 0.0f); glVertex3f(-3.0f, 1.0f, 0.0f); glVertex3f(-2.0f, 1.0f, 0.0f); glVertex3f(-2.0f, 0.0f, 0.0f); glVertex3f(-3.0f, 0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glVertex3f( 0.0f, 1.0f, 0.0f); glVertex3f( 0.0f, 0.0f, 0.0f); glVertex3f(-1.0f, 0.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glVertex3f( 2.0f, 1.0f, 0.0f); glVertex3f( 2.0f, 0.0f, 0.0f); glVertex3f( 1.0f, 0.0f, 0.0f); //viies rida glVertex3f(-4.0f, 0.0f, 0.0f); glVertex3f(-3.0f, 0.0f, 0.0f); glVertex3f(-3.0f,-1.0f, 0.0f); glVertex3f(-4.0f,-1.0f, 0.0f); glVertex3f(-2.0f, 0.0f, 0.0f); glVertex3f(-1.0f, 0.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glVertex3f(-2.0f,-1.0f, 0.0f); glVertex3f( 0.0f, 0.0f, 0.0f); glVertex3f( 1.0f, 0.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glVertex3f( 0.0f,-1.0f, 0.0f); glVertex3f( 2.0f, 0.0f, 0.0f); glVertex3f( 3.0f, 0.0f, 0.0f); glVertex3f( 3.0f,-1.0f, 0.0f); glVertex3f( 2.0f,-1.0f, 0.0f); //kuues rida glVertex3f(-5.0f,-1.0f, 0.0f); glVertex3f(-4.0f,-1.0f, 0.0f); glVertex3f(-4.0f,-2.0f, 0.0f); glVertex3f(-5.0f,-2.0f, 0.0f); glVertex3f(-3.0f,-1.0f, 0.0f); glVertex3f(-2.0f,-1.0f, 0.0f); glVertex3f(-2.0f,-2.0f, 0.0f); glVertex3f(-3.0f,-2.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glVertex3f( 0.0f,-1.0f, 0.0f); glVertex3f( 0.0f,-2.0f, 0.0f); glVertex3f(-1.0f,-2.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glVertex3f( 2.0f,-1.0f, 0.0f); glVertex3f( 2.0f,-2.0f, 0.0f); glVertex3f( 1.0f,-2.0f, 0.0f); //seitsmes rida glVertex3f(-4.0f,-2.0f, 0.0f); glVertex3f(-3.0f,-2.0f, 0.0f); glVertex3f(-3.0f,-3.0f, 0.0f); glVertex3f(-4.0f,-3.0f, 0.0f); glVertex3f(-2.0f,-2.0f, 0.0f); glVertex3f(-1.0f,-2.0f, 0.0f); glVertex3f(-1.0f,-3.0f, 0.0f); glVertex3f(-2.0f,-3.0f, 0.0f); glVertex3f( 0.0f,-2.0f, 0.0f); glVertex3f( 1.0f,-2.0f, 0.0f); glVertex3f( 1.0f,-3.0f, 0.0f); glVertex3f( 0.0f,-3.0f, 0.0f); glVertex3f( 2.0f,-2.0f, 0.0f); glVertex3f( 3.0f,-2.0f, 0.0f); glVertex3f( 3.0f,-3.0f, 0.0f); glVertex3f( 2.0f,-3.0f, 0.0f); //kaheksas rida glVertex3f(-5.0f,-3.0f, 0.0f); glVertex3f(-4.0f,-3.0f, 0.0f); glVertex3f(-4.0f,-4.0f, 0.0f); glVertex3f(-5.0f,-4.0f, 0.0f); glVertex3f(-3.0f,-3.0f, 0.0f); glVertex3f(-2.0f,-3.0f, 0.0f); glVertex3f(-2.0f,-4.0f, 0.0f); glVertex3f(-3.0f,-4.0f, 0.0f); glVertex3f(-1.0f,-3.0f, 0.0f); glVertex3f( 0.0f,-3.0f, 0.0f); glVertex3f( 0.0f,-4.0f, 0.0f); glVertex3f(-1.0f,-4.0f, 0.0f); glVertex3f( 1.0f,-3.0f, 0.0f); glVertex3f( 2.0f,-3.0f, 0.0f); glVertex3f( 2.0f,-4.0f, 0.0f); glVertex3f( 1.0f,-4.0f, 0.0f); ////////////////////////////// // VALGED RUUDUD // ////////////////////////////// glColor3f(1.0f,1.0f,1.0f); //esimene rida glVertex3f(-5.0f, 4.0f, 0.0f); glVertex3f(-4.0f, 4.0f, 0.0f); glVertex3f(-4.0f, 3.0f, 0.0f); glVertex3f(-5.0f, 3.0f, 0.0f); glVertex3f(-3.0f, 4.0f, 0.0f); glVertex3f(-2.0f, 4.0f, 0.0f); glVertex3f(-2.0f, 3.0f, 0.0f); glVertex3f(-3.0f, 3.0f, 0.0f); glVertex3f(-1.0f, 4.0f, 0.0f); glVertex3f( 0.0f, 4.0f, 0.0f); glVertex3f( 0.0f, 3.0f, 0.0f); glVertex3f(-1.0f, 3.0f, 0.0f); glVertex3f( 1.0f, 4.0f, 0.0f); glVertex3f( 2.0f, 4.0f, 0.0f); glVertex3f( 2.0f, 3.0f, 0.0f); glVertex3f( 1.0f, 3.0f, 0.0f); //teine rida glVertex3f(-4.0f, 3.0f, 0.0f); glVertex3f(-3.0f, 3.0f, 0.0f); glVertex3f(-3.0f, 2.0f, 0.0f); glVertex3f(-4.0f, 2.0f, 0.0f); glVertex3f(-2.0f, 3.0f, 0.0f); glVertex3f(-1.0f, 3.0f, 0.0f); glVertex3f(-1.0f, 2.0f, 0.0f); glVertex3f(-2.0f, 2.0f, 0.0f); glVertex3f( 0.0f, 3.0f, 0.0f); glVertex3f( 1.0f, 3.0f, 0.0f); glVertex3f( 1.0f, 2.0f, 0.0f); glVertex3f( 0.0f, 2.0f, 0.0f); glVertex3f( 2.0f, 3.0f, 0.0f); glVertex3f( 3.0f, 3.0f, 0.0f); glVertex3f( 3.0f, 2.0f, 0.0f); glVertex3f( 2.0f, 2.0f, 0.0f); //kolmas rida glVertex3f(-5.0f, 2.0f, 0.0f); glVertex3f(-4.0f, 2.0f, 0.0f); glVertex3f(-4.0f, 1.0f, 0.0f); glVertex3f(-5.0f, 1.0f, 0.0f); glVertex3f(-3.0f, 2.0f, 0.0f); glVertex3f(-2.0f, 2.0f, 0.0f); glVertex3f(-2.0f, 1.0f, 0.0f); glVertex3f(-3.0f, 1.0f, 0.0f); glVertex3f(-1.0f, 2.0f, 0.0f); glVertex3f( 0.0f, 2.0f, 0.0f); glVertex3f( 0.0f, 1.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glVertex3f( 1.0f, 2.0f, 0.0f); glVertex3f( 2.0f, 2.0f, 0.0f); glVertex3f( 2.0f, 1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 0.0f); //neljas rida glVertex3f(-4.0f, 1.0f, 0.0f); glVertex3f(-3.0f, 1.0f, 0.0f); glVertex3f(-3.0f, 0.0f, 0.0f); glVertex3f(-4.0f, 0.0f, 0.0f); glVertex3f(-2.0f, 1.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glVertex3f(-1.0f, 0.0f, 0.0f); glVertex3f(-2.0f, 0.0f, 0.0f); glVertex3f( 0.0f, 1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glVertex3f( 1.0f, 0.0f, 0.0f); glVertex3f( 0.0f, 0.0f, 0.0f); glVertex3f( 2.0f, 1.0f, 0.0f); glVertex3f( 3.0f, 1.0f, 0.0f); glVertex3f( 3.0f, 0.0f, 0.0f); glVertex3f( 2.0f, 0.0f, 0.0f); //viies rida glVertex3f(-5.0f, 0.0f, 0.0f); glVertex3f(-4.0f, 0.0f, 0.0f); glVertex3f(-4.0f,-1.0f, 0.0f); glVertex3f(-5.0f,-1.0f, 0.0f); glVertex3f(-3.0f, 0.0f, 0.0f); glVertex3f(-2.0f, 0.0f, 0.0f); glVertex3f(-2.0f,-1.0f, 0.0f); glVertex3f(-3.0f,-1.0f, 0.0f); glVertex3f(-1.0f, 0.0f, 0.0f); glVertex3f( 0.0f, 0.0f, 0.0f); glVertex3f( 0.0f,-1.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glVertex3f( 1.0f, 0.0f, 0.0f); glVertex3f( 2.0f, 0.0f, 0.0f); glVertex3f( 2.0f,-1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); //kuues rida glVertex3f(-4.0f,-1.0f, 0.0f); glVertex3f(-3.0f,-1.0f, 0.0f); glVertex3f(-3.0f,-2.0f, 0.0f); glVertex3f(-4.0f,-2.0f, 0.0f); glVertex3f(-2.0f,-1.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glVertex3f(-1.0f,-2.0f, 0.0f); glVertex3f(-2.0f,-2.0f, 0.0f); glVertex3f( 0.0f,-1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glVertex3f( 1.0f,-2.0f, 0.0f); glVertex3f( 0.0f,-2.0f, 0.0f); glVertex3f( 2.0f,-1.0f, 0.0f); glVertex3f( 3.0f,-1.0f, 0.0f); glVertex3f( 3.0f,-2.0f, 0.0f); glVertex3f( 2.0f,-2.0f, 0.0f); //seitsmes rida glVertex3f(-5.0f,-2.0f, 0.0f); glVertex3f(-4.0f,-2.0f, 0.0f); glVertex3f(-4.0f,-3.0f, 0.0f); glVertex3f(-5.0f,-3.0f, 0.0f); glVertex3f(-3.0f,-2.0f, 0.0f); glVertex3f(-2.0f,-2.0f, 0.0f); glVertex3f(-2.0f,-3.0f, 0.0f); glVertex3f(-3.0f,-3.0f, 0.0f); glVertex3f(-1.0f,-2.0f, 0.0f); glVertex3f( 0.0f,-2.0f, 0.0f); glVertex3f( 0.0f,-3.0f, 0.0f); glVertex3f(-1.0f,-3.0f, 0.0f); glVertex3f( 1.0f,-2.0f, 0.0f); glVertex3f( 2.0f,-2.0f, 0.0f); glVertex3f( 2.0f,-3.0f, 0.0f); glVertex3f( 1.0f,-3.0f, 0.0f); //kaheksas rida glVertex3f(-4.0f,-3.0f, 0.0f); glVertex3f(-3.0f,-3.0f, 0.0f); glVertex3f(-3.0f,-4.0f, 0.0f); glVertex3f(-4.0f,-4.0f, 0.0f); glVertex3f(-2.0f,-3.0f, 0.0f); glVertex3f(-1.0f,-3.0f, 0.0f); glVertex3f(-1.0f,-4.0f, 0.0f); glVertex3f(-2.0f,-4.0f, 0.0f); glVertex3f( 0.0f,-3.0f, 0.0f); glVertex3f( 1.0f,-3.0f, 0.0f); glVertex3f( 1.0f,-4.0f, 0.0f); glVertex3f( 0.0f,-4.0f, 0.0f); glVertex3f( 2.0f,-3.0f, 0.0f); glVertex3f( 3.0f,-3.0f, 0.0f); glVertex3f( 3.0f,-4.0f, 0.0f); glVertex3f( 2.0f,-4.0f, 0.0f); glEnd(); /* col=0.3f; glLoadIdentity(); glTranslatef(4.0f,1.0f,-10.0f); glBegin(GL_TRIANGLES); glColor3f(col,col,col); glVertex3f( -2.5f,2.0f, 0.0f); glVertex3f( -3.0f,1.0f, 0.0f); glVertex3f( -2.0f,1.0f, 0.0f); glEnd(); */ int j=0; for (int i=0;i!=64;i++) { if(laud[i]=='m') { col=0.3f; glLoadIdentity(); glTranslatef(xpos[i],ypos[i],-10.0f); glBegin(GL_TRIANGLES); glColor3f(col,col,col); glVertex3f( -2.5f,2.0f, 0.0f); glVertex3f( -3.0f,1.0f, 0.0f); glVertex3f( -2.0f,1.0f, 0.0f); glEnd(); } if(laud[i]=='v') { col=0.7f; glLoadIdentity(); glTranslatef(xpos[i],ypos[i],-10.0f); glBegin(GL_TRIANGLES); glColor3f(col,col,col); glVertex3f( -2.5f,2.0f, 0.0f); glVertex3f( -3.0f,1.0f, 0.0f); glVertex3f( -2.0f,1.0f, 0.0f); glEnd(); } if(laud[i]=='1') { glLoadIdentity(); glTranslatef(xpos[i],ypos[i],-10.0f); glBegin(GL_QUADS); glColor3f(0.0f,cols,0.0f); glVertex3f(-3.0f,2.0f, 0.0f); glVertex3f(-2.0f,2.0f, 0.0f); glVertex3f(-2.0f,1.0f, 0.0f); glVertex3f(-3.0f,1.0f, 0.0f); glEnd(); } if(laud[i]=='V') { glLoadIdentity(); glTranslatef(xpos[i],ypos[i],-10.0f); glBegin(GL_TRIANGLES); glColor3f(0.7f,0.7f,0.7f); glVertex3f( -3.0f,2.0f, 0.0f); glVertex3f( -2.0f,2.0f, 0.0f); glVertex3f( -2.5f,1.0f, 0.0f); glEnd(); } if(laud[i]=='M') { glLoadIdentity(); glTranslatef(xpos[i],ypos[i],-10.0f); glBegin(GL_TRIANGLES); glColor3f(0.3f,0.3f,0.3f); glVertex3f( -3.0f,2.0f, 0.0f); glVertex3f( -2.0f,2.0f, 0.0f); glVertex3f( -2.5f,1.0f, 0.0f); glEnd(); } } if(cols>0.6f)pr=1; if(cols<0.1f)pr=0; if(pr==1) cols-=0.01f; if(pr==0) cols+=0.01f; /* glLoadIdentity(); glTranslatef(-1.5f,0.0f,-6.0f); glRotatef(rtri,0.5f,1.0f,0.1f); glBegin(GL_TRIANGLES); glColor3f(1.0f,0.0f,0.0f); glVertex3f( 0.0f, 1.0f, 0.0f); glColor3f(0.0f,1.0f,0.0f); glVertex3f(-1.0f,-1.0f, 1.0f); glColor3f(0.0f,0.0f,1.0f); glVertex3f( 1.0f,-1.0f, 1.0f); glColor3f(1.0f,0.0f,0.0f); glVertex3f( 0.0f, 1.0f, 0.0f); glColor3f(0.0f,0.0f,1.0f); glVertex3f( 1.0f,-1.0f, 1.0f); glColor3f(0.0f,1.0f,0.0f); glVertex3f( 1.0f,-1.0f, -1.0f); glColor3f(1.0f,0.0f,0.0f); glVertex3f( 0.0f, 1.0f, 0.0f); glColor3f(0.0f,1.0f,0.0f); glVertex3f( 1.0f,-1.0f, -1.0f); glColor3f(0.0f,0.0f,1.0f); glVertex3f(-1.0f,-1.0f, -1.0f); glColor3f(1.0f,0.0f,0.0f); glVertex3f( 0.0f, 1.0f, 0.0f); glColor3f(0.0f,0.0f,1.0f); glVertex3f(-1.0f,-1.0f,-1.0f); glColor3f(0.0f,1.0f,0.0f); glVertex3f(-1.0f,-1.0f, 1.0f); glEnd(); */ /* glLoadIdentity(); glTranslatef(movx,movy,-17.0f); glRotatef(rquad,1.0f,0.5f,0.2f); glBegin(GL_QUADS); glColor3f(0.0f,1.0f,0.0f); glVertex3f( 1.0f, 1.0f,-1.0f); glVertex3f(-1.0f, 1.0f,-1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glColor3f(1.0f,0.5f,0.0f); glVertex3f( 1.0f,-1.0f, 1.0f); glVertex3f(-1.0f,-1.0f, 1.0f); glVertex3f(-1.0f,-1.0f,-1.0f); glVertex3f( 1.0f,-1.0f,-1.0f); glColor3f(1.0f,0.0f,0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glVertex3f(-1.0f,-1.0f, 1.0f); glVertex3f( 1.0f,-1.0f, 1.0f); glColor3f(1.0f,1.0f,0.0f); glVertex3f( 1.0f,-1.0f,-1.0f); glVertex3f(-1.0f,-1.0f,-1.0f); glVertex3f(-1.0f, 1.0f,-1.0f); glVertex3f( 1.0f, 1.0f,-1.0f); glColor3f(0.0f,0.0f,1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glVertex3f(-1.0f, 1.0f,-1.0f); glVertex3f(-1.0f,-1.0f,-1.0f); glVertex3f(-1.0f,-1.0f, 1.0f); glColor3f(1.0f,0.0f,1.0f); glVertex3f( 1.0f, 1.0f,-1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glVertex3f( 1.0f,-1.0f, 1.0f); glVertex3f( 1.0f,-1.0f,-1.0f); glEnd(); */ /* rtri+=1.2f; rquad-=1.15f; if(movy1)movy+=0.1f; if(movy2)movy-=0.1f; if(movx1)movx+=0.1f; if(movx2)movx-=0.1f; */ return TRUE; } GLvoid KillGLWindow(GLvoid) { if (fullscreen) { ChangeDisplaySettings(NULL,0); ShowCursor(TRUE); } if (hRC) { if (!wglMakeCurrent(NULL,NULL)) { MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); } if (!wglDeleteContext(hRC)) { MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); } hRC=NULL; } if (hDC && !ReleaseDC(hWnd,hDC)) { MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); hDC=NULL; } if (hWnd && !DestroyWindow(hWnd)) { MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); hWnd=NULL; } if (!UnregisterClass("OpenGL",hInstance)) { MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); hInstance=NULL; } } BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag) { GLuint PixelFormat; WNDCLASS wc; DWORD dwExStyle; DWORD dwStyle; RECT WindowRect; WindowRect.left=(long)0; WindowRect.right=(long)width; WindowRect.top=(long)0; WindowRect.bottom=(long)height; fullscreen=fullscreenflag; hInstance = GetModuleHandle(NULL); wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = (WNDPROC) WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = "OpenGL"; if (!RegisterClass(&wc)) { MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if (fullscreen) { DEVMODE dmScreenSettings; memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); dmScreenSettings.dmSize=sizeof(dmScreenSettings); dmScreenSettings.dmPelsWidth = width; dmScreenSettings.dmPelsHeight = height; dmScreenSettings.dmBitsPerPel = bits; dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) { 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; } else { MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP); return FALSE; } } } if (fullscreen) { dwExStyle=WS_EX_APPWINDOW; dwStyle=WS_POPUP; ShowCursor(FALSE); } else { dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; dwStyle=WS_OVERLAPPEDWINDOW; } AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Create The Window if (!(hWnd=CreateWindowEx( dwExStyle, "OpenGL", title, dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top, NULL, NULL, hInstance, NULL))) { KillGLWindow(); MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } static PIXELFORMATDESCRIPTOR pfd= { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, bits, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; if (!(hDC=GetDC(hWnd))) { KillGLWindow(); MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) { KillGLWindow(); MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if(!SetPixelFormat(hDC,PixelFormat,&pfd)) { KillGLWindow(); MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if (!(hRC=wglCreateContext(hDC))) { KillGLWindow(); MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if(!wglMakeCurrent(hDC,hRC)) { KillGLWindow(); MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } ShowWindow(hWnd,SW_SHOW); SetForegroundWindow(hWnd); SetFocus(hWnd); ReSizeGLScene(width, height); if (!InitGL()) { KillGLWindow(); MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } return TRUE; } LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_ACTIVATE: { if (!HIWORD(wParam)) { active=TRUE; } else { active=FALSE; } return 0; } case WM_SYSCOMMAND: { switch (wParam) { case SC_SCREENSAVE: case SC_MONITORPOWER: return 0; } break; } case WM_CLOSE: { PostQuitMessage(0); return 0; } case WM_KEYDOWN: { keys[wParam] = TRUE; TCHAR tchar = (TCHAR)wParam; if(tchar == 'w' || tchar == 'W') movy1=true; else if(tchar == 's' || tchar == 'S') movy2=true; else if(tchar == 'a' || tchar == 'A') movx2=true; else if(tchar == 'd' || tchar == 'D') movx1=true; return 0; } case WM_KEYUP: { keys[wParam] = FALSE; TCHAR tchar = (TCHAR)wParam; if(tchar == 'w' || tchar == 'W') movy1=false; else if(tchar == 's' || tchar == 'S') movy2=false; else if(tchar == 'a' || tchar == 'A') movx2=false; else if(tchar == 'd' || tchar == 'D') movx1=false; return 0; } case WM_SIZE: { ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); return 0; } } return DefWindowProc(hWnd,uMsg,wParam,lParam); } void vyhed() { v=0; int n1=7,n2=9,n3=7,n4=9; for(int i=0;i!=64;i++) { if(laud[i]=='1') laud[i]='.'; } for(int i=0;i!=64;i++) { if(laud[i]=='v') { v++; if(laud[i-7]=='.'){laud[i-7]='1';} if(laud[i-9]=='.'){laud[i-9]='1';} if(laud[i+7]=='.'){laud[i+7]='1';} if(laud[i+9]=='.'){laud[i+9]='1';} } if(laud[i]=='V') { //v++; n1=7; n2=9; n3=7; n4=9; if((i-n1)>0) { while(laud[i-n1]=='.'||laud[i-n1]=='1') { laud[i-n1]='1'; n1+=7; } } if((i-n2)>0) { while(laud[i-n2]=='.'||laud[i-n2]=='1') { laud[i-n2]='1'; n2+=9; } } if((i+n3)<=64) { while(laud[i+n3]=='.'||laud[i+n3]=='1') { laud[i+n3]='1'; n3+=7; } } if((i+n4)<=64) { while(laud[i+n4]=='.'||laud[i+n4]=='1') { laud[i+n4]='1'; n4+=9; } } } } } void myhed() { m=0; int n1=7,n2=9,n3=7,n4=9; for(int i=0;i!=64;i++) { if(laud[i]=='1') laud[i]='.'; } for(int i=0;i!=64;i++) { if(laud[i]=='m') { m++; if(laud[i-7]=='.'){laud[i-7]='1';} if(laud[i-9]=='.'){laud[i-9]='1';} if(laud[i+7]=='.'){laud[i+7]='1';} if(laud[i+9]=='.'){laud[i+9]='1';} } if(laud[i]=='M') { //m++; n1=7; n2=9; n3=7; n4=9; if((i-n1)>0) { while(laud[i-n1]=='.'||laud[i-n1]=='1') { laud[i-n1]='1'; n1+=7; } } if((i-n2)>0) { while(laud[i-n2]=='.'||laud[i-n2]=='1') { laud[i-n2]='1'; n2+=9; } } if((i+n3)<=64) { while(laud[i+n3]=='.'||laud[i+n3]=='1') { laud[i+n3]='1'; n3+=7; } } if((i+n4)<=64) { while(laud[i+n4]=='.'||laud[i+n4]=='1') { laud[i+n4]='1'; n4+=9; } } } } } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { srand(time(0)); MSG msg; BOOL done=FALSE; //////////////////////////////////////////////////// bool kord=true; char kb; int i=0,r=0,k=0,s=0; string rida; ifstream sis("kabe.sis"); while(!sis.eof()&&i!=8) { getline(sis,rida); laud+=rida; i++; } sis.seekg(-1,ios::end); sis>>kb; sis.close(); if(kb=='v')kord=true; if(kb=='m')kord=false; ofstream val("kabe.val"); if(kb=='v') { vyhed(); r=rand()%(v+1); } if(kb=='m') { myhed(); r=rand()%(m+1); } //cout<0) { for(i=0;i!=64;i++) { if(laud[i]=='v') s++; if(s==r) { if(laud[i+7]=='1'&&kord==true) { laud[i]='.'; laud[i+7]='v'; kord=false; } if(laud[i+9]=='1'&&kord==true) { laud[i]='.'; laud[i+9]='v'; kord=false; } if(laud[i-7]=='1'&&kord==true) { laud[i]='.'; laud[i-7]='v'; kord=false; } if(laud[i-9]=='1'&&kord==true) { laud[i]='.'; laud[i-9]='v'; kord=false; } if(kord){r=rand()%(v+1);i=0;s=0;} } } } if(kb=='m'&&m>0) { for(i=63;i!=-1;i--) { if(laud[i]=='m') s++; if(s==r) { if(laud[i+7]=='1'&&kord==false) { laud[i]='.'; laud[i+7]='m'; kord=true; } if(laud[i+9]=='1'&&kord==false) { laud[i]='.'; laud[i+9]='m'; kord=true; } if(laud[i-7]=='1'&&kord==false) { laud[i]='.'; laud[i-7]='m'; kord=true; } if(laud[i-9]=='1'&&kord==false) { laud[i]='.'; laud[i-9]='m'; kord=true; } if(!kord){r=rand()%(m+1);i=63;s=0;} } } } if(kb=='v') { vyhed(); } if(kb=='m') { myhed(); } for(i=0;i!=64;i++) { //cout<