data.zip, windows.zip, glut32.dll 這3個檔案的網址在 http://jsyeh.org/3dcg10
shapes.exe這可以讓我們看到各種圖形的宣告,還有順序點。
Point 點
Line 線
Line_Loop 線與線會連結起來
Line_Strip 線與線會相連 頭尾不相連
TRIANGLE_FAN 座標順時針跑
TRIANGLE STRIP_ N字型跑
QUADS 四邊形
QUAD_STRIP 多邊形
POLYGON 多邊形
------------------------------------------------------------------------
#include <stdio.h>
#include <GL/GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
glutSolidTeapot(0.3);
glutSwapBuffers();搭配GLUT_DOUBLE兩倍顯示
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);///兩個顯示參數
glutCreateWindow("Week03 Mouse");///視窗標題
glutDisplayFunc(display);/// 讀入display()的程式
//glutMouseFunc() ///滑鼠事件
//glutMotionFunc()///滑鼠動作事件
glutMainLoop(); ///GLUT迴圈
}

////滑鼠事件宣告 ------------要在 glutMouseFunc(mouse) 宣告mouse進去;
void mouse(int button,int state,int x,int y)
{
printf("%d %d %d %d\n",button,state,x,y);
}
////可以用滑鼠讀入座標並 printf 出來
***新增
if(state==GLUT_DOWN)
{
printf("glVertex %.2f %.2f\n",(x-150)/150.0,(y-150)/150.0);
}/////滑鼠點下的時的座標
----------------------
***新增
if(state==GLUT_DOWN)
{
printf("glVertex %.2f %.2f\n",(x-150)/150.0,(y-150)/150.0);
}/////滑鼠點下的時的座標
----------------------
#include <stdio.h>
#include <GL/glut.h>
float teapotX=0, teapotY=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();//備份矩陣
glTranslatef(teapotX, teapotY, 0); //依照茶壺的座標移動
glutSolidTeapot(0.3);
glPopMatrix();//還原矩陣
glutSwapBuffers(); //搭配GLUT_DOUBLE兩倍顯示
}
void motion(int x, int y) //mouse motion 事件
{
teapotX = (x-150)/150.0; // 依照motion時的x來改teapot的座標
teapotY = (150-y)/150.0;// 依照motion時的y來改teapot的座標
glutPostRedisplay(); //重畫畫面
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week03 Mouse");
glutDisplayFunc(display);
//glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();//主要GLUT迴圈
}


沒有留言:
張貼留言