2.移動,旋轉,縮放
3.用滑鼠 直接印出座標
程式碼 :
#include <GL/glut.h>
#include <stdio.h>
void mouse(int button,int state,int x,int y)
{
if(state==GLUT_DOWN)
{
printf("glVertex2f((%d-100)/100,-(%d-100)/100)\n",x,y);
}
}
void display()
{
glBegin(GL_POLYGON);
glColor3f(0,0.2,0.8);
glVertex2f(-0.5,0.5);
glVertex2f(-0.5,-0.5);
glVertex2f(1,0);
glVertex2f(1,1);
glEnd();
glutSwapBuffers();
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("hello3D");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
4.畫圓
#include <stdio.h>
#include <math.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()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3ub(153,217,234);
glPushMatrix();
glTranslatef(0,-0.5,0);
glBegin(GL_POLYGON);
for(float angle=0; angle<3.14159265357989 *2/4*3; angle+= 0.1)
{
glVertex2f(0.2*cos(angle), 0.2*sin(angle) );
}
glEnd();
glPopMatrix();
glPushMatrix();
glTranslatef(0,0.5,0);
glBegin(GL_POLYGON);
for(float angle=0; angle<3.14159265357989 ; angle+= 0.1)
{
glVertex2f(0.2*cos(angle), 0.2*sin(angle) );
}
glEnd();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.5,0,0);
glBegin(GL_POLYGON);
for(float angle=0; angle<3.14159265357989 *2; angle+= 0.1)
{
glVertex2f(0.2*cos(angle), 0.2*sin(angle) );
}
glEnd();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("circle");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}








沒有留言:
張貼留言