*基本輸入
-#include <GL/glut.h> ///使用GLUT外掛
#include<stdio.h>
int main(int argc , char**argv) ///進階的main()參數(個數,字串)
{
glutInit(&argc,argv); ///進階參數,初始GLUT
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); ///開起2種模式
glutCreateWindow("Week03 Mousehl 操作"); //盡量不要用中文
glutDisplayFunc(display); ///等一下準備 void display()
glutMouseFunc(moust); ///滑鼠按鈕
glutMotionFunc(motion); ///滑鼠滾輪
glutMainLoop(); ///主要迴圈
}
-各種參數的應用
-void display()
{
glClearColor(r,g,b,透明度) ///用來指定Clear的顏色 (要打在glClear的上面)
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);
}
-void motion(int x,int y)
{
teapotX=(x-150)/150.0;
teapotY=-(y-150)/150.0;
printf("%d %d\n",x,y);
glutPostRedisplay();
}
*程式碼
-#include <GL/glut.h> ///使用GLUT外掛
#include<stdio.h>
float teapotX=0,teapotY=0;///teapot的位置,一開始在0,0
void display()
{
glClearColor(1,1,0,1);///(r,g,b,透明度) ///用來指定Clear的顏色 (要打在glClear的上面)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ///2種模式
glColor3f(1,0,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);
}
void motion(int x,int y)
{
teapotX=(x-150)/150.0;
teapotY=-(y-150)/150.0;
printf("%d %d\n",x,y);///印出移動的數字
glutPostRedisplay();
}
int main(int argc , char**argv) ///進階的main()參數(個數,字串)
{
glutInit(&argc,argv); ///進階參數,初始GLUT
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); ///開起2種模式
glutCreateWindow("Week03 Mousehl 操作"); ///盡量不要用中文
glutDisplayFunc(display); ///等一下準備 void display()
glutMouseFunc(mouse); ///滑鼠按鈕
glutMotionFunc(motion); ///滑鼠滾輪
glutMainLoop(); ///主要迴圈
}
*程式碼
-#include <GL/glut.h> ///使用GLUT外掛
#include<stdio.h>
float teapotX=0,teapotY=0;///teapot的位置,一開始在0,0
void display()
{
glClearColor(1,1,0,1);///(r,g,b,透明度) ///用來指定Clear的顏色 (要打在glClear的上面)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ///2種模式
glColor3f(1,0,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);
}
void motion(int x,int y)
{
teapotX=(x-150)/150.0;
teapotY=-(y-150)/150.0;
printf("%d %d\n",x,y);///印出移動的數字
glutPostRedisplay();
}
int main(int argc , char**argv) ///進階的main()參數(個數,字串)
{
glutInit(&argc,argv); ///進階參數,初始GLUT
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); ///開起2種模式
glutCreateWindow("Week03 Mousehl 操作"); ///盡量不要用中文
glutDisplayFunc(display); ///等一下準備 void display()
glutMouseFunc(mouse); ///滑鼠按鈕
glutMotionFunc(motion); ///滑鼠滾輪
glutMainLoop(); ///主要迴圈
}




沒有留言:
張貼留言