WEEK04
Work01
#include <GL/glut.h>
#include <stdio.h>
void mouse(int button,int state,int x,int y)
{
if(state==GLUT_DOWN) printf("glVertex2f((%d-150)/150.0, -(%d-150)/150.0)\n",x,y);
}
void display()
{
glClearColor(150/255.0,170/255.0,55/255.0,1);
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Hello");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
Work03
額外的學習01
#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
void mouse(int button,int state,int x,int y)#include <math.h>
{
if(state==GLUT_DOWN) printf("glVertex2f((%d-150)/150.0, -(%d-150)/150.0)\n",x,y);
}
void display()
{
glClearColor(150/255.0,170/255.0,55/255.0,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(0,0.5,0);
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(float angle=0; angle<M_PI*2; angle+=0.1)
{
glVertex2f(0.2*cos(angle),0.2*sin(angle));
}
glEnd();
glTranslatef(0.5,0,0);
glBegin(GL_POLYGON);
glColor3f(1,1,1);
for(float angle=0; angle<M_PI*2; angle+=0.1)
{
glVertex2f(0.1*cos(angle),0.1*sin(angle));
}
glEnd();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Hello");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
額外的學習02
請反白
#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
float nowX,nowY,now;
void mouse(int button,int state,int x,int y)
{
if(state==GLUT_DOWN)
{
nowX=(x-150)/150.0;nowY=-(y-150)/150.0;
now+=0.1;
}//printf("glVertex2f((%d-150)/150.0, -(%d-150)/150.0)\n",x,y);
}
void display()
{
glClearColor(150/255.0,170/255.0,55/255.0,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glBegin(GL_POLYGON);
glColor3f(1,0,1);
for(float angle=0; angle<M_PI*2; angle+=0.1)
{
glVertex2f(nowX+0.3*cos(angle),nowY+0.3*sin(angle));
}
glEnd();
glBegin(GL_POLYGON);
glColor3f(1,1,1);
glVertex2f(nowX,nowY);
for(float angle=0; angle<now; angle+=0.1)
{
glVertex2f(nowX+0.3*cos(angle),nowY+0.3*sin(angle));
}
glEnd();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Hello");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}


















沒有留言:
張貼留言