Tres En Raya Opengl
struct punto
{
float x;
float y;
};
int matriz[3][3] = {0};
punto mipunto = {-0.4,1.5};
void dibjcuadrado(float x, float y)
{
glBegin(GL_POLYGON);glColor3f(1.0, 0.0, 1.0);
glVertex2f(-0.1+x, -0.1+y);
glVertex2f(-0.1+x,0.1+y);
glVertex2f(0.1+x, 0.1+y);
glVertex2f(0.1+x, -0.1+y);
glEnd();
}
void dibjtriangulo(float x,float y)
{
glBegin(GL_POLYGON);
glColor3f(1.0, 0.0, 1.0);
glVertex2f(-0.1+x, -0.1+y);
glVertex2f(0.0+x,0.1+y);
glVertex2f(0.1+x,-0.1+y);
glEnd();
}
void display(void){
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINES);
glColor3f(1.0, 0.0, 1.0);
glVertex2f(-0.2, -1);
glVertex2f(-0.2, 1);
glVertex2f(0.2, -1);
glVertex2f(0.2,1);
glVertex2f(-1,0.2);
glVertex2f(1,0.2);
glVertex2f(-1, -0.2);
glVertex2f(1, -0.2);
glEnd();
dibjcuadrado(mipunto.x,mipunto.y);/*dibjcuadrado(0.4,0);
dibjcuadrado(0,0.4);
dibjtriangulo(0.4,0.4);
dibjtriangulo(-0.4,-0.4);
dibjtriangulo(0.4,-0.4);
*/
glFlush();
}
void init()
{
glClearColor (0.0, 0.0, 0.0, 0.0);glColor3f(1.0, 1.0, 1.0);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho(-2,2,-2,2,-2,2);
}
void teclado (unsigned char tecla, int x, int y)
{
if( tecla=='x')
{if(mipunto.x-0.4)
{
mipunto.x=mipunto.x-0.4;
}
}
else if( tecla=='d')
{
int c=0;
if(mipunto.x==-0.4)
{
c=0;
}else
if(mipunto.x==0)
{
c=01;
}elseif(mipunto.x==0.4)
{
c=02;
}
if(matriz[0][c]==0)
{
matriz[0][c]=1;
}else
if(matriz[1][c]==0)
{
matriz[1][c]=1;
}elseif(matriz[2][c]==0)
{
matriz[2][c]=1;
}
}
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);...
Regístrate para leer el documento completo.