Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <gl\gl.h>
- #include <gl\glu.h>
- #include <gl\glut.h>
- #define _USE_MATH_DEFINES
- #include <math.h>
- static void redraw(void);
- int main(int argc, char **argv);
- int main(int argc, char **argv)
- {
- glutInit(&argc,argv);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- glutInitWindowSize(800,800);
- glutCreateWindow("Шаховска Табла");
- glutDisplayFunc(redraw);
- glMatrixMode(GL_PROJECTION); //hello
- gluPerspective(45, //view angle
- 1.0, //aspect ratio
- 10.0, //near clip
- 200.0);//far clip
- glMatrixMode(GL_MODELVIEW);
- glutMainLoop();
- return 0;
- }
- static void tabla(){
- int br = 0;
- for(int i=0;i<8;i++){
- for(int j=0;j<8;j++){
- glBegin(GL_POLYGON);
- if(br%2==0)
- glColor3f(1.0,1.0,1.0);
- else
- glColor3f(0.3,0.3,0.3);
- br++;
- glVertex2f(i,j);
- glVertex2f(i,j+1);
- glVertex2f(i+1,j+1);
- glVertex2f(i+1,j);
- glEnd();
- }
- br++;
- }
- }
- static void ramka(){
- glBegin(GL_POLYGON);
- glColor3f(0.5,0.5,0.5);
- glVertex2f(-0.2,-0.2);
- glVertex2f(8.2,-0.2);
- glVertex2f(8.2,8.2);
- glVertex2f(-0.2,8.2);
- glEnd();
- }
- static void crtajKrug(int s, int od, float r, float xk, float yk, bool crvena){
- float x,y;
- float radius = r;
- yk*=-1;
- glBegin(GL_POLYGON);
- if(crvena)
- glColor3f(1.0f,0.0f,0.0f);
- else
- glColor3f(0.0f,0.0f,1.0f);
- if(od==0){
- x = (float)radius * cos(359 * M_PI/180.0f)+xk;
- y = (float)radius * sin(359 * M_PI/180.0f)+8+yk;
- }
- else{
- x = (float)radius * cos(od * M_PI/180.0f)+xk;
- y = (float)radius * sin(od * M_PI/180.0f)+8+yk;
- }
- for(int j = od; j <= s; j++)
- {
- glVertex2f(x,y);
- x = (float)radius * cos(j * M_PI/180.0f)+xk;
- y = (float)radius * sin(j * M_PI/180.0f)+8+yk;
- glVertex2f(x,y);
- }
- glEnd();
- }
- void DrawEllipse(float radiusX, float radiusY, float xk, float yk)
- {
- int i;
- yk*=-1;
- glBegin(GL_POLYGON);
- for(i=0;i<80;i++)
- {
- float rad = (i*M_PI/180)+90;
- glVertex2f(cos(rad)*radiusX+xk, sin(rad)*radiusY+8+yk);
- }
- glEnd();
- }
- static void crtajPiun(float x, float y, bool crvena){
- crtajKrug(181, 0, 0.35, x+0.5,y+0.9, crvena);
- crtajKrug(360, 0, 0.19, x+0.5,y+0.5, crvena);
- crtajKrug(360, 0, 0.12, x+0.5,y+0.25, crvena);
- }
- static void crtajTop(float xk, float yk, bool crvena){
- glBegin(GL_QUADS);
- yk*=-1;
- if(crvena)
- glColor3f(1.0,0.0,0.0);
- else
- glColor3f(0.0,0.0,1.0);
- //osnova
- glVertex2f(xk+0.15,yk+7.1);
- glVertex2f(xk+0.85,yk+7.1);
- glVertex2f(xk+0.85,yk+7.2);
- glVertex2f(xk+0.15,yk+7.2);
- //dolen trapez
- glVertex2f(xk+0.15,yk+7.2);
- glVertex2f(xk+0.85,yk+7.2);
- glVertex2f(xk+0.73,yk+7.35);
- glVertex2f(xk+0.27,yk+7.35);
- //sredna kocka
- glVertex2f(xk+0.27,yk+7.35);
- glVertex2f(xk+0.73,yk+7.35);
- glVertex2f(xk+0.73,yk+7.65);
- glVertex2f(xk+0.27,yk+7.65);
- //goren trapez
- glVertex2f(xk+0.27,yk+7.65);
- glVertex2f(xk+0.73,yk+7.65);
- glVertex2f(xk+0.85,yk+7.80);
- glVertex2f(xk+0.15,yk+7.80);
- //kockicki
- glVertex2f(xk+0.15,yk+7.80);
- glVertex2f(xk+0.325,yk+7.80);
- glVertex2f(xk+0.325,yk+7.90);
- glVertex2f(xk+0.15,yk+7.90);
- glVertex2f(xk+0.4125,yk+7.80);
- glVertex2f(xk+0.5875,yk+7.80);
- glVertex2f(xk+0.5875,yk+7.90);
- glVertex2f(xk+0.4125,yk+7.90);
- glVertex2f(xk+0.675,yk+7.80);
- glVertex2f(xk+0.85,yk+7.80);
- glVertex2f(xk+0.85,yk+7.90);
- glVertex2f(xk+0.675,yk+7.90);
- glEnd();
- }
- static void crtajLovec(float xk, float yk, bool crvena){
- crtajKrug(360, 0, 0.08,0.5+xk,0.2+yk, crvena);
- crtajKrug(360, 0, 0.18,0.5+xk,0.43+yk, crvena);
- crtajKrug(180, 0, 0.3, 0.5+xk,0.9+yk, crvena);
- yk*=-1;
- glBegin(GL_POLYGON);
- if(crvena)
- glColor3f(1.0,0.0,0.0);
- else
- glColor3f(0.0,0.0,1.0);
- glVertex2f(0.35+xk,7.5+yk);
- glVertex2f(0.3+xk,7.4+yk);
- glVertex2f(0.4+xk,7.3+yk);
- glVertex2f(0.6+xk,7.3+yk);
- glVertex2f(0.7+xk,7.4+yk);
- glVertex2f(0.65+xk,7.5+yk);
- glEnd();
- }
- static void crtajKonj(float xk, float yk, bool crvena){
- if(crvena)
- glColor3f(1.0,0.0,0.0);
- else
- glColor3f(0.0,0.0,1.0);
- //Zaktivenost
- DrawEllipse(0.5,0.7,0.7+xk,0.7+yk);
- yk*=-1;
- glBegin(GL_POLYGON);
- glVertex2f(0.7+xk,7.1+yk);
- glVertex2f(0.2+xk,7.1+yk);
- glVertex2f(0.5+xk,7.5+yk);
- glEnd();
- //Dolen triagolnik
- glBegin(GL_POLYGON);
- glVertex2f(0.47+xk,7.9+yk);
- glVertex2f(0.2+xk,7.1+yk);
- glVertex2f(0.5+xk,7.5+yk);
- glEnd();
- //Usta
- glBegin(GL_POLYGON);
- glVertex2f(0.5+xk,7.5+yk);
- glVertex2f(0.8+xk,7.35+yk);
- glVertex2f(0.85+xk,7.45+yk);
- glVertex2f(0.57+xk,7.92+yk);
- glVertex2f(0.47+xk,7.92+yk);
- glEnd();
- //Ostatok
- glBegin(GL_POLYGON);
- glVertex2f(0.57+xk,7.92+yk);
- glVertex2f(0.47+xk,7.92+yk);
- glVertex2f(0.1+xk,7.1+yk);
- glVertex2f(0.57+xk,7.1+yk);
- glEnd();
- }
- static void crtajKralica(float xk, float yk, bool crvena){
- if(crvena)
- glColor3f(1.0,0.0,0.0);
- else
- glColor3f(0.0,0.0,1.0);
- crtajKrug(360, 0, 0.166, 0.33+xk, 0.5+yk, crvena);
- crtajKrug(360, 0, 0.166, 0.67+xk, 0.5+yk, crvena);
- crtajKrug(360, 0, 0.08, 0.5+xk, 0.28+yk, crvena);
- crtajKrug(326, 215, 0.258, 0.51+xk, 0.65+yk, crvena);
- yk*=-1;
- glBegin(GL_QUADS);
- glVertex2f(0.42+xk,7.72+yk);
- glVertex2f(0.58+xk,7.72+yk);
- glVertex2f(0.58+xk,7.32+yk);
- glVertex2f(0.42+xk,7.32+yk);
- glEnd();
- glBegin(GL_QUADS);
- glVertex2f(0.194+xk,7.5+yk);
- glVertex2f(0.82+xk,7.5+yk);
- glVertex2f(0.72+xk,7.3+yk);
- glVertex2f(0.294+xk,7.3+yk);
- glVertex2f(0.72+xk,7.3+yk);
- glVertex2f(0.72+xk,7.2+yk);
- glVertex2f(0.294+xk,7.2+yk);
- glVertex2f(0.294+xk,7.3+yk);
- glEnd();
- glBegin(GL_LINES);
- glVertex2f(0.5+xk,7.9+yk);
- glVertex2f(0.5+xk,7.5+yk);
- glVertex2f(0.45+xk,7.86+yk);
- glVertex2f(0.55+xk,7.86+yk);
- glEnd();
- }
- static void crtajKral(float xk, float yk, bool crvena){
- if(crvena)
- glColor3f(1.0,0.0,0.0);
- else
- glColor3f(0.0,0.0,1.0);
- crtajKrug(360, 0, 0.07, 0.84+xk, 0.3+yk, crvena);
- crtajKrug(360, 0, 0.07, 0.67+xk, 0.25+yk, crvena);
- crtajKrug(360, 0, 0.07, 0.50+xk, 0.2+yk, crvena);
- crtajKrug(360, 0, 0.07, 0.33+xk, 0.25+yk, crvena);
- crtajKrug(360, 0, 0.07, 0.16+xk, 0.3+yk, crvena);
- yk*=-1;
- glBegin(GL_QUADS);
- glVertex2f(0.15+xk,7.1+yk);
- glVertex2f(0.85+xk,7.1+yk);
- glVertex2f(0.75+xk,7.2+yk);
- glVertex2f(0.25+xk,7.2+yk);
- glVertex2f(0.25+xk,7.2+yk);
- glVertex2f(0.75+xk,7.2+yk);
- glVertex2f(0.85+xk,7.4+yk);
- glVertex2f(0.15+xk,7.4+yk);
- glEnd();
- glBegin(GL_TRIANGLES);
- glVertex2f(0.15+xk,7.4+yk);
- glVertex2f(0.29+xk,7.4+yk);
- glVertex2f(0.16+xk,7.7+yk);
- glVertex2f(0.29+xk,7.4+yk);
- glVertex2f(0.43+xk,7.4+yk);
- glVertex2f(0.33+xk,7.75+yk);
- glVertex2f(0.43+xk,7.4+yk);
- glVertex2f(0.57+xk,7.4+yk);
- glVertex2f(0.50+xk,7.8+yk);
- glVertex2f(0.57+xk,7.4+yk);
- glVertex2f(0.71+xk,7.4+yk);
- glVertex2f(0.67+xk,7.75+yk);
- glVertex2f(0.71+xk,7.4+yk);
- glVertex2f(0.85+xk,7.4+yk);
- glVertex2f(0.84+xk,7.7+yk);
- glEnd();
- }
- static void redraw(void)
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glPushMatrix();
- glTranslatef(-4,-4,-10);
- //Crtaj ramka
- ramka();
- //Ctraj tabla
- tabla();
- //crveni piuni
- for (int i=0; i<8;i++){
- crtajPiun(i,1, true);}
- //plavi piuni
- for (int i=0; i<8;i++){
- crtajPiun(i,6, false);}
- //crtaj topovi
- crtajTop(0,0,true);
- crtajTop(7,0,true);
- crtajTop(7,7,false);
- crtajTop(0,7,false);
- //crtaj lovec
- crtajLovec(2,0,true);
- crtajLovec(5,0,true);
- crtajLovec(2,7,false);
- crtajLovec(5,7,false);
- //crtanje konj
- crtajKonj(1,0,true);
- crtajKonj(6,0,true);
- crtajKonj(1,7,false);
- crtajKonj(6,7,false);
- //crtanje kralica
- crtajKralica(4,0,true);
- crtajKralica(4,7,false);
- //crtanje kral
- crtajKral(3,0,true);
- crtajKral(3,7,false);
- glPopMatrix();
- glutSwapBuffers();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement