開啟程式複習上週課程內容
新程式碼做出簡易畫板
#include <GL/glut.h>
#include <stdio.h>
float vx[2000],vy[2000];
int N=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_LINE_LOOP);
for(int i=0; i<N; i++){
glVertex2f(vx[i],vy[i]);
}
glEnd();
glutSwapBuffers();
}
void mouse(int botton,int state,int x,int y)
{
}
void motion(int x,int y)
{
printf("%d %d\n",x,y);
vx[N] = (x-150)/150.0;
vy[N] = -(y-150)/150.0;
N++;
display();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("08160465 大宇 Week05 宣告陣列");
glutDisplayFunc(display);
glutMouseFunc( mouse );
glutMotionFunc( motion );
glutMainLoop();
}
從線條變成多個三角形組成的扇面
#include <GL/glut.h>
#include <stdio.h>
float vx[2000],vy[2000];
int N=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_TRIANGLE_FAN);
glColor3ub(28,107,240);
for(int i=0; i<N; i++){
glVertex2f(vx[i],vy[i]);
}
glEnd();
glutSwapBuffers();
}
void mouse(int botton,int state,int x,int y)
{
}
void motion(int x,int y)
{
printf("%d %d\n",x,y);
vx[N] = (x-150)/150.0;
vy[N] = -(y-150)/150.0;
N++;
display();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("08160465 大宇 Week05 宣告陣列");
glutDisplayFunc(display);
glutMouseFunc( mouse );
glutMotionFunc( motion );
glutMainLoop();
}
利用老師作的模擬考程式,練習GL必備程式碼
1. glPushMatrix();備份的矩陣
2. glTranslatef(x,y,z);移動
3. glRotatef(angle,x,y,z);旋轉
4. glScalef(x,y,z);大小
5. glBegin(GL_POLYGON);畫開始
6. glColor3f(r,g,b);顏色
7. glTexCoord2f(tx,ty);貼圖座標
8. glNormal3f(nx,nt,nz);打光
9. glVertex3f(x,y,z);頂點
10. glEnd();畫結束
11. glPopMatrix();還原的的矩陣
==========






沒有留言:
張貼留言