自己打
#include <GL/glut.h> ///使用GLUT外掛
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ; ///2種模式
glutSolidTeapot(0.3) ;
glutSwapBuffers(); ///交換畫面buffer便會顯示
}
int main(int argc , char**argv) ///進階的main() 參數(個數,字串)
{
glutInit(&argc ,argv); ///近接參數,初始GLUT
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH) ; ///開啟2種模式
glutCreateWindow("Week03 Mouse操作"); ///盡量不要用中文
glutDisplayFunc(display); ///等一下樓上要準備 viod display()
///glutMouseFunc(mouse); ///等一下也會準備好mouse()_功能 按鈕
///glutMotionFunc(motion); ///等一下也會準備好motion()移動
glutMainLoop();
}
加上顏色
#include <GL/glut.h> ///使用GLUT外掛
void display()
{
glClearColor(1 , 1 , 0 , 1 ); ///黃色背景
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ; ///2種模式
glColor3f(0, 1 , 0 );///標示顏色
glutSolidTeapot(0.3) ;
glutSwapBuffers(); ///交換畫面buffer便會顯示
}
int main(int argc , char**argv) ///進階的main() 參數(個數,字串)
{
glutInit(&argc ,argv); ///近接參數,初始GLUT
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH) ; ///開啟2種模式
glutCreateWindow("Week03 Mouse操作"); ///盡量不要用中文
glutDisplayFunc(display); ///等一下樓上要準備 viod display()
///glutMouseFunc(mouse); ///等一下也會準備好mouse()_功能 按鈕
///glutMotionFunc(motion); ///等一下也會準備好motion()移動
glutMainLoop();
}
顯示座標 滑鼠按
#include <GL/glut.h> ///使用GLUT外掛
void display()
{
glClearColor(1 , 1 , 0 , 1 ); ///黃色背景
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ; ///2種模式
glColor3f(0, 1 , 0 );///標示顏色
glutSolidTeapot(0.3) ;
glutSwapBuffers(); ///交換畫面buffer便會顯示
}
void mouse(int button , int state , int x , int y )
{
if(state==GLUT_DOWN) printf("glVertex2f( %f , %f ) ;\n",(x-150)/150.0,-(y-150)/150.0);
}
int main(int argc , char**argv) ///進階的main() 參數(個數,字串)
{
glutInit(&argc ,argv); ///近接參數,初始GLUT
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH) ; ///開啟2種模式
glutCreateWindow("Week03 Mouse操作"); ///盡量不要用中文
glutDisplayFunc(display); ///等一下樓上要準備 viod display()
glutMouseFunc(mouse); ///等一下也會準備好mouse()_功能 按鈕
///glutMotionFunc(motion); ///等一下也會準備好motion()移動
glutMainLoop();
}
可以移動
#include <GL/glut.h> ///使用GLUT外掛
float teapotX=0 , teapotY=0 ;///teapot的位置 , 一開始在 0, 0
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ; ///2種模式
glPushMatrix();///NOW: 備份矩陣
glTranslatef(teapotX , teapotY , 0); ///NOW: 移動的參數要準備好!!!
glutSolidTeapot(0.3);
glPopMatrix(); ///NOW: 還原矩陣
glutSwapBuffers(); ///交換畫面buffer便會顯示
}
#include <stdio.h>
void mouse(int button , int state , int x , int y )
{
if(state==GLUT_DOWN) printf("glVertex2f( %f , %f ) ;\n",(x-150)/150.0,-(y-150)/150.0);
///NOW: 把大象放到冰箱 : (1)把冰箱門大開 , (3) 把冰箱門關起來
}
void motion( int x , int y )
{///NOW:(2)把大象放進冰箱
teapotX=(x-150)/150.0 ;teapotY=-(y-150)/150.0;///NOW: 把你的mouse 的位置,設成teapot的位置
printf("%d %d\n", x , y );///印出移動的數字
glutPostRedisplay();///NOW:貼個3M便利貼POST , 有空要記得重畫畫面Redisplay
}
int main(int argc , char**argv) ///進階的main() 參數(個數,字串)
{
glutInit(&argc ,argv); ///近接參數,初始GLUT
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH) ; ///開啟2種模式
glutCreateWindow("Week03 Mouse操作"); ///盡量不要用中文
glutDisplayFunc(display); ///等一下樓上要準備 viod display()
glutMouseFunc(mouse); ///等一下也會準備好mouse()_功能 按鈕
glutMotionFunc(motion); ///等一下也會準備好motion()移動
glutMainLoop();
}
沒有留言:
張貼留言